a blog index

dotnet-7.0
Paul Schneider 1 year ago
parent 2562c9a569
commit 02d80795ca
10 changed files with 47 additions and 45 deletions

@ -72,8 +72,8 @@ namespace Yavsc.Models
/// Billing postal address
/// </summary>
/// <returns></returns>
[ForeignKeyAttribute("PostalAddressId")]
public virtual Location PostalAddress { get; set; }
[ForeignKey("PostalAddressId")]
public virtual Location? PostalAddress { get; set; }
public long? PostalAddressId { get; set; }
/// <summary>
@ -88,7 +88,7 @@ namespace Yavsc.Models
return this.Id + " " + this.AccountBalance?.Credits.ToString() + this.Email + " " + this.UserName + " $" + this.AccountBalance?.Credits.ToString();
}
public BankIdentity BankInfo { get; set; }
public virtual List<BankIdentity> BankInfo { get; set; }
public long DiskQuota { get; set; } = 512 * 1024 * 1024;
public long DiskUsage { get; set; } = 0;

@ -58,6 +58,21 @@ namespace Yavsc.Models.Bank
[DisplayName("Clé RIB")]
public int BankedKey { get; set; }
public virtual ApplicationUser User { get; set; }
public string UserId { get; set; }
public override bool Equals(object? obj)
{
if (obj==null) return false;
if (! typeof(BankIdentity).IsAssignableFrom(obj.GetType())) return false;
BankIdentity tobj = (BankIdentity)obj;
return tobj.IBAN == IBAN &&
tobj.BIC == BIC &&
tobj.AccountNumber == AccountNumber &&
tobj.BankedKey == BankedKey;
}
}

@ -332,16 +332,14 @@ namespace Yavsc.Controllers
var user = _dbContext.Users.Include(u=>u.BankInfo)
.Single(u=>u.Id == uid);
if (user.BankInfo != null)
{
model.Id = user.BankInfo.Id;
_dbContext.Entry(user.BankInfo).State = EntityState.Detached;
_dbContext.Update(model);
}
else {
user.BankInfo = model;
if (user.BankInfo.Any(
bi => bi.Equals(model)
)) return BadRequest(new { message = "data already present" });
user.BankInfo.Add(model);
_dbContext.Update(user);
}
await _dbContext.SaveChangesAsync();
}
return RedirectToAction(nameof(Index), new { Message = ManageMessageId.SetBankInfoSuccess });

@ -67,7 +67,7 @@ namespace Yavsc.Controllers
{
string posterId = (await _context.Users.SingleOrDefaultAsync(u=>u.UserName == userName))?.Id ?? null ;
var result = _context.UserPosts(posterId, User.Identity.Name);
return View("Index", result.OrderByDescending(p => p.DateCreated).ToList().Skip(pageLen*pageNum).Take(pageLen).GroupBy(p=> p.Title ));
return View("Index", result.ToArray().Skip(pageLen*pageNum).Take(pageLen).OrderByDescending(p => p.DateCreated).ToList().GroupBy(p=> p.Title ));
}
// GET: Blog/Details/5
[AllowAnonymous]

@ -41,7 +41,7 @@ namespace Yavsc.Helpers
b => b.Author
).Where(x => x.Author.Id == posterId && x.Visible);
// BlogIndexKey
return result.OrderByDescending(p => p.DateCreated);
return result;
}
}
}

@ -51,9 +51,11 @@ namespace Yavsc.Models
builder.Entity<Contact>().HasKey(x => new { x.OwnerId, x.UserId });
builder.Entity<DeviceDeclaration>().Property(x => x.DeclarationDate).HasDefaultValueSql("LOCALTIMESTAMP");
builder.Entity<BlogTag>().HasKey(x => new { x.PostId, x.TagId });
builder.Entity<ApplicationUser>().HasMany<ChatConnection>(c => c.Connections);
builder.Entity<ApplicationUser>().Property(u => u.Avatar).HasDefaultValue(Constants.DefaultAvatar);
builder.Entity<ApplicationUser>().Property(u => u.DiskQuota).HasDefaultValue(Constants.DefaultFSQ);
builder.Entity<UserActivity>().HasKey(u => new { u.DoesCode, u.UserId });
builder.Entity<Instrumentation>().HasKey(u => new { u.InstrumentId, u.UserId });
builder.Entity<CircleAuthorizationToBlogPost>().HasKey(a => new { a.CircleId, a.BlogPostId });
@ -78,6 +80,7 @@ namespace Yavsc.Models
builder.Entity<Activity>().Property(a=>a.ParentCode).IsRequired(false);
builder.Entity<BlogPost>().HasOne(p => p.Author).WithMany(a => a.Posts);
}
// this is not a failback procedure.

@ -9,35 +9,33 @@ namespace Yavsc.ViewComponents
public class BlogIndexViewComponent: ViewComponent
{
private readonly ApplicationDbContext _context;
public BlogIndexViewComponent(
ApplicationDbContext context)
{
_context = context;
}
// Renders blog index ofr the specified user by name
// Renders blog index ofr the specified user by name,
// grouped by title
public async Task<IViewComponentResult> InvokeAsync(string viewerId, int skip=0, int maxLen=25)
{
long[] usercircles = await _context.Circle.Include(c=>c.Members).
Where(c=>c.Members.Any(m=>m.MemberId == viewerId))
.Select(c=>c.Id).ToArrayAsync();
IQueryable<BlogPost> posts ;
var allposts = _context.Blogspot
.Include(b => b.Author)
.Include(p=>p.ACL)
.Include(p=>p.Tags)
.Include(p=>p.Comments)
.Where(p=>p.AuthorId == viewerId || p.Visible);
.Where(p => p.AuthorId == viewerId || p.Visible).ToArray();
if (usercircles != null) {
posts = allposts.Where(p=> p.ACL.Count==0 || p.ACL.Any(a=> usercircles.Contains(a.CircleId)))
;
}
else {
posts = allposts.Where(p => p.ACL.Count == 0);
}
IEnumerable<BlogPost> posts = (usercircles != null) ?
allposts.Where(p=> p.ACL.Count==0 || p.ACL.Any(a => usercircles.Contains(a.CircleId)))
: allposts.Where(p => p.ACL.Count == 0);
var data = posts.OrderByDescending( p=> p.DateCreated).ToArray();
var data = posts.OrderByDescending( p=> p.DateCreated);
var grouped = data.GroupBy(p=> p.Title).Skip(skip).Take(maxLen);
return View("Default", grouped);

@ -18,7 +18,7 @@ namespace Yavsc.ViewComponents
public async Task<IViewComponentResult> InvokeAsync (
string htmlFieldName,
string calId = null)
string calId )
{
var minDate = DateTime.Now;
var maxDate = minDate.AddDays(20);
@ -30,18 +30,6 @@ namespace Yavsc.ViewComponents
return View(model);
}
public async Task<IViewComponentResult> InvokeAsync (
string htmlFieldName)
{
var minDate = DateTime.Now;
var maxDate = minDate.AddDays(20);
var model = await _manager.CreateViewModelAsync(
htmlFieldName,
null, minDate, maxDate
);
return View(model);
}
}
}

@ -42,7 +42,7 @@ namespace Yavsc.ViewModels.Manage
public string PostalAddress { get; set; }
public BankIdentity BankInfo { get; set; }
public List<BankIdentity> BankInfo { get; set; }
public long DiskQuota { get; set; }
public long DiskUsage { get; set; }

@ -163,10 +163,10 @@
Facture acquittée.
}{ </text>
var bi = from.BankInfo;
if (bi!=null) {
if (from.BankInfo!=null) foreach (var bi in from.BankInfo){
<text>À régler par chèque ou par virement bancaire :
\begin{center}
\begin{tabular}{|c c c c|}
@if (!string.IsNullOrWhiteSpace(bi.BankCode) && !string.IsNullOrWhiteSpace(bi.WicketCode)

Loading…