public async Task <IActionResult> Edit([FromQuery] Guid id, [FromBody] CommentPutDto commentPutDto) { if (id != commentPutDto.ID) { return(BadRequest()); } await commentService.UpdateAsync(commentPutDto); return(NoContent()); }
public async Task EditAsync(CommentPutDto commentPutDto) { var commentToEdit = await _mongoRepository.FindByIdAsync(commentPutDto.Id); if (commentToEdit == null) { throw new ArgumentNullException($"Comment with id {commentPutDto.Id} does not exist"); } commentToEdit.Text = commentPutDto.Text; await _mongoRepository.ReplaceOneAsync(commentToEdit); }
public async Task <bool> UpdateAsync(CommentPutDto proPlanPutDto) { CommentPutDtoValidator validator = new CommentPutDtoValidator(); ValidationResult results = validator.Validate(proPlanPutDto); if (!results.IsValid) { throw new ValidationException("proPlanPutDTO", string.Join(". ", results.Errors)); } Comment project = await _repository.GetByIdAsync(proPlanPutDto.ID); if (project == null) { throw new NotFoundException($"The server can not find the requested Comment with ID: {proPlanPutDto.ID}"); } return(await _repository.UpdateAsync(mapper.Map <Comment>(proPlanPutDto)) != null); }
public async Task <IActionResult> Edit(CommentPutDto commentPutDto) { await _commentService.EditAsync(commentPutDto); return(NoContent()); }