示例#1
0
 public static LikeViewModel FromLike(Like like)
 {
     return(new LikeViewModel
     {
         Id = like.Id,
         User = UserSummaryViewModel.FromUser(like.User)
     });
 }
示例#2
0
 public static MediaViewModel FromMedia(Media media) => new MediaViewModel
 {
     Id        = media.Id,
     MediaType = media.MediaType,
     MimeType  = media.MimeType,
     FileSize  = media.FileSize,
     Owner     = UserSummaryViewModel.FromUser(media.Owner)
 };
示例#3
0
 public static RepostViewModel FromRepost(Repost repost)
 {
     return(new RepostViewModel
     {
         Id = repost.Id,
         User = UserSummaryViewModel.FromUser(repost.User)
     });
 }
示例#4
0
        public static PublicationViewModel FromPublication(Publication publication, Guid?userId = null)
        {
            return(new PublicationViewModel
            {
                Id = publication.Id,

                CreationDate = publication.CreationDate,
                SubmissionType = publication.SubmissionType,
                TextContent = publication.TextContent,
                MediaId = publication.MediaId == null ? null : publication.MediaId,

                ReplyPublicationId = publication.ReplyPublicationId,
                User = UserSummaryViewModel.FromUser(publication.User),

                RepliesAmount = publication.Replies != null ? publication.Replies.Count : -1,
                RepostsAmount = publication.Reposts != null ? publication.Reposts.Count : -1,
                LikesAmount = publication.Likes != null ? publication.Likes.Count : -1,

                Reposted = userId.HasValue && publication.Reposts.Any(x => x.UserId == userId),
                Liked = userId.HasValue && publication.Likes.Any(x => x.UserId == userId)
            });
        }