public void TestInsert()
        {
            Performance performance = new Performance();
            IArtistDao artistDao = DALFactory.CreateArtistDao(DALFactory.CreateDatabase());
            Artist artist = artistDao.findById(1);

            IVenueDao venueDao = DALFactory.CreateVenueDao(DALFactory.CreateDatabase());
            Venue venue = venueDao.findById(1);

            performance.Artist = artist;
            performance.Venue = venue;
            performance.StagingTime = DateTime.Now;

            IPerformanceDao dao = DALFactory.CreatePerformanceDao(DALFactory.CreateDatabase());
            dao.Insert(performance);

            IList<Performance> result = dao.findAll();
            Assert.AreEqual(result.Count, 3);
        }
 private void SavePerformanceHelper(Performance current)
 {
     if (current.Artist != null && current.Artist.Id >= 0 && current.Venue != null && current.Venue.Id > 0)
     {
         administrationService.SavePerformance(current);
     }
 }
        //Load Items Asynchronious
        public void LoadItems()
        {
            IList<PerformanceVM> calculateModels = new List<PerformanceVM>();
            Performances.Clear();
            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += new DoWorkEventHandler((sender, args) =>
            {
                IList<Venue> venues = administrationService.GetVenues();
                foreach (Venue venue in venues)
                {
                    IList<Performance> performances = administrationService.GetPerformancesByVenueAndDay(venue, CurrentDate);
                    if (performances.Count > 4)
                    {
                        return;
                    }
                    DateTime d = CurrentDate.Date;
                    Performance col1 = new Performance();
                    col1.StagingTime = d.AddHours(14);
                    Performance col2 = new Performance();
                    col2.StagingTime = d.AddHours(15);
                    Performance col3 = new Performance();
                    col3.StagingTime = d.AddHours(16);
                    Performance col4 = new Performance();
                    col4.StagingTime = d.AddHours(17);
                    Performance col5 = new Performance();
                    col5.StagingTime = d.AddHours(18);

                    foreach (Performance p in performances)
                    {
                        if (p.StagingTime.Hour >= 18)
                        {
                            col5 = p;
                        }
                        else if (p.StagingTime.Hour >= 17 )
                        {
                            col4 = p;
                        }
                        else if (p.StagingTime.Hour >= 16)
                        {
                            col3 = p;
                        }
                        else if (p.StagingTime.Hour >= 15)
                        {
                            col2 = p;
                        }
                        else if (p.StagingTime.Hour >= 14)
                        {
                            col1 = p;
                        }
                    }

                    calculateModels.Add(new PerformanceVM(venue, col1, col2, col3, col4, col5, administrationService,this));

                }
            });
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler((sender, args) => {
                Performances.Clear();
                foreach(PerformanceVM vm in calculateModels)
                {
                    vm.GroupCheckBox();
                    Performances.Add(vm);
                }
                RaisePropertyChangedEvent(nameof(Performances));
            });
            worker.RunWorkerAsync(System.Reflection.Assembly.GetExecutingAssembly().Location);
        }
        private static void CreatePerformances()
        {
            Console.WriteLine("Insert Performances ");
            IVenueDao venueDao = DALFactory.CreateVenueDao(DALFactory.CreateDatabase());
            IPerformanceDao performanceDao = DALFactory.CreatePerformanceDao(DALFactory.CreateDatabase());
            IArtistDao artistDao = DALFactory.CreateArtistDao(DALFactory.CreateDatabase());
            int year = 2016;
            int month = 01;
            int day = 23;
            for (int i=0; i<3; i++)
            {
                int count = 1;
                int hour = 14;
                int min = 00;
                int second = 00;
                for (int j = 1; j <= 40; j++)
                {
                    count++;
                    if(count == 10)
                    {
                        hour= hour +2;
                        count = 1;
                    }
                    DateTime dt = new DateTime(year, month, day, hour, min, second);

                    Venue venue = venueDao.findById(j);
                    Artist artist = artistDao.findById(j);
                    Performance p = new Performance();
                    p.Artist = artist;
                    p.Venue = venue;
                    p.StagingTime = dt;
                    performanceDao.Insert(p);
                }
                day++;
            }
        }
        private bool ValidateOneItem(Performance current)
        {
            foreach (Performance p in this.GetPerformancesToValidate())
            {

                if (p?.Artist?.Id == current?.Artist?.Id && p != current)
                {
                    DateTime postPoneDate = new DateTime(current.StagingTime.Year, current.StagingTime.Month, current.StagingTime.Day, current.StagingTime.Hour, 0, 0);
                    DateTime currentDate = new DateTime(p.StagingTime.Year, p.StagingTime.Month, p.StagingTime.Day, p.StagingTime.Hour, 0, 0);

                    if (postPoneDate >= currentDate.AddHours(-2) && postPoneDate <= currentDate.AddHours(2))
                    {
                        return false;
                    }

                }
            }
            return true;
        }
        public PerformanceVM(Venue v, Performance p1, Performance p2, Performance p3, Performance p4, Performance p5,IAdministrationServices service, PerformanceAdministrationVM parent)
        {
            this.Artists = new ObservableCollection<Artist>();
            this.administrationService = service;
            this.parent = parent;
            venue = v;
            Col1 = p1;
            Col2 = p2;
            Col3 = p3;
            Col4 = p4;
            Col5 = p5;

            this.Artists.Clear();
            IList<Artist> arts = administrationService.GetArtists();
            foreach (Artist artist in arts)
            {
                Artists.Add(artist);
            }

            RemoveEntryCol1 = new RelayCommand(c => {
                Col1.Artist = null;
                RaisePropertyChangedEvent(nameof(ArtistCol1));
                RaisePropertyChangedEvent(nameof(ArtistNameCol1));
                RaisePropertyChangedEvent(nameof(CountryCol1));
                RaisePropertyChangedEvent(nameof(CatagoryCol1));
                RaisePropertyChangedEvent(nameof(ColorCol1));
            });
            RemoveEntryCol2 = new RelayCommand(c => {
                Col2.Artist = null;
                RaisePropertyChangedEvent(nameof(ArtistCol2));
                RaisePropertyChangedEvent(nameof(ArtistNameCol2));
                RaisePropertyChangedEvent(nameof(CountryCol2));
                RaisePropertyChangedEvent(nameof(CatagoryCol2));
                RaisePropertyChangedEvent(nameof(ColorCol2));
            });
            RemoveEntryCol3 = new RelayCommand(c => {
                Col3.Artist = null;
                RaisePropertyChangedEvent(nameof(ArtistCol3));
                RaisePropertyChangedEvent(nameof(ArtistNameCol3));
                RaisePropertyChangedEvent(nameof(CountryCol3));
                RaisePropertyChangedEvent(nameof(CatagoryCol3));
                RaisePropertyChangedEvent(nameof(ColorCol3));
            });
            RemoveEntryCol4 = new RelayCommand(c => {
                Col4.Artist = null;
                RaisePropertyChangedEvent(nameof(ArtistCol4));
                RaisePropertyChangedEvent(nameof(ArtistNameCol4));
                RaisePropertyChangedEvent(nameof(CountryCol4));
                RaisePropertyChangedEvent(nameof(CatagoryCol4));
                RaisePropertyChangedEvent(nameof(ColorCol4));
            });
            RemoveEntryCol5 = new RelayCommand(c => {
                Col5.Artist = null;
                RaisePropertyChangedEvent(nameof(ArtistCol5));
                RaisePropertyChangedEvent(nameof(ArtistNameCol5));
                RaisePropertyChangedEvent(nameof(CountryCol5));
                RaisePropertyChangedEvent(nameof(CatagoryCol5));
                RaisePropertyChangedEvent(nameof(ColorCol5));
            });

            SendEmailCol1 = new RelayCommand(c =>
            {
                IList<Performance> toSend = new List<Performance>();
                toSend.Add(Col1);
                administrationService.SendMail(toSend,toSend);
                AppMessages.ShowSuccessMessage.Send("Mail sent");
            });
            SendEmailCol2 = new RelayCommand(c =>
            {
                IList<Performance> toSend = new List<Performance>();
                toSend.Add(Col2);
                administrationService.SendMail(toSend, toSend);
                AppMessages.ShowSuccessMessage.Send("Mail sent");
            });
            SendEmailCol3 = new RelayCommand(c =>
            {
                IList<Performance> toSend = new List<Performance>();
                toSend.Add(Col3);
                administrationService.SendMail(toSend, toSend);
                AppMessages.ShowSuccessMessage.Send("Mail sent");
            });
            SendEmailCol4 = new RelayCommand(c =>
            {
                IList<Performance> toSend = new List<Performance>();
                toSend.Add(Col4);
                administrationService.SendMail(toSend, toSend);
                AppMessages.ShowSuccessMessage.Send("Mail sent");
            });
            SendEmailCol5 = new RelayCommand(c =>
            {
                IList<Performance> toSend = new List<Performance>();
                toSend.Add(Col5);
                administrationService.SendMail(toSend, toSend);
                AppMessages.ShowSuccessMessage.Send("Mail sent");
            });
        }
 public bool SavePerformance(Performance p)
 {
     IPerformanceDao dao = DALFactory.CreatePerformanceDao(database);
     dao.Insert(p);
     return true;
 }