Exemplo n.º 1
0
        public async Task <CommentDTO> CreateAsync(CommentDTO comment)
        {
            var currentUser = _userContext.CurrentUser;

            if (comment.CreatedDate == default(DateTime))
            {
                comment.CreatedDate = DateTime.Now;
            }
            comment.UserId = currentUser.Id;

            var commentToSave = CommentMapper.ConvertToComment(comment);

            var createdComment = await _db.Comments.CreateAsync(commentToSave);

            await _db.SaveAsync();

            var createdCommentDTO = CommentMapper.ConvertToCommentDTO(createdComment);

            createdCommentDTO.UserDTO = currentUser;
            return(createdCommentDTO);
        }