예제 #1
0
        public Task <Either <ActionResult, CommentViewModel> > AddCommentAsync(Guid releaseId,
                                                                               Guid contentSectionId,
                                                                               Guid contentBlockId,
                                                                               AddOrUpdateCommentRequest request)
        {
            return(CheckContentSectionExists(releaseId, contentSectionId)
                   .OnSuccess(CheckCanUpdateRelease)
                   .OnSuccess(async tuple =>
            {
                var(_, section) = tuple;

                var contentBlock = section.Content.Find(block => block.Id == contentBlockId);

                if (contentBlock == null)
                {
                    return ValidationActionResult <CommentViewModel>(ContentBlockNotFound);
                }

                var comment = new Comment
                {
                    Id = new Guid(),
                    ContentBlockId = contentBlockId,
                    Content = request.Content,
                    Created = DateTime.UtcNow,
                    CreatedById = _userService.GetUserId()
                };

                await _context.Comment.AddAsync(comment);
                await _context.SaveChangesAsync();
                return await GetCommentAsync(comment.Id);
            }
                              ));
        }
예제 #2
0
 public Task <Either <ActionResult, CommentViewModel> > UpdateCommentAsync(Guid commentId,
                                                                           AddOrUpdateCommentRequest request)
 {
     return(_persistenceHelper.CheckEntityExists <Comment>(commentId)
            .OnSuccess(_userService.CheckCanUpdateComment)
            .OnSuccess(async comment =>
     {
         _context.Comment.Update(comment);
         comment.Content = request.Content;
         comment.Updated = DateTime.UtcNow;
         await _context.SaveChangesAsync();
         return await GetCommentAsync(commentId);
     }
                       ));
 }