public OperationResult Delete(int id) { using (var configurationSettingsRepository = repositoryFactory.CreateConfigurationSettingsRepository()) { var entity = configurationSettingsRepository.GetById(id); if (entity == null) { return(OperationResult.Error("not found")); } configurationSettingsRepository.Remove(id); configurationSettingsRepository.Commit(); return(OperationResult.Succeed()); } }
private async Task <List <Currency> > GetApiCurrencies() { if (!IsConfigued()) { return(CreateDefault().ToList()); } var configurationSettingsRepository = repositoryFactory.CreateConfigurationSettingsRepository(); using (var httpClient = new HttpClient()) { var baseUrl = configurationSettingsRepository.GetValue(ApiUrlKey); var apiKey = configurationSettingsRepository.GetValue(AppIdKey); httpClient.BaseAddress = new Uri(baseUrl); var response = await httpClient.GetAsync($"latest.json?app_id={apiKey}"); response.EnsureSuccessStatusCode(); var content = (await response.Content.ReadAsStringAsync()).Replace(@"\n", ""); var values = JsonConvert.DeserializeObject <Latest>(content); return(values .Rates .Where(x => supportedCurrencies.Any(y => y.Equals(x.Key))) .Select(x => new Currency { Name = x.Key, Value = x.Value, ChangeStamp = DateTime.Now }) .ToList()); } }