public ActionResult Save(customermovie model) { var customer = _context.Customer.Single( c => c.id == model.customer); var movies = _context.movies.Where( m => model.CustmoerMovies.Contains(m.ID)).ToList(); foreach (var movie in movies) { var rental = new Rental { customer = customer, movie = movie, DateRented = DateTime.Now, Name = customer.name }; _context.rentals.Add(rental); _context.SaveChanges(); } return(RedirectToAction("Customer", "Customer")); }
public ActionResult New() { var customernames = _context.Customer.Select(m => new SelectListItem() { Text = m.name, Value = m.id.ToString() }).ToList(); var moviesnames = _context.movies.Select(m => new SelectListItem() { Text = m.Name, Value = m.ID.ToString() }).ToList(); var viewModel = new customermovie { movies = moviesnames, customers = customernames }; return(View(viewModel)); }