public List<UGenre> GetAllRoot() { List<UGenre> tmp = Db.Genres.Where(w=>w.ParentID == null).ToList(); List<UGenre> result = new List<UGenre>(); foreach (UGenre g in tmp) { UGenre tmpGenre = new UGenre(g); tmpGenre.Children = this.GetByParentID(g.GenreID); result.Add(tmpGenre); } return result; }
public void Update(UGenre genre) { Db.Entry<UGenre>(genre).State = System.Data.Entity.EntityState.Modified; Db.SaveChanges(); }
public void Create(UGenre genre) { genre.GenreID = Guid.NewGuid(); Db.Genres.Add(genre); Db.SaveChanges(); }
public SeedGenres(string versionID, ContentModel db, UmbracoProvider provider) : base(versionID, db, provider) { SeedName = "Genres"; SeedStart(); if (SeedCanRun) { List<UGenre> genres = UProvider.GetList<UGenre>("Genre").Distinct().ToList(); foreach(UGenre g in genres) { UGenre baseGenre = new UGenre(g); baseGenre.IsPublished = true; if (!Db.Genres.Where(w => w.UmbracoID == g.UmbracoID).Any()) { baseGenre.GenreID = Guid.NewGuid(); baseGenre.ParentID = null; if (baseGenre.Theme != null) { if (!db.Genres.Where(w => w.UmbracoID == baseGenre.UmbracoID).Any()) { if (g.Children != null) { if (db.Themes.Where(w => w.UmbracoID == baseGenre.Theme.UmbracoID).Any()) { baseGenre.ThemeID = Db.Themes.AsNoTracking().Where(w=>w.UmbracoID == baseGenre.Theme.UmbracoID).First().ThemeID; baseGenre.ParentID = null; baseGenre.Children = null; baseGenre.Theme = null; Db.Genres.Add(baseGenre); } } } } } else { UGenre updated = Db.Genres.AsNoTracking().Where(w => w.UmbracoID == g.UmbracoID).First(); baseGenre.GenreID = updated.GenreID; baseGenre.Children = null; baseGenre.Theme = null; Db.Entry<UGenre>(baseGenre).State = System.Data.Entity.EntityState.Modified; } } try { Db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { HandleDbEntityValidationException(ex); throw ex; } foreach (UGenre g in genres) { UGenre baseGenre = new UGenre(g); if (g.Children != null) { foreach (UGenre child in baseGenre.Children) { UGenre tmpChild = new UGenre(child); if (!Db.Genres.Where(w => w.UmbracoID == child.UmbracoID).Any()) { UTheme activeTheme = new UTheme(); if (child.Theme != null) { activeTheme = Db.Themes.AsNoTracking().Where(w => w.UmbracoID == child.Theme.UmbracoID).First(); } else { activeTheme = Db.Themes.AsNoTracking().Where(w => w.Name == "Default").First(); } tmpChild.ThemeID = activeTheme.ThemeID; tmpChild.GenreID = Guid.NewGuid(); Guid? parentId = Db.Genres.AsNoTracking().Where(w => w.UmbracoID == baseGenre.UmbracoID).First().GenreID; tmpChild.Theme = null; tmpChild.ParentID = parentId; Db.Genres.Add(tmpChild); } } } } try { Db.SaveChanges(); SeedFinished(true); } catch(System.Data.Entity.Validation.DbEntityValidationException ex) { HandleDbEntityValidationException(ex); throw ex; } } else { SeedFinished(true); } }