Blog presentation

This commit is contained in:
Paul Schneider
2024-12-03 01:44:58 +00:00
parent a4932d08f1
commit f91f000405
7 changed files with 58 additions and 52 deletions

View File

@ -14,7 +14,7 @@ namespace Yavsc.Helpers
{
return user.FindFirstValue("sub");
}
public static string GetUserName(this ClaimsPrincipal user)
{
return user.FindFirstValue(ClaimTypes.Name);
@ -27,21 +27,28 @@ namespace Yavsc.Helpers
public static IEnumerable<BlogPost> UserPosts(this ApplicationDbContext dbContext, string posterId, string readerId)
{
long[] readerCirclesMemberships = dbContext.Circle.Include(c=>c.Members).Where(c=>c.Members.Any(m=>m.MemberId == readerId))
.Select(c=>c.Id).ToArray();
var result = (readerId!=null)
?
dbContext.Blogspot.Include(
b => b.Author
).Include(p=>p.ACL).Where(x => x.Author.Id == posterId &&
(x.Visible &&
(x.ACL.Count==0 || x.ACL.Any(a=> readerCirclesMemberships.Contains(a.CircleId)))))
:
dbContext.Blogspot.Include(
if (readerId == null)
{
var userPosts = dbContext.Blogspot.Include(
b => b.Author
).Where(x => x.Author.Id == posterId && x.Visible);
// BlogIndexKey
return result;
).Where(x => ((x.AuthorId == posterId) && (x.Visible))).ToArray();
return userPosts;
}
else
{
long[] readerCirclesMemberships =
dbContext.Circle.Include(c => c.Members)
.Where(c => c.Members.Any(m => m.MemberId == readerId))
.Select(c => c.Id).ToArray();
return dbContext.Blogspot.Include(
b => b.Author
).Include(p => p.ACL).Where(x => x.Author.Id == posterId &&
(x.Visible &&
(x.ACL.Count == 0 || x.ACL.Any(a => readerCirclesMemberships.Contains(a.CircleId)))));
}
}
}
}