public void Add(Genre genre)
 {
     //Create the queries
     ctx.Genres.Add(genre);
     //Execute the queries
     ctx.SaveChanges();
 }
示例#2
0
 public void Add(Genre genre)
 {
     using (var ctx = new MovieShopContext())
     {
         // create queries
         ctx.Genres.Add(genre);
         // execute changes
         ctx.SaveChanges();
     }
 }
示例#3
0
 public Genre Delete(Genre genre)
 {
     using (var ctx = new MovieShopContextDB())
     {
         var genreDB = ctx.Genres.FirstOrDefault(item => item.Id == genre.Id);
         ctx.Genres.Remove(genreDB);
         ctx.SaveChanges();
         return genre;
     }
 }
示例#4
0
 public Genre Update(Genre genre)
 {
     using (var ctx = new MovieShopContextDB())
     {
         var genreDB = ctx.Genres.FirstOrDefault(item => item.Id == genre.Id);
         genreDB.Name = genre.Name;
         genreDB.Movies = genre.Movies;
         ctx.SaveChanges();
         return genre;
     }
 }
示例#5
0
 public void Update(Genre genre)
 {
     using (var ctx = new MovieShopContext())
     {
         var genreToUpdate = ctx.Genres.Where(x => x.Id == genre.Id).FirstOrDefault();
         if (genreToUpdate != null)
         {
             genreToUpdate.Name = genre.Name;
             ctx.SaveChanges();
         }
     }
 }
示例#6
0
        public Genre Add(Genre genre)
        {
            using (var ctx = new MovieShopContextDB())
            {
                //Create the queries
                ctx.Genres.Add(genre);
                //Execute the queries
                ctx.SaveChanges();

                return genre;
            }
        }
示例#7
0
 public void Remove(Genre genre)
 {
     try
     {
         using (var ctx = new MovieShopContext())
         {
             var genreToDelete = ctx.Genres.Where(x => x.Id == genre.Id).FirstOrDefault();
             ctx.Genres.Remove(genreToDelete);
             ctx.SaveChanges();
         }
     }
     catch (DbUpdateException ex)
     {
         throw new Exception("This Genre exists in a movie and can not be deleted");
     }
 }
示例#8
0
 public ActionResult DeleteConfirmed(Genre genre)
 {
     facade.GetGenreRepository().Delete(genre);
     return RedirectToAction("Index");
 }
示例#9
0
 public ActionResult Create(Genre genre)
 {
     facade.GetGenreRepository().Add(genre);
     return Redirect("Create");
 }