コード例 #1
0
        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)
            });
        }
コード例 #2
0
        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)
            });
        }
コード例 #3
0
        public static async Task <IList <AlbumSummary> > GetAlbumSummariesAsync(
            ApplicationDbContext dbContext,
            UserInfo user)
        {
            var results = await dbContext.MediaAlbums
                          .Where(a => a.UserId == user.UserInfoId)
                          .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))
                          .Select(a =>
                                  new
            {
                a.MediaAlbumId,
                a.Title,
                a.Description,
                Medias      = a.UserMedias.Take(4),
                LatestMedia = a.UserMedias.OrderByDescending(um => um.CreatedUtc).FirstOrDefault(),
                Likes       = a.Likes,
                a.CommentThread
            })
                          .ToListAsync();

            return(results
                   .Select(
                       a =>
                       new AlbumSummary
            {
                Id = a.MediaAlbumId,
                UserId = user.UserInfoId,
                Title = a.Title,
                Description = a.Description,
                SampleMediaUrls = a.Medias.Select(UserMediaOperations.GetUrl).ToList(),
                LastModifiedText = a.LatestMedia != null
                            ? TimeOperations.GetTimeAgo(a.LatestMedia.CreatedUtc)
                            : "",
                LikeUrl = $"/api/Albums/{a.MediaAlbumId}/Like",
                LikeGroups = LikeOperations.MakeLikeGroups(a.Likes),
                CommentUrl = $"/api/Albums/{a.MediaAlbumId}/Comment",
                Comments = CommentOperations.GetComments(a.CommentThread)
            })
                   .ToList());
        }
コード例 #4
0
ファイル: CommentOperations.cs プロジェクト: jenyayel/rgroup
        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());
        }