public static WallPostsViewModel Create(Post p, ApplicationUser currentUser) { return new WallPostsViewModel() { Id = p.Id, Author = new UserViewModelMinified() { Id = p.OwnerId, Gender = p.Owner.Gender, Name = p.Owner.Name, ProfileImageData = p.Owner.ProfileImageData, Username = p.Owner.UserName }, WallOwner = new OwnerViewModel {Id = p.OwnerId, Username = p.Owner.UserName}, PostContent = p.Content, Date = p.CreatedOn, LikesCount = p.Likes.Count, Liked = p.Likes .Any(l => l.UserId == currentUser.Id), TotalCommentsCount = p.Comments.Count, Comments = p.Comments .Take(3) .Select(c => CommentViewModel.CreateCommentAndUser(c, currentUser)) }; }
public static UserViewModelPreview Create(ApplicationUser user, ApplicationUser loggedUser) { return new UserViewModelPreview() { Id = user.Id, Name = user.Name, Username = user.UserName, Gender = user.Gender, ProfileImageData = user.ProfileImageData, IsFriend = user.Friends .Any(fr => fr.Id == loggedUser.Id), HasPendingRequest = user.FriendRequests .Any(r => r.Status == FriendRequestStatus.Pending && (r.FromId == loggedUser.Id || r.ToId == loggedUser.Id)) }; }
public static CommentViewModel CreateCommentAndUser(Comment c, ApplicationUser currentUser) { return new CommentViewModel() { Id = c.Id, Author = new UserViewModelMinified() { Id = c.CommentOwner.Id, Gender = c.CommentOwner.Gender, Name = c.CommentOwner.Name, ProfileImageData = c.CommentOwner.ProfileImageData, Username = c.CommentOwner.UserName }, LikesCount = c.Likes.Count, Content = c.Content, CreatedOn = c.CreatedOn, IsLiked = c.Likes.Any(l => l.UserId == currentUser.Id) }; }