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 async Task <AlbumDetail> GetAlbumAsync( ApplicationDbContext dbContext, int albumId) { MediaAlbum entity = await dbContext.MediaAlbums .Include(a => a.UserMedias.Select(um => um.Description)) .Include(a => a.UserMedias.Select(um => um.Likes.Select(like => like.User))) .Include(a => a.UserMedias.Select(um => um.CommentThread.Comments.Select(c => c.Text))) .Include(a => a.UserMedias.Select(um => um.CommentThread.Comments.Select(c => c.User.Avatar))) .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.MediaAlbumId == albumId); if (entity == null) { return(null); } return(new AlbumDetail { Title = entity.Title, UserId = entity.UserId, Description = entity.Description, Items = entity.UserMedias .Select( um => new AlbumItem { Id = um.UserMediaId, UserId = um.UserId, Title = um.Title, Description = um.Description?.Content, CreatedTime = um.CreatedUtc.ToString("s"), CreatedTimeAgo = TimeOperations.GetTimeAgo(um.CreatedUtc), MediaUrl = UserMediaOperations.GetUrl(um), LikeUrl = UserMediaOperations.GetLikeUrl(um), LikeGroups = LikeOperations.MakeLikeGroups(um.Likes), CommentUrl = UserMediaOperations.GetCommentUrl(um), Comments = CommentOperations.GetComments(um.CommentThread) }) .ToList(), LikeUrl = $"/api/Albums/{entity.MediaAlbumId}/Like", LikeGroups = LikeOperations.MakeLikeGroups(entity.Likes), CommentUrl = $"/api/Albums/{entity.MediaAlbumId}/Comment", Comments = CommentOperations.GetComments(entity.CommentThread) }); }