public async ValueTask <IActionResult> Post([FromBody] CommentViewModel model) { if (ModelState.IsValid) { Comment comment = model.Convert <CommentViewModel, Comment>(_mapper); comment.DatePosted = DateTime.Now; (bool succeeded, Comment addedComment, string error) = await _repo.Add(comment); if (succeeded) { return(Ok(addedComment.Convert(_mapper))); } return(BadRequest(new ErrorDTO { Message = error })); } return(base.BadRequest(ShowError())); }
public async ValueTask <IActionResult> Put([FromBody] CommentViewModel model) { if (ModelState.IsValid) { if (model.Id != 0) { Comment comment = model.Convert <CommentViewModel, Comment>(_mapper); (bool succeeded, Comment updatedComment, string error) = await _repo.Update(comment, model.Id); if (succeeded) { return(Ok(updatedComment.Convert(_mapper))); } return(NotFound(new ErrorDTO { Message = error })); } } return(BadRequest(ShowError())); }