public UpdateCountriesResult UpdateCountries(List <Country> newCountries) { List <Country> existedCountries = _countriesRepository.GetAll().ToList(); UpdateCountriesResult result = new UpdateCountriesResult { Updated = existedCountries.Intersect(newCountries, new KeyEqualityComparer <Country>(o => o.EnglishName)).ToList(), Created = newCountries.Except(existedCountries, new KeyEqualityComparer <Country>(o => o.EnglishName)).ToList(), Deleted = existedCountries.Except(newCountries, new KeyEqualityComparer <Country>(o => o.EnglishName)).ToList() }; result.Updated.ForEach(item => { Country source = newCountries.Single(country => country.EnglishName == item.EnglishName); item.EnglishName = source.EnglishName; item.ISO = source.ISO; item.PhoneCode = source.PhoneCode; item.ThreeCharsCode = source.ThreeCharsCode; item.TwoCharsCode = source.TwoCharsCode; _countriesRepository.Update(item); }); result.Created.ForEach(item => _countriesRepository.Add(item)); result.Deleted.ForEach(item => _countriesRepository.Delete(item)); return(result); }
public ViewResult DeleteConfirmed(int?id) { if (id == null) { return(View("Error")); } Country country = db.Countries.FirstOrDefault(a => a.CountryID == id); if (country == null) { return(View("Error")); } db.Delete(country); return(View("Index")); }
public IActionResult Delete(int Id) { _countriesRepository.Delete(Id); return(RedirectToAction("Index", "Countries")); }