Example #1
0
        private static async Task <IList <TimelineEntryDetails> > EntriesQueryToDetailsAsync(
            IQueryable <TimelineEntry> q)
        {
            var results = await q
                          .Include(te => te.User.Avatar)
                          .Include(te => te.Message.Likes.Select(like => like.User))
                          .Include(te => te.CommentThread.Comments.Select(c => c.Text))
                          .Include(te => te.CommentThread.Comments.Select(c => c.User.Avatar))
                          .Select(
                te =>
                new
            {
                te.TimelineEntryId,
                User     = te.User,
                Message  = te.Message.Content,
                DateTime = te.Message.CreatedUtc,
                Media    = te.Media.Select(tme => tme.Media),
                Likes    = te.Message.Likes,
                te.CommentThread
            })
                          .ToListAsync();

            return(results.Select(
                       te =>
                       new TimelineEntryDetails
            {
                UserId = te.User.UserInfoId,
                UserName = te.User.Name,
                AvatarUrl = UserOperations.GetAvatarUrl(te.User),
                Message = te.Message,
                DateTime = te.DateTime.ToString("s"),
                MediaUrls = te.Media.Select(UserMediaOperations.GetUrl).ToList(),
                LikeUrl = $"/api/Timeline/{te.TimelineEntryId}/Like",
                LikeGroups = LikeOperations.MakeLikeGroups(te.Likes),
                CommentUrl = $"/api/Timeline/{te.TimelineEntryId}/Comment",
                Comments = CommentOperations.GetComments(te.CommentThread)
            })
                   .ToList());
        }
Example #2
0
        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());
        }