public static void SaveCoins(Country country, List <CoinDiffusion> coins, DAL.EuroContext context, bool isCommemorative = false) { var template = new Coin(); var loadCoins = context.Coin.ToList(); foreach (var coin in coins) { template.CountryId = country.Id; template.Year = coin.Year; template.Diffusion = coin.Diffusion; template.Name = coin.Name; template.Url = coin.Url; template.Valeur = coin.Valeur; template.IsCommemorative = coin.IsCommemorative; if (!loadCoins.Any(m => m.IsCommemorative == template.IsCommemorative && m.Year == template.Year && m.Name == template.Name && m.Url == template.Url && m.Valeur == template.Valeur && m.Year == template.Year && m.CountryId == m.CountryId)) { context.Coin.Add(template); context.SaveChanges(); } } }
public void Populate(DAL.EuroContext context) { _context = context; _country = context.Country.Single(m => m.Name == CountryNames.FINLANDE); CoinsToSave.Clear(); Populate2Euro(); Populate2EuroCommemorative(); Populate1Euro(); Populate50Cents(); Populate20Cents(); Populate10Cents(); Populate5Cents(); Populate2Cents(); Populate1Cents(); SaveCoins(_country, CoinsToSave, _context); }