Exemple #1
0
 public static Country AddCountry(Country country)
 {
   if (country == null) return null;
   using (var db = new BookshelfDbContext())
   {
     db.Countries.Add(country);
     db.SaveChanges();
     var id = db.Countries.Max(x => x.Id);
     return db.Countries.Where(x => x.Id == id).FirstOrDefault();
   }
 }
 private Country AddCountryCommon()
 {
   var dlg = new AddValueWindow(AddNewCountryLabelText);
   if (dlg.ShowDialog() == false) return null;
   var value = dlg.GetValue();
   if (value == null || value == string.Empty) return null;
   if (!CountryList.Where(x => x.Name == value).Any())
   {
     var country = new Country();
     country.Name = value;
     using (var db = new BookshelfDbContext())
     {
       db.Countries.Add(country);
       db.SaveChanges();
     }
     OnPropertyChanged("CountryList");
   }
   return CountryList.Where(x => x.Name == value).First();
 }