yavsc/src/Yavsc/Helpers/UserHelpers.cs

31 lines
1.1 KiB
C#
Raw Normal View History

2018-11-20 15:50:04 +01:00
using System.Collections.Generic;
2017-02-01 19:53:10 +01:00
using System.Linq;
2018-11-20 15:50:04 +01:00
using Microsoft.Data.Entity;
2017-02-01 19:53:10 +01:00
using Yavsc.Models;
2018-11-20 15:50:04 +01:00
using Yavsc.Models.Blog;
2017-02-01 19:53:10 +01:00
namespace Yavsc.Helpers
{
public static class UserHelpers
{
2018-11-20 15:50:04 +01:00
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);
}
2017-02-01 19:53:10 +01:00
}
}