public static async Task <AlbumItem> GetMediaAsync( ApplicationDbContext dbContext, int mediaId) { UserMedia entity = await dbContext.UserMedias .Include(a => a.Description) .Include(a => a.Likes.Select(like => like.User)) .Include(a => a.CommentThread.Comments.Select(c => c.Text)) .Include(a => a.CommentThread.Comments.Select(c => c.User.Avatar)) .SingleOrDefaultAsync(a => a.UserMediaId == mediaId); if (entity == null) { return(null); } return(new AlbumItem { Id = entity.UserMediaId, UserId = entity.UserId, Title = entity.Title, Description = entity.Description?.Content, CreatedTime = entity.CreatedUtc.ToString("s"), CreatedTimeAgo = TimeOperations.GetTimeAgo(entity.CreatedUtc), MediaUrl = UserMediaOperations.GetUrl(entity), LikeUrl = UserMediaOperations.GetLikeUrl(entity), LikeGroups = LikeOperations.MakeLikeGroups(entity.Likes), CommentUrl = UserMediaOperations.GetCommentUrl(entity), Comments = CommentOperations.GetComments(entity.CommentThread) }); }
public static IList <CommentDetails> GetComments(CommentThread commentThread) { if (commentThread == null) { return(new CommentDetails[0]); } return(commentThread.Comments .OrderBy(c => c.Text.CreatedUtc) .Select( c => new CommentDetails { UserName = c.User.Name, UserId = c.UserId, AvatarUrl = UserOperations.GetAvatarUrl(c.User), Message = c.Text.Content, TimeAgo = TimeOperations.GetTimeAgo(c.Text.CreatedUtc), LikeUrl = $"/api/Comments/{c.CommentId}/Like", LikeGroups = LikeOperations.MakeLikeGroups(c.Text.Likes) }) .ToList()); }