Exemple #1
0
 public SeedThemes(string versionID, ContentModel db, UmbracoProvider provider)
     : base(versionID, db, provider)
 {
     SeedName = "Themes";
     SeedStart();
     if (SeedCanRun)
     {
         List<UTheme> Themes = UProvider.GetList<UTheme>("Theme").ToList();
         if(Themes.Count > 0)
         {
             foreach(UTheme t in Themes)
             {
                 UTheme tmp = new UTheme(t);
                 if (!Db.Themes.Where(w => w.UmbracoID == t.UmbracoID).Any())
                 {
                     t.ThemeID = Guid.NewGuid();
                     Db.Themes.Add(t);
                 }
             }
         }
         try
         {
             Db.SaveChanges();
             SeedFinished(true);
         }
         catch (System.Data.Entity.Validation.DbEntityValidationException ex)
         {
             HandleDbEntityValidationException(ex);
             throw ex;
         }
     } else
     {
         SeedFinished(true);
     }
 }
Exemple #2
0
        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);
            }
        }