public void TestInsert()
        {
            IDatabase db = DALFactory.CreateDatabase();
            IVenueDao dao = DALFactory.CreateVenueDao(db);
            Venue v = new Venue();
            v.Description = "UNIT-TEST";
            v.Latitude = 2;
            v.Longitude = 2;
            v.ShortDescription = "NO";
            v.Address = "TestAddress";

            dao.Insert(v);

            Assert.AreEqual(dao.findAll().Count, 3);
        }
        public VenueVM(Venue venue, IAdministrationServices service)
        {
            this.venue = venue;
            this.administrationService = service;

            Save = new RelayCommand(c =>
            {
                if (!Validator.ValidateAll().IsValid)
                {
                    return;
                }
                this.venue = administrationService.SaveVenue(this.venue);
                if (this.venue != null && this.venue.Id > 0)
                {
                    AppMessages.ShowSuccessMessage.Send($"Venue {this.venue.Description} saved ");
                    AppMessages.VenueChanged.Send(AppMessages.ChangeType.Change);
                }
                else
                {
                    AppMessages.ShowErrorMessage.Send($"Error occured while saving Venue {this.venue.Description} ");
                }
            });

            Remove = new RelayCommand(c =>
            {
                try {
                    if (administrationService.DeleteVenue(this.venue))
                    {
                        AppMessages.ShowSuccessMessage.Send($"Venue {this.venue.Description} removed ");
                        AppMessages.VenueChanged.Send(AppMessages.ChangeType.Remove);
                        return;
                    }
                    else
                    {
                        AppMessages.ShowErrorMessage.Send($"Error occured while removing Venue {this.venue.Description} ");
                    }
                }catch(ElementInUseException e)
                {
                    AppMessages.ShowErrorMessage.Send(e.Message);
                }
            });
            ApplyValidationRules();
        }
        private static void CreateVenues()
        {
            Console.WriteLine("Insert Venues ");

            Random rand = new Random();
            IVenueDao venueDao = DALFactory.CreateVenueDao(DALFactory.CreateDatabase());
            for (int i = 1; i <= 60; i++)
            {
                Venue v = new Venue();
                v.Address = "My Random Place " + i;
                v.Description = "This is Random Stage No " + i;
                v.ShortDescription = "Random Stage " + i;
                v.Latitude = (int) (48.30613 * 1000000);
                v.Longitude = (int) (14.286813 * 1000000);
                v.Latitude = v.Latitude + rand.Next(1, 100);
                v.Longitude = v.Longitude + rand.Next(1, 100);

                venueDao.Insert(v);
            }
        }
 public IList<Performance> QueryPerformancesByVenueAndDay(Venue venue, DateTime day)
 {
     IPerformanceDao dao = DALFactory.CreatePerformanceDao(database);
     return dao.FindPerformanceForVenueByDay(venue, day);
 }
        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");
            });
        }
 private bool canDeleteVenue(Venue venue)
 {
     IPerformanceDao dao = DALFactory.CreatePerformanceDao(database);
     return dao.findByProperty(typeof(Performance).GetProperty("Venue"), venue).Count <= 0;
 }
 public Venue SaveVenue(Venue venue)
 {
     IVenueDao dao = DALFactory.CreateVenueDao(database);
     if(venue.Id != null && venue.Id > 0)
     {
         dao.Update(venue);
         return venue;
     }
     venue = dao.Insert(venue);
     return venue;
 }
 public IList<Performance> GetPerformancesByVenueAndDay(Venue venue, DateTime day)
 {
     return queryService.QueryPerformancesByVenueAndDay(venue, day);
 }
 public bool DeleteVenue(Venue venue)
 {
     if (!canDeleteVenue(venue))
     {
         throw new ElementInUseException($"Can't delete Venue {venue.Description}. Venue is assigend in any Performance");
     }
     IVenueDao dao = DALFactory.CreateVenueDao(database);
     return dao.Delete(venue);
 }