public void Add(Customer customer) { using (var ctx = new MovieShopContext()) { ctx.Customers.Add(customer); ctx.SaveChanges(); } }
public void Remove(Order order) { using (var ctx = new MovieShopContext()) { var orderToDelete = ctx.Orders.Where(Order => Order.Id == order.Id).FirstOrDefault(); ctx.Orders.Remove(orderToDelete); ctx.SaveChanges(); } }
public void Remove(Movie movie) { using (var ctx = new MovieShopContext()) { var movieToDelete = ctx.Movies.FirstOrDefault(x => x.Id == movie.Id); ctx.Movies.Remove(movieToDelete); ctx.SaveChanges(); } }
public void Add(Genre genre) { using (var ctx = new MovieShopContext()) { // create queries ctx.Genres.Add(genre); // execute changes ctx.SaveChanges(); } }
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(); } } }
public void Update(Order order) { using (var ctx = new MovieShopContext()) { var orderToUpdate = ctx.Orders.Where(Order => Order.Id == order.Id).FirstOrDefault(); if (orderToUpdate != null) { orderToUpdate.Movies = order.Movies; ctx.SaveChanges(); } } }
public void Add(Order order) { using (var ctx = new MovieShopContext()) { List<Movie> movies = new List<Movie>(); foreach (var movie in order.Movies) { movies.Add(ctx.Movies.FirstOrDefault(movieToSearch => movieToSearch.Id == movie.Id)); } order.Movies = movies; order.Customer = ctx.Customers.FirstOrDefault(cust => cust.Id == order.Customer.Id); ctx.Orders.Add(order); ctx.SaveChanges(); } }
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"); } }
public void Remove(Customer customer) { try { using (var ctx = new MovieShopContext()) { var customerToDelete = ctx.Customers.Where(cust => cust.Id == customer.Id).FirstOrDefault(); ctx.Customers.Remove(customerToDelete); ctx.SaveChanges(); } } catch (DbUpdateException ex) { throw new Exception("Customer cannot be deleted"); } }
public void Update(Movie movie) { using (var ctx = new MovieShopContext()) { var movieToUpdate = ctx.Movies.FirstOrDefault(x => x.Id == movie.Id); if (movieToUpdate != null) { movieToUpdate.Title = movie.Title; movieToUpdate.Price = movie.Price; movieToUpdate.Year = movie.Year; movieToUpdate.PicturePath = movie.PicturePath; movieToUpdate.TrailerURL = movie.TrailerURL; movieToUpdate.Genre = ctx.Genres.FirstOrDefault(x => x.Id == movie.Genre.Id); ctx.SaveChanges(); } } }
public void Update(Customer customer) { using (var ctx = new MovieShopContext()) { var customerToUpdate = ctx.Customers.Where(cust => cust.Id == customer.Id).FirstOrDefault(); if (customerToUpdate != null) { customerToUpdate.Country = customer.Country; customerToUpdate.Email = customer.Email; customerToUpdate.Firstname = customer.Firstname; customerToUpdate.Lastname = customer.Lastname; customerToUpdate.StreetName = customer.StreetName; customerToUpdate.StreetNumber = customer.StreetNumber; customerToUpdate.Zipcode = customer.Zipcode; ctx.SaveChanges(); } } }