public SeedCountries(string versionID, ContentModel db, UmbracoProvider provider) : base(versionID, db, provider) { InitCountryDict(); SeedName = "Countries"; SeedStart(); if (SeedCanRun) { List<UCountry> results = UProvider.GetList<UCountry>("Country").ToList(); List<UCountry> notInDict = getNotInDict(results); foreach (KeyValuePair<string,string> country in CDictionary) { UCountry tmp = new UCountry() { CountryID = Guid.NewGuid(), Name = country.Value, CultureIsoName = country.Key, CreateDate = DateTime.Now, CreatorName = "DBMigrator", IsPublished = true }; if (results.Where(w => w.CultureIsoName.ToLower() == country.Key.ToLower() && w.Name == country.Value).Any()) { tmp.UmbracoID = results.Where(w => w.CultureIsoName.ToLower() == country.Key.ToLower() && w.Name == country.Value).FirstOrDefault().UmbracoID; } Db.Countries.Add(tmp); } foreach(UCountry c in notInDict) { c.CountryID = Guid.NewGuid(); c.CreatorName = "Umbraco"; c.IsPublished = true; Db.Countries.Add(c); } try { Db.SaveChanges(); SeedFinished(true); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { HandleDbEntityValidationException(ex); throw ex; } catch(Exception ex) { throw ex; } } else { SeedFinished(true); } }
public void Update(UCountry country) { Db.Entry<UCountry>(country).State = System.Data.Entity.EntityState.Modified; Db.SaveChanges(); }
public void Create(UCountry country) { country.CountryID = Guid.NewGuid(); Db.Countries.Add(country); Db.SaveChanges(); }