public async Task <ExampleUpdateResponse> UpdateAsync(int id, ExampleUpdateRequest request) => await ExecuteAsync(async() => { var response = new ExampleUpdateResponse(); var example = await _exampleRepository.GetByIdAsync(id, false).ConfigureAwait(false); if (example != null) { //Changing property example.Update(request.Age, request.Name); //Validate example.Validate(example, new ExampleValidator()); if (!example.Valid) { _notification.AddNotifications(example.ValidationResult); return(response); } await _exampleRepository.UpdateAsync(example).ConfigureAwait(false); } else { throw new NotFoundException(); } return(response); });
public async Task <IActionResult> UpdateAsync([FromRoute] int id, [FromBody] ExampleUpdateRequest request) => Response(await _exampleService.UpdateAsync(id, request).ConfigureAwait(false));