public void RemoveComment(CommentDeleteModel commentToDelete) { var entity = _ctx.Comments.Single(e => e.CommentId == commentToDelete.CommentId); _ctx.Comments.Remove(entity); _ctx.SaveChanges(); }
public IHttpActionResult Delete(CommentDeleteModel commentToDelete) { var service = CreateCommentService(); service.RemoveComment(commentToDelete); return(Ok()); }
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(); }
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()); }