public async Task <List <TimeLineVM> > GetTimeLine(int userId, int pageIndex) { List <int> followings = await _followService.FollowingList(userId); var posts = await _unitOfWork.Post.GetFilteredList( selector : x => new TimeLineVM { Id = x.Id, Text = x.Text, ImagePath = x.ImagePath, AppUserId = x.AppUserId, LikeCounts = x.Likes.Count, CommentCounts = x.Comments.Count, ShareCounts = x.Shares.Count, CreateDate = x.CreateDate, UserName = x.AppUser.UserName, UserImage = x.AppUser.ImagePath, isLiked = x.Likes.Any(y => y.AppUserId == userId) }, orderBy : x => x.OrderByDescending(y => y.CreateDate), predicate : x => followings.Contains(x.AppUserId), include : x => x.Include(z => z.AppUser).ThenInclude(z => z.Followers).Include(z => z.Likes), pageIndex : pageIndex); return(posts); }
public async Task <List <FollowListVM> > UserFollowings(int id, int pageIndex) { List <int> followings = await _followService.FollowingList(id); var followingsList = await _unitOfWork.AppUser.GetFilteredList(selector : y => new FollowListVM { Id = y.Id, ImagePath = y.ImagePath, UserName = y.UserName, }, predicate : x => followings.Contains(x.Id), include : x => x .Include(z => z.Followers), pageIndex : pageIndex); return(followingsList); }
public async Task <List <TimelineVm> > GetTimeline(int userId, int pageIndex) { List <int> followings = await _followService.FollowingList(userId); var posts = await _unitOfWork.Post.GetFilteredList( selector : x => new TimelineVm { Id = x.Id, Text = x.Text, ImagePath = x.ImagePath, AppUserId = x.AppUserId, LikesCount = x.Likes.Count, MentionsCount = x.Mentions.Count, SharesCount = x.Shares.Count, CreateDate = x.CreateDate, UserName = x.AppUser.UserName, UserImage = x.AppUser.ImagePath, Name = x.AppUser.Name, isLiked = x.Likes.Any(h => h.AppUserId == userId) }, orderBy : z => z.OrderByDescending(a => a.CreateDate), predicate : a => followings.Contains(a.AppUserId), include : a => a.Include(h => h.AppUser).ThenInclude(h => h.Followers).Include(h => h.Likes), pageIndex : pageIndex); //This is AutoMapper usage. //var posts = await _context.Posts // .Include(x => x.AppUser).ThenInclude(x => x.Followers) // .Include(x => x.Likes) // .ProjectTo<TimelineVm>(_mapper.ConfigurationProvider, new { userId }) // .Where(x => followings.Contains(x.AppUserId)) // .OrderByDescending(x => x.CreateDate).ToListAsync(); return(posts); }