public UpdateBreweryPayload UpdateBrewery( UpdateBreweryInput input, [Service] IBreweryValidationConductor validationConductor, [Service] IBreweryConductor breweryConductor, [Service] IMapper mapper, CancellationToken cancellationToken) { var dto = mapper.Map <DTO.Brewery>(input); if (!validationConductor.CanUpdate(dto.Id ?? default, dto, out var errors)) { return(new UpdateBreweryPayload( errors.Select(err => new UserError(err.message, err.key)).ToList(), input.ClientMutationId)); } var brewery = breweryConductor.Update(mapper.Map <Entity.Brewery>(dto)); if (!brewery.HasErrors && !(brewery.ResultObject is null)) { return(new UpdateBreweryPayload(brewery.ResultObject, input.ClientMutationId)); } return(new UpdateBreweryPayload( brewery.Errors.Select(err => new UserError(err.Message, err.Key)).ToList(), input.ClientMutationId)); }
public IActionResult Update( [FromRoute] long id, [FromBody] DTO.Brewery dto) { // Validation if (!_validationConductor.CanUpdate(id, dto, out _)) { return(BadRequest()); } var brewery = _breweryConductor.Update(_mapper.Map <Brewery>(dto)); if (brewery.HasErrors || brewery.ResultObject is null) { return(BadRequest(brewery.Errors)); } _ = _mapper.Map <DTO.Brewery>(brewery.ResultObject); return(Ok()); }