Beispiel #1
0
 public void AddDvd(Dvd dvd)
 {
     if (dvdEntity.Dvd.Count() == 0)
     {
         dvd.DvdId = 1;
     }
     else
     {
         var maxID = dvdEntity.Dvd.Max(d => d.DvdId);
         dvd.DvdId = maxID + 1;
     }
     dvdEntity.Dvd.Add(dvd);
     dvdEntity.SaveChanges();
 }
Beispiel #2
0
        public void DeleteDirector(int?directorId)
        {
            var repository = new DVDLibraryEntities();

            var dir = repository.Director.FirstOrDefault(d => d.DirectorID == directorId);

            repository.Director.Remove(dir);
            repository.SaveChanges();
        }
Beispiel #3
0
        public Director AddDirector(DirectorIdRequest newDirector)
        {
            var repository    = new DVDLibraryEntities();
            var directorToAdd = new Director();

            directorToAdd.DirectorFirstName = newDirector.FirstName;
            directorToAdd.DirectorLastName  = newDirector.LastName;

            repository.Director.Add(directorToAdd);
            repository.SaveChanges();

            Director addedDirector = new Director();

            addedDirector.DirectorFirstName = newDirector.FirstName;
            addedDirector.DirectorLastName  = newDirector.LastName;
            addedDirector.DirectorID        = directorToAdd.DirectorID;
            return(addedDirector);
        }
Beispiel #4
0
        public void Delete(int dvdId)
        {
            var repository = new DVDLibraryEntities();

            string director = GetById(dvdId).Director;

            var dvd = repository.Dvd.FirstOrDefault(d => d.DvdId == dvdId);

            if (dvd != null)
            {
                repository.Dvd.Remove(dvd);
                repository.SaveChanges();
            }

            if (!string.IsNullOrEmpty(director))
            {
                DirectorTableCleanUp(director);
            }
        }
Beispiel #5
0
        public void Edit(DVD dvd)
        {
            var repository = new DVDLibraryEntities();
            Dvd dvdToEdit  = new Dvd();

            dvdToEdit.DvdId        = dvd.DvdId;
            dvdToEdit.Title        = dvd.Title;
            dvdToEdit.RealeaseYear = dvd.RealeaseYear;
            dvdToEdit.Notes        = dvd.Notes;

            int?ratingId = Helpers.GetRatingId(dvd.Rating);

            if (ratingId == null)
            {
                dvdToEdit.RatingId = null;
            }
            else
            {
                dvdToEdit.RatingId = ratingId;
            }

            int?directorId = GetDirectorId(dvd.Director);

            if (directorId == null)
            {
                dvdToEdit.DirectorId = null;
            }
            else
            {
                dvdToEdit.DirectorId = directorId;
            }

            repository.Entry(dvdToEdit).State = System.Data.Entity.EntityState.Modified;
            repository.SaveChanges();

            if (!string.IsNullOrEmpty(dvd.Director))
            {
                DirectorTableCleanUp(dvd.Director);
            }
        }
Beispiel #6
0
        public void Add(DVD dvd)
        {
            var repository = new DVDLibraryEntities();
            Dvd dvdToAdd   = new Dvd();

            dvdToAdd.Title        = dvd.Title;
            dvdToAdd.RealeaseYear = dvd.RealeaseYear;
            dvdToAdd.Notes        = dvd.Notes;

            int?ratingId = Helpers.GetRatingId(dvd.Rating);

            if (ratingId == null)
            {
                dvdToAdd.RatingId = null;
            }
            else
            {
                dvdToAdd.RatingId = ratingId;
            }

            int?directorId = GetDirectorId(dvd.Director);

            if (directorId == null)
            {
                dvdToAdd.DirectorId = null;
            }
            else
            {
                dvdToAdd.DirectorId = directorId;
            }

            repository.Dvd.Add(dvdToAdd);
            repository.SaveChanges();

            dvd.DvdId = dvdToAdd.DvdId;
        }