public async Task <IActionResult> PutAsync(int id, [FromBody] SaveCommentResource resource) { var comment = _mapper.Map <SaveCommentResource, Comment>(resource); var result = await _commentService.UpdateAsync(id, comment); if (!result.Succes) { return(BadRequest(result.Message)); } var commentResource = _mapper.Map <Comment, CommentResource>(result.Resource); return(Ok(commentResource)); }
public async Task <IActionResult> addUserComment(string phoneNumber, [FromBody] SaveCommentResource commentResource) { var user = await userRepository.GetOne(phoneNumber); if (user == null) { return(NotFound()); } var comment = mapper.Map <SaveCommentResource, Comment>(commentResource); comment.Date = DateTime.Now; user.Comments.Add(comment); await unitOfWork.CompleteAsync(); return(Ok()); }
public async Task <IActionResult> PostAsync(SaveCommentResource resource) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } var comment = _mapper.Map <SaveCommentResource, Comment>(resource); var result = await _commentService.SaveAsync(comment); if (!result.Success) { return(BadRequest(result.Message)); } var commentResource = _mapper.Map <Comment, CommentResource>(result.Resource); return(Ok(commentResource)); }
public async Task <IActionResult> PostAsync(int commenterId, int publicationId, [FromBody] SaveCommentResource resource) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } var existingAccount = await _accountService.GetByIdAsync(commenterId); if (!existingAccount.Success) { return(BadRequest(existingAccount.Message)); } var existingPublication = await _publicationService.GetByIdAsync(publicationId); if (!existingPublication.Success) { return(BadRequest(existingPublication.Message)); } var comment = _mapper.Map <SaveCommentResource, Comment>(resource); comment.Commenter = existingAccount.Resource; comment.Publication = existingPublication.Resource; var result = await _commentService.SaveAsync(comment); if (!result.Success) { return(BadRequest(result.Message)); } var commentResource = _mapper.Map <Comment, CommentResource>(result.Resource); return(Ok(commentResource)); }