public virtual async Task UpdateCustomCurrencyAsync(CreateCustomCurrencyInput input) { if (input.Online == true) { try { string url = string.Format("http://download.finance.yahoo.com/d/quotes.csv?s={0}{1}=X&f=l1", "USD", input.Code); HttpClient client = new HttpClient(); var response = await client.GetStringAsync(url); decimal exchangeRate = decimal.Parse(response, System.Globalization.CultureInfo.InvariantCulture); input.ConversionRatio = Math.Round(exchangeRate, 3); } catch (Exception ex) { input.ConversionRatio = 0; } } input.TenantId = (int)(AbpSession.TenantId); var Currency = input.MapTo <CustomCurrency>(); var val = _CustomcurrencyRepository .GetAll().Where(p => p.CurrencyId == input.CurrencyId && p.TenantId == input.TenantId && p.Id != input.Id).FirstOrDefault(); if (val == null) { await _CustomcurrencyRepository.UpdateAsync(Currency); } else { throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in Currency ..."); } }
public async Task CreateOrUpdateCustomCurrency(CreateCustomCurrencyInput input) { if (input.Id != 0) { await UpdateCustomCurrencyAsync(input); } else { await CreateCustomCurrencyAsync(input); } }