Ejemplo n.º 1
0
        public SeedFestivals(string versionID, ContentModel db, UmbracoProvider provider)
            : base(versionID, db, provider)
        {
            SeedName = "Festivals";
            SeedStart();
            if (SeedCanRun)
            {
                List<UFestival> results = UProvider.GetList<UFestival>("Festival").ToList();
                if (results.Count > 0)
                {
                    foreach (UFestival r in results)
                    {
                        if (!db.Festivals.Where(w => w.UmbracoID == r.UmbracoID).Any())
                        {
                            r.FestivalID = Guid.NewGuid();
                            UFestival tmp = new UFestival(r);
                            tmp.IsPublished = true;
                            if (tmp.Genres != null)
                            {
                                foreach (UGenre tmpGenre in tmp.Genres)
                                {
                                    UGenre dbGenre = Db.Genres.Where(w => w.UmbracoID == tmpGenre.UmbracoID).First();
                                    Db.G2F.Add(new UGenre2UFestival { G2FID = Guid.NewGuid(), FestivalID = tmp.FestivalID, GenreID = dbGenre.GenreID });
                                }
                                tmp.Genres = null;
                            }
                            UCountry dbCountry = Db.Countries.Where(w => w.UmbracoID == r.Country.UmbracoID).First();
                            tmp.CountryID = dbCountry.CountryID;
                            tmp.Country = null;

                            if (r.Artists != null)
                            {
                                foreach (UArtist tmpArtist in tmp.Artists)
                                {
                                    UArtist dbArtist = db.Artists.Where(w => w.UmbracoID == tmpArtist.UmbracoID).First();
                                    db.A2F.Add(new UArtist2UFestival { A2FID = Guid.NewGuid(), ArtistID = dbArtist.ArtistID, FestivalID = tmp.FestivalID });
                                }
                                tmp.Artists = null;
                            }
                            Db.Festivals.Add(tmp);
                        }
                    }
                }
                try
                {
                    Db.SaveChanges();
                    SeedFinished(true);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                {
                    HandleDbEntityValidationException(ex);
                    throw ex;
                }
            }
            else
            {
                SeedFinished(true);
            }
        }
Ejemplo n.º 2
0
        public List<UFestival> GetFestivalsByMonth(int year, int month)
        {
            DynamicPublishedContent Content = _UHelper.Content(DataSourceID);
            DynamicPublishedContentList children = Content.Children;
            foreach(DynamicPublishedContent child in children)
            {
                DynamicPublishedContentList festivals = child.Children;
                foreach(DynamicPublishedContent festival in festivals)
                {
                    UFestival f = new UFestival
                    {
                        //TODO:
                        //Fix safe mapping
                    };
                }
            }

            List<dynamic> result = new List<dynamic>();

            return new List<UFestival>();
        }
Ejemplo n.º 3
0
 public List<UFestival> GetFilteredFestival(FC.Shared.FormModels.FestivalFilter filter)
 {
     List<UFestival> result = new List<UFestival>();
     List<UFestival> tmpList = new List<UFestival>();
     if(filter.CountryIDs == null)
     {
         filter.CountryIDs = new List<Guid?>();
     }
     if(filter.GenreIDs == null)
     {
         filter.GenreIDs = new List<Guid?>();
     }
     if(filter.GenreIDs.Count() > 0 && filter.CountryIDs.Count() == 0)
     {
         result = Db.Festivals.Where(w => w.StartDate.Month == filter.MonthNum && w.StartDate.Year == filter.YearNum).ToList();
         foreach (UFestival f in result)
         {
             UFestival tmp = new UFestival(f);
             tmp.Genres = Db.G2F.Where(w => w.FestivalID == f.FestivalID).Select(s => s.Genre).ToList();
             if (tmp.Genres.Select(s => s).Where(w => filter.GenreIDs.Contains(w.GenreID)).Any())
             {
                 tmpList.Add(tmp);
             }
         }
     }
     else if (filter.GenreIDs.Count() > 0 && filter.CountryIDs.Count() > 0)
     {
         result = Db.Festivals.Where(w => w.StartDate.Month == filter.MonthNum && w.StartDate.Year == filter.YearNum && filter.CountryIDs.Contains(w.CountryID)).ToList();
         foreach (UFestival f in result)
         {
             UFestival tmp = new UFestival(f);
             tmp.Genres = Db.G2F.Where(w => w.FestivalID == f.FestivalID).Select(s => s.Genre).ToList();
             if (tmp.Genres.Select(s => s).Where(w => filter.GenreIDs.Contains(w.GenreID)).Any())
             {
                 tmpList.Add(tmp);
             }
         }
     }
     else if (filter.GenreIDs.Count() == 0 && filter.CountryIDs.Count() > 0)
     {
         result = Db.Festivals.Where(w => w.StartDate.Month == filter.MonthNum && w.StartDate.Year == filter.YearNum && filter.CountryIDs.Contains(w.CountryID)).ToList();
         foreach (UFestival f in result)
         {
             UFestival tmp = new UFestival(f);
             tmp.Genres = Db.G2F.Where(w => w.FestivalID == f.FestivalID).Select(s => s.Genre).ToList();
             tmpList.Add(tmp);
         }
     }
     else if (filter.GenreIDs.Count() == 0 && filter.CountryIDs.Count() == 0)
     {
         if (filter.MonthNum == 0 || filter.YearNum == 0)
         {
             throw new Exception("Invalid year or month specified");
         }
         else
         {
             result = Db.Festivals.Where(w => w.StartDate.Month == filter.MonthNum && w.StartDate.Year == filter.YearNum).ToList();
             foreach (UFestival f in result)
             {
                 UFestival tmp = new UFestival(f);
                 tmp.Genres = Db.G2F.Where(w => w.FestivalID == f.FestivalID).Select(s => s.Genre).ToList();
                 tmpList.Add(tmp);
             }
         }
     } else
     {
         throw new Exception("Cannot filter festivals because none of the filter parameters was specified.");
     }
     return tmpList.OrderBy(o => o.OrderDate).ToList();
 }
Ejemplo n.º 4
0
 public void Create(UFestival fest)
 {
     fest.FestivalID = Guid.NewGuid();
     Db.Festivals.Add(fest);
     Db.SaveChanges();
 }
Ejemplo n.º 5
0
 public void Update(UFestival fest)
 {
     Db.Entry<UFestival>(fest).State = System.Data.Entity.EntityState.Modified;
     Db.SaveChanges();
 }