/// <summary> /// /// </summary> /// <param name="entity"></param> /// <param name="model"></param> /// <returns></returns> public static Currency Update(this Currency entity, CurrencyUpdateModel model) { if (entity == null) { return(null); } entity.IsoNumber = model.IsoNumber > 0 ? model.IsoNumber : entity.IsoNumber; entity.IsoCode = !string.IsNullOrWhiteSpace(model.Code) ? model.Code : entity.IsoCode; entity.Name = !string.IsNullOrWhiteSpace(model.Name) ? model.Name : entity.Name; entity.Country = !string.IsNullOrWhiteSpace(model.Country) ? model.Country : entity.Country; return(entity); }
public async Task <IActionResult> Put([FromRoute] IsoCode code, [FromBody] CurrencyUpdateModel model, CancellationToken token = default) { try { var updateCurrency = await _currencyService.GetCurrencyByIsoCode(code.IsoCodeValue, true, token) .ConfigureAwait(false); if (updateCurrency == null) { return(NotFoundObjectResult(nameof(CurrencyService), "currency don't exist")); } await _repository.UpdateAsync(updateCurrency.Update(model), token : token).ConfigureAwait(false); await _currencyService.ClearCurrencyCacheAsync(); return(OkObjectResult(updateCurrency.ToModel())); } catch (Exception e) { return(LogAndError500Response(nameof(CurrenciesController), e)); } }