Ejemplo n.º 1
0
        public void RemoveComment(CommentDeleteModel commentToDelete)
        {
            var entity = _ctx.Comments.Single(e => e.CommentId == commentToDelete.CommentId);

            _ctx.Comments.Remove(entity);
            _ctx.SaveChanges();
        }
Ejemplo n.º 2
0
        public IHttpActionResult Delete(CommentDeleteModel commentToDelete)
        {
            var service = CreateCommentService();

            service.RemoveComment(commentToDelete);
            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task DeleteAsync(CommentDeleteModel commentModel)
        {
            var comment = await GetCommentOnEditOrDeleteAsync(commentModel.ParentQuestionId, commentModel.ParentAnswerId, commentModel.CommentId);

            var votesSum = await _voteRepository.CountAsync(v => v.CommentId == commentModel.CommentId);

            if (votesSum > 0)
            {
                throw new BusinessException($"Cannot delete comment '{commentModel.CommentId}' because associated votes exist.");
            }
            _commentRepository.Delete(comment);
            await _uow.SaveAsync();
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> DeleteOnAnswerAsync(
            [FromRoute] Guid questionId,
            [FromRoute] Guid answerId,
            [FromRoute] Guid commentId)
        {
            var comment = new CommentDeleteModel
            {
                ParentQuestionId = questionId,
                ParentAnswerId   = answerId,
                CommentId        = commentId
            };
            await _commentService.DeleteAsync(comment);

            return(NoContent());
        }