static async Task UpdateCurrencies(RatesContext context, IDictionary <string, string> symbols) { var currencies = await context.Currencies.ToListAsync(); var toUpdate = new List <Currency>(); var toAdd = new List <Currency>(); foreach ((var symbol, var name) in symbols) { var currency = currencies.SingleOrDefault(c => c.Symbol == symbol); if (currency is null) { currency = new Currency { Symbol = symbol, FullName = name }; toAdd.Add(currency); } else { currency.FullName = name; toUpdate.Add(currency); } } context.AddRange(toAdd); context.UpdateRange(toUpdate); await context.SaveChangesAsync(); }
public async Task SaveChanges() { await context.SaveChangesAsync(); }