Ejemplo n.º 1
0
 public static TopicResultDto Create(Topic topic)
 {
     return(new TopicResultDto
     {
         Uri = topic.Uri,
         Title = topic.Title,
         Category = ViewCategoryDto.Create(topic.Category),
         User = ViewUserDto.Create(topic.User),
         NumberOfComments = topic.Comments.Count,
         NumberOfViews = topic.Views.Count,
         CreatedAt = DateTime.SpecifyKind(topic.CreatedAt, DateTimeKind.Utc)
     });
 }
Ejemplo n.º 2
0
 public static ViewTopicDto Create(string userId, Topic topic, bool isBookmarked)
 {
     return(new ViewTopicDto
     {
         Id = topic.Id,
         Title = topic.Title,
         Content = topic.Content,
         Uri = topic.Uri,
         Category = ViewCategoryDto.Create(topic.Category),
         User = ViewUserDto.Create(topic.User),
         CreatedAt = topic.CreatedAt,
         NumberOfUpVotes = topic.Votes.Count(c => c.IsUp),
         NumberOfDownVotes = topic.Votes.Count(c => !c.IsUp),
         IsUpVoted = userId != null?topic.Votes.FirstOrDefault(c => c.UserId.Equals(userId))?.IsUp : null,
         IsBookmarked = isBookmarked,
         Comments = topic.Comments.Select(c => ViewCommentDto.Create(userId, c))
     });
 }