コード例 #1
0
 public void Delete(int dvdId)
 {
     using (DvdCatalogEntities data = new DvdCatalogEntities())
     {
         data.Dvds.Remove(data.Dvds.FirstOrDefault(x => x.DvdId == dvdId));
         data.SaveChanges();
     }
 }
コード例 #2
0
        public void SaveNew(string title, int releaseYear, string directorName, string ratingName, string notes)
        {
            Dvd dvd = new Dvd();

            using (DvdCatalogEntities data = new DvdCatalogEntities())
            {
                dvd.Director = (from x in data.Directors select x).FirstOrDefault(y => y.DirectorName == directorName);
                if (dvd.Director == null)
                {
                    Director director = new Director();
                    director.DirectorName = directorName;
                    data.Directors.Add(director);
                }
                dvd.Rating      = (from r in data.Ratings select r).First(x => x.RatingName == ratingName);
                dvd.ReleaseYear = releaseYear;
                dvd.Title       = title;
                dvd.Notes       = notes;
                data.Dvds.Add(dvd);
                data.SaveChanges();
            }
        }
コード例 #3
0
 public void Edit(int dvdId, string title, int releaseYear, string directorName, string ratingName, string notes)
 {
     using (DvdCatalogEntities data = new DvdCatalogEntities())
     {
         Dvd dvd = data.Dvds.FirstOrDefault(x => x.DvdId == dvdId);
         dvd.Title       = title;
         dvd.ReleaseYear = releaseYear;
         var directorCheck = data.Directors.FirstOrDefault(
             y =>
             y.DirectorName == directorName
             );
         dvd.Director = directorCheck;
         if (dvd.Director == null || dvd.Director.DirectorName == "")
         {
             Director director = new Director();
             director.DirectorName = directorName;
             data.Directors.Add(director);
             dvd.Director = director;
         }
         dvd.Rating = data.Ratings.First(x => x.RatingName == ratingName);
         dvd.Notes  = notes;
         data.SaveChanges();
     }
 }