public BriefPostDTO Map(Post post) { return new BriefPostDTO { PostId = post.PostId, PostText = post.Text, CreatedAt = post.CreatedAt, ModifiedAt = post.ModifiedAt, Author = _userToUserDtoMapper.Map(post.User), CommentCount = post.Comments.Count() }; }
public PostDTO Map(Post post) { return new PostDTO { PostId = post.PostId, PostText = post.Text, CreatedAt = post.CreatedAt, ModifiedAt = post.ModifiedAt, Author = _userToUserDtoMapper.Map(post.User), Comments = _commentToCommentDtoMapper.Map(post.Comments) }; }
public PostDTO CreatePost(BlogContext context, string sessionToken, string postText) { var user = _authenticationService.GetUserBySessionToken(context, sessionToken); var post = new Post { User = user, Text = postText, CreatedAt = DateTime.UtcNow, ModifiedAt = null, Comments = new List<Comment>() }; post = context.Posts.Add(post); context.SaveChanges(); return _postToPostDtoMapper.Map(post); }