public async Task<ValidationResult> DeleteComment(DeleteCommentDTO model) { try { //Find and delete the comment EventComment comment = await _commentsRepo.GetByIdAsync(model.CommentId); if (comment == null) return AddError("Comment could not be found"); if(comment.EventId != model.EventId && comment.CreatorId != model.UserId) return AddError("No Comment matching the EventId and/or the UserId could be found"); _commentsRepo.Delete(comment); await SaveChangesAsync(); Result.Success = true; return Result; } catch (Exception ex) { return AddError(ex.Message); } }
public async Task<IHttpActionResult> DeleteComment(DeleteCommentDTO model) { if (!ModelState.IsValid) return BadRequest(); var result = await _commentService.DeleteComment(model); if (result.Success) { return Ok(); } return BadRequest(result.Error); }