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