Ejemplo n.º 1
0
 public Artist Create(Artist artist)
 {
     DbCommand cmd = createInsertCommand(artist.Name, artist.Image, artist.Video, artist.CategoryId, artist.CountryId, artist.Email);
     db.ExecuteNonQuery(cmd);
     artist.Id = (int)(((MySqlCommand)cmd).LastInsertedId);
     return artist;
 }
Ejemplo n.º 2
0
 public void Delete(Artist artist)
 {
     DbCommand cmd = createDeleteCommand(artist.Id);
     if (db.ExecuteNonQuery(cmd) != 1) {
         throw new EntityNotFoundException();
     }
 }
Ejemplo n.º 3
0
        public void SetUp()
        {
            transaction = new TransactionScope();

            DALFactory factory = DALFactory.GetInstance();
            db = factory.CreateDatabase();
            dao = factory.CreateArtistDAO(db);

            artist1 = new Artist {
                Id = 1,
                Name = "Christoph The Wurst",
                Image = "some-image",
                Video = "some-video",
                CategoryId = 3,
                CountryId = 15,
                Email = "*****@*****.**",
            };
            artist2 = new Artist {
                Id = 2,
                Name = "Stefan The Rösch",
                Image = "some-image",
                Video = "some-video",
                CategoryId = 4,
                CountryId = 7,
                Email = "*****@*****.**",
            };

            var sqls = new List<string> {
                "SET FOREIGN_KEY_CHECKS=0",
                "DELETE FROM `artist`",
                "INSERT INTO `artist` VALUES (1, 'Christoph The Wurst', 'some-image', 'some-video', 3, 15, '*****@*****.**', 0)",
                "INSERT INTO `artist` VALUES (2, 'Stefan The Rösch', 'some-image', 'some-video', 4, 7, '*****@*****.**', 0)"
            };
            runDbCommands(db, sqls);
        }
Ejemplo n.º 4
0
        private static void TestArtist(IDatabase db, DALFactory dalFactory)
        {
            Console.WriteLine("*************************************");
            Console.WriteLine("ARTIST TEST");

            IArtistDAO artistDAO = dalFactory.CreateArtistDAO(db);

            Console.WriteLine("\nAll artists:");
            foreach (var artist in artistDAO.GetAll()) {
                Console.WriteLine(artist);
            }

            Console.WriteLine("\nArtist with ID=1:");
            Console.WriteLine(artistDAO.GetById(1));

            Artist artist1 = new Artist() {
                Name = "Stefan the Rösch",
                CategoryId = 1,
                CountryId = 25
            };
            Artist newArtist = artistDAO.Create(artist1);
            Console.WriteLine("New Artist: " + newArtist);
            Console.WriteLine("Inserted Artist: " + artist1);

            artist1.Name = "Christoph the Wurst";
            artistDAO.Update(artist1);
            Console.WriteLine("Updated artist: " + artist1);

            artistDAO.Delete(artist1);
            Console.WriteLine("\nArtist deleted");
        }
Ejemplo n.º 5
0
 public override Artist CreateArtist(Artist artist)
 {
     try {
         return dalFactory.CreateArtistDAO(db).Create(artist);
     } catch {
         throw new BusinessLogicException($"Could not create Artist {artist.Name}.");
     }
 }
Ejemplo n.º 6
0
 public void TestCreate()
 {
     var newArtist = new Artist {
         Id = -1,
         Name = "Florian The Tremmel",
         Image = "the-image",
         Video = "the-video",
         CategoryId = 13,
         CountryId = 3,
         Email = "*****@*****.**"
     };
     newArtist = dao.Create(newArtist);
     Assert.True(newArtist.Id != -1);
     Assert.True(dao.GetById(newArtist.Id).IsEqualTo(newArtist));
 }
Ejemplo n.º 7
0
        public override void DeleteArtist(Artist artist)
        {
            try {
                var aDao = dalFactory.CreateArtistDAO(db);
                var pDao = dalFactory.CreatePerformanceDAO(db);
                var dDao = dalFactory.CreateSpectacledayDAO(db);
                var dsDao = dalFactory.CreateSpectacledayTimeSlotDAO(db);

                var pArtist = pDao.GetForArtist(artist);
                var days = dDao.GetForPerformances(pArtist);
                var dSlot = dsDao.GetForPerformances(pArtist);

                List<int> dayIds = days.Where(d => d.Day >= DateTime.Now).Select(d => d.Id).ToList();
                List<int> dSlotIds = dSlot.Where(ds => dayIds.Contains(ds.SpectacledayId)).Select(ds => ds.Id).ToList();

                using (TransactionScope trans = new TransactionScope()) {
                    aDao.Delete(artist);
                    pArtist.ToList().ForEach(p => { if (dSlotIds.Contains(p.SpectacledayTimeSlot)) pDao.Delete(p); });
                    trans.Complete();
                }
            } catch (EntityNotFoundException) {
                throw new BusinessLogicException($"Could not delete Artist {artist.Name}, Artist {artist.Name} not found.");
            }
        }
Ejemplo n.º 8
0
 public void DeleteArtist(Artist artist)
 {
     bl.DeleteArtist(artist);
 }
Ejemplo n.º 9
0
 public Artist CreateArtist(Artist artist)
 {
     return bl.CreateArtist(artist);
 }
Ejemplo n.º 10
0
 public Artist UpdateArtist(Artist artist)
 {
     return bl.UpdateArtist(artist);
 }
Ejemplo n.º 11
0
 public abstract Artist GetArtistById(Artist artist);
Ejemplo n.º 12
0
 public override Artist GetArtistById(Artist artist)
 {
     return dalFactory.CreateArtistDAO(db).GetById(artist.Id);
 }
Ejemplo n.º 13
0
 public Task<IEnumerable<Performance>> GetPerformancesForArtistAsync(Artist artist)
 {
     return Task.Run(() => GetPerformancesForArtist(artist));
 }
Ejemplo n.º 14
0
 public Artist Update(Artist artist)
 {
     DbCommand cmd = createUpdateCommand(artist.Id, artist.Name, artist.Image, artist.Video, artist.CategoryId, artist.CountryId, artist.Email);
     if (db.ExecuteNonQuery(cmd) != 1) {
         throw new EntityNotFoundException();
     }
     return artist;
 }
Ejemplo n.º 15
0
 private void InsertArtistsIntoCells(Venue venue, Row row)
 {
     try {
         int i = 0;
         foreach (var timeSlot in timeSlots) {
             i++;
             SpectacledayTimeSlot daySlot = spectacleDayTimeSlots.Where(s => s.TimeSlotId == timeSlot.Id).FirstOrDefault();
             Performance performance = performances.Where(p => p.SpectacledayTimeSlot == daySlot.Id &&
                                                               p.VenueId == venue.Id).FirstOrDefault();
             Artist currArtist = null;
             if (performance != null) {
                 currArtist = artists.Where(a => a.Id == performance.ArtistId).FirstOrDefault();
             }
             if (currArtist == null) {
                 currArtist = new Artist() { Name = "" };
             }
             row.Cells[i].AddParagraph(currArtist.Name);
         }
     } catch (Exception e) {
         throw new BusinessLogicException($"Could not create PDF-File table cell value for artist." + e.Message);
     }
 }
Ejemplo n.º 16
0
 public IEnumerable<Performance> GetForArtist(Artist artist)
 {
     var result = new List<Performance>();
     var cmd = CreateSelectForArtist(artist.Id);
     using (IDataReader reader = db.ExecuteReader(cmd)) {
         while (reader.Read()) {
             result.Add(CreatePerformanceFromReader(reader));
         }
         return result;
     }
 }
Ejemplo n.º 17
0
 public override IEnumerable<Performance> GetPerformancesForArtist(Artist artist)
 {
     return dalFactory.CreatePerformanceDAO(db).GetForArtist(artist);
 }
Ejemplo n.º 18
0
 public abstract IEnumerable<Performance> GetPerformancesForArtist(Artist artist);
Ejemplo n.º 19
0
 public abstract Artist UpdateArtist(Artist artist);
Ejemplo n.º 20
0
 public abstract Artist CreateArtist(Artist artist);
Ejemplo n.º 21
0
 public abstract void DeleteArtist(Artist artist);
Ejemplo n.º 22
0
 public Task<Artist> UpdateArtistAsync(Artist artist)
 {
     return Task.Run(() => UpdateArtist(artist));
 }
Ejemplo n.º 23
0
 public Artist GetArtistById(Artist artist)
 {
     return bl.GetArtistById(artist);
 }
Ejemplo n.º 24
0
 public void DeleteArtistAsync(Artist artist)
 {
     Task.Run(() => DeleteArtist(artist));
 }
Ejemplo n.º 25
0
 public List<Performance> GetPerformancesForArtist(Artist artist)
 {
     return bl.GetPerformancesForArtist(artist).ToList();
 }
Ejemplo n.º 26
0
 public Task<Artist> GetArtistByIdAsync(Artist artist)
 {
     return Task.Run(() => GetArtistById(artist));
 }
Ejemplo n.º 27
0
 public static bool IsEqualTo(this Artist a1, Artist a2)
 {
     return a1.Id == a2.Id
         && a1.Name == a2.Name
         && a1.Image == a2.Image
         && a1.Video == a2.Video
         && a1.CategoryId == a2.CategoryId
         && a1.CountryId == a2.CountryId
         && a1.Email == a2.Email;
 }