public void Add(Movie movie) { using (var ctx = new ShopContextConnection()) { ctx.Movies.Attach(movie); ctx.Movies.Add(movie); ctx.SaveChanges(); } }
public void Add(Order order) { using (var ctx = new ShopContextConnection()) { ctx.Orders.Attach(order); ctx.Orders.Add(order); ctx.SaveChanges(); } }
public void Add(Genre genre) { using (var ctx = new ShopContextConnection()) { //Create the queries ctx.Genres.Add(genre); //Execute the queries ctx.SaveChanges(); } }
public void Delete(Movie movie) { using (var ctx = new ShopContextConnection()) { ctx.Movies.Attach(movie); //var thisMovie = ctx.Movies.Where(x => x.Id == movie.Id).FirstOrDefault(); ctx.Movies.Remove(movie); ctx.SaveChanges(); } }
//public void Edit([Bind(Include = "Id,Title,Year,Price")] Movie movie) //{ // if (ModelState.IsValid) // { // ctx.Entry(movie).State = EntityState.Modified; // ctx.SaveChanges(); // return RedirectToAction("Index"); // } //} public void Edit(Movie movie) { using (var ctx = new ShopContextConnection()) { //A gift to Lars from KBTZ team. Enjoy! var movieDB = ctx.Movies.FirstOrDefault(x => x.Id == movie.Id); movieDB.Genre = ctx.Genres.FirstOrDefault(x => x.Id == movie.Genre.Id); movieDB.Title = movie.Title; movieDB.Price = movie.Price; movieDB.Year = movie.Year; movieDB.Description = movie.Description; movieDB.url = movie.url; movieDB.MovieCoverUrl = movie.MovieCoverUrl; ctx.SaveChanges(); //ctx.SaveChanges(); } }