コード例 #1
0
        public ArtistVM(Artist artist, IAdministrationServices service, IIOService ioservice)
        {
            this.administrationService = service;
            this.ioService = ioservice;
            this.artist = artist;
            this.Catagories = new ObservableCollection<Catagory>();
            this.Countries = new ObservableCollection<string>();
            LoadData();

            SaveCommand = new RelayCommand(async s => {
                if (!(await Validator.ValidateAllAsync()).IsValid)
                {
                    return;
                }
                artist = administrationService.SaveArtist(artist);
                if (artist != null && artist.Id > 0)
                {
                    AppMessages.ShowSuccessMessage.Send($"Artist {artist.Name} saved ");
                    AppMessages.ArtistChanged.Send(AppMessages.ChangeType.Change);
                    return;
                }
                AppMessages.ShowErrorMessage.Send($"Error occured while saving Artist {artist.Name} ");
            });

            DeleteCommand = new RelayCommand(c =>
            {
                if(artist.Id == null)
                {
                    AppMessages.ArtistChanged.Send(AppMessages.ChangeType.Remove);
                    return;
                }
                if (administrationService.DeleteArtist(artist))
                {
                    AppMessages.ShowSuccessMessage.Send($"Artist {artist.Name} removed ");
                    AppMessages.ArtistChanged.Send(AppMessages.ChangeType.Remove);
                    return;
                }
                AppMessages.ShowErrorMessage.Send($"Error occured while removing Artist {artist.Name} ");

            });
            ChangePictureCommand = new RelayCommand(c =>
            {
                this.artist.Picture = ioService.openFileBase64Encoded();
                RaisePropertyChangedEvent(nameof(Picture));
            });

            AddValidationRules();
        }
コード例 #2
0
 public Task<bool> CheckEmailIsAvailable(string email, Artist artist)
 {
     return Task<bool>.Run(() =>
     {
         IArtistDao dao = DALFactory.CreateArtistDao(database);
         IList < Artist > artists = dao.findByProperty(typeof(Artist).GetProperty("Email"), email);
         if (artists != null && artists.Count > 0)
         {
             if(artists.Count == 1 && artists.First().Id == artist.Id)
             {
                 return true;
             }
             return false;
         }
         return true;
     });
 }
コード例 #3
0
        public void TestInsert()
        {
            PropertyInfo info = typeof(Artist).GetProperty("Email");
            Artist artist = new Artist();
            artist.Email = "*****@*****.**";
            artist.Name = "UnitTestArtist";
            artist.Link = "I do not have any Link";
            artist.Country = "AUT";

            IArtistDao dao = DALFactory.CreateArtistDao(DALFactory.CreateDatabase());
            dao.Insert(artist);

            Artist result = dao.findByUniqueProperty(info, "*****@*****.**");
            Assert.AreEqual(result.Email, artist.Email);
            Assert.AreEqual(result.Name, artist.Name);
            Assert.AreEqual(result.Link, artist.Link);
            Assert.AreEqual(result.Country, artist.Country);
        }
コード例 #4
0
        private static void CreateArtists()
        {
            Console.WriteLine("Insert Artists ");
            Random r = new Random();
            RootObject generatedEntries = FetchPersons();
            IArtistDao dao = DALFactory.CreateArtistDao(DALFactory.CreateDatabase());
            ICatagoryDao catagoryDao = DALFactory.CreateCatagoryDao(DALFactory.CreateDatabase());

            generatedEntries.results.ToList().ForEach(x => {
                Console.WriteLine(x.user.name.first);
                Artist artist = new Artist();
                artist.Catagory = catagoryDao.findById(r.Next(1, 10));
                artist.Name = x.user.name.first + " " + x.user.name.last;
                artist.Email = x.user.email;
                artist.Country = "AUT";
                artist.Picture = GetBase64EncodedImageFromUrl(x.user.picture.thumbnail);
                dao.Insert(artist);
                Console.WriteLine("Inserted ");

            });
        }
コード例 #5
0
 /// <summary>
 /// disable an artist and set performances after now 
 /// </summary>
 /// <param name="artist"></param>
 /// <returns></returns>
 public bool DeleteArtist(Artist artist)
 {
     IArtistDao dao = DALFactory.CreateArtistDao(database);
     Artist toDelete = dao.findById(artist.Id);
     if(toDelete == null)
     {
         return false;
     }
     toDelete.Deleted = true;
     bool success = dao.Update(toDelete);
     if (success)
     {
         IPerformanceDao performanceDao = DALFactory.CreatePerformanceDao(database);
         IList<Performance> performances = performanceDao.FindPerformanceForArtistsAfterDate(toDelete, DateTime.Now);
         foreach(Performance p in performances)
         {
             Console.WriteLine("found performances " + p.Id + "artist " + p.Artist.Name);
             p.Canceld = true;
             success = performanceDao.Update(p);
         }
     }
     return success;
 }
コード例 #6
0
 public Artist SaveArtist(Artist artist)
 {
     IArtistDao dao = DALFactory.CreateArtistDao(database);
     if(artist.Id != null && artist.Id > 0)
     {
         dao.Update(artist);
         return artist;
     }
     artist = dao.Insert(artist);
     return artist;
 }