factorisation

This commit is contained in:
2018-11-20 15:50:04 +01:00
parent 02a582bf0f
commit 10ad16b639
2 changed files with 28 additions and 19 deletions

View File

@ -1,5 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Data.Entity;
using Yavsc.Models;
using Yavsc.Models.Blog;
namespace Yavsc.Helpers
{
@ -21,5 +24,24 @@ namespace Yavsc.Helpers
var avatar = user.UserName;
return $"/Avatars/{avatar}{imgFmt}.png";
}
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(
b => b.Author
).Where(x => x.Author.Id == posterId && x.Visible);
// BlogIndexKey
return result.OrderByDescending(p => p.DateCreated);
}
}
}