using System.Collections.Generic; using System.Linq; using BlueWest.Data; using Microsoft.EntityFrameworkCore; namespace BlueWest.WebApi.EF { internal static class CurrencyExtensions { internal static (bool, Currency) NotFound() => (false, null); internal static (bool, Currency) AddCurrency(this CountryDbContext dbContext, CurrencyCreate currencyToCreate) { var newCurrency = new Currency(currencyToCreate); dbContext.Add(newCurrency); var resultOperation = dbContext.SaveChanges() >= 0; return (resultOperation, newCurrency); } internal static (bool, Currency) UpdateCurrency(this CountryDbContext dbContext, int currencyId, CurrencyUpdate currencyToUpdate) { var currency = dbContext.Currencies.FirstOrDefault(x => x.Id == currencyId); if (currency == null) return NotFound(); currency.Update(currencyToUpdate); dbContext.Update(currency); var resultOperation = dbContext.SaveChanges() >= 0; return (resultOperation, currency); } } }