public async Task <ActionResult <GastoResource> > UpdateGasto(Guid id, [FromBody] SaveGastoResource saveGastoResource) { var validator = new SaveGastoResourceValidator(); var validationResult = await validator.ValidateAsync(saveGastoResource); var requestIsInvalid = id == null || !validationResult.IsValid; if (requestIsInvalid) { return(BadRequest(validationResult.Errors)); } var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var gastoToBeUpdated = await _gastoService.GetGastoById(id, userId); if (gastoToBeUpdated == null) { return(NotFound()); } var gasto = _mapper.Map <SaveGastoResource, Gasto>(saveGastoResource); await _gastoService.UpdateGasto(gastoToBeUpdated, gasto); var updatedGasto = await _gastoService.GetGastoById(id, userId); var updateGastoResource = _mapper.Map <Gasto, GastoResource>(updatedGasto); return(Ok(updateGastoResource)); }
//[HttpOptions] public async Task <IActionResult> Put(int id, GastoCreacionDto gastoDto) => Ok(new ApiResponse <bool>(await _gastoService.UpdateGasto(id, gastoDto)));