using System.Collections.Generic; using System.Linq; using BlueWest.Data; using Microsoft.EntityFrameworkCore; namespace BlueWest.WebApi.EF { internal static class CurrencyExtensions { internal static Currency GetCurrencyById(this DbSet currencies, int currencyId) => currencies.GetOne(x => x.Id == currencyId); internal static (bool, T) NotFound() where T : class => (false, null); internal static (bool, Currency) AddCurrency(this CountryDbContext dbContext, CurrencyCreate currencyToCreate) { var newCurrency = new Currency(currencyToCreate); return dbContext.Currencies.Add(dbContext, 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(); var newCurrency = new Currency(currencyToUpdate); var operationResult = dbContext.Currencies.Update(dbContext, newCurrency); return operationResult; } } }