public ActionResult CreateMovie(newviewmodel viewmodel) { /* if (!ModelState.IsValid) * { * var viewmodels = new newviewmodel * { * genre = _context.Genre.ToList(), * movie = viewmodel.movie * }; * return View("EditMovieDetails",viewmodels); * * }*/ if (viewmodel.movie.MovieId == 0) { viewmodel.movie.DateAdded = DateTime.Now; _context.Movie.Add(viewmodel.movie); } else { var movieindb = _context.Movie.Single(m => m.MovieId == viewmodel.movie.MovieId); movieindb.MovieName = viewmodel.movie.MovieName; movieindb.NumberInStock = viewmodel.movie.NumberInStock; movieindb.GenreId = viewmodel.movie.GenreId; movieindb.ReleaseDate = viewmodel.movie.ReleaseDate; } // try //{ _context.SaveChanges(); //} return(RedirectToAction("MovieList", "Movie")); }
public ActionResult New() { var genres = _context.Genre.ToList(); var viewmodel = new newviewmodel { genre = genres }; return(View("EditMovieDetails", viewmodel)); }
public ActionResult CustomerForm() { var membership = _context.MembershipType.ToList(); var viewmodels = new newviewmodel() { MembershipTypes = membership }; return(View(viewmodels)); }
public ActionResult Edit(int id) { var customers = _context.Customers.SingleOrDefault(c => c.CustomerId == id); if (customers == null) { return(HttpNotFound()); } var viewmodels = new newviewmodel { customer = customers, MembershipTypes = _context.MembershipType.ToList() }; return(View("CustomerForm", viewmodels)); }
public ActionResult EditMovieDetails(int id) { var movies = _context.Movie.SingleOrDefault(c => c.MovieId == id); if (movies == null) { return(HttpNotFound()); } var viewmodel = new newviewmodel { genre = _context.Genre.ToList(), movie = movies }; return(View(viewmodel)); }
public ActionResult Create(Customer customer) { if (!ModelState.IsValid) { var viewmodel = new newviewmodel { customer = customer, MembershipTypes = _context.MembershipType.ToList() }; return(View("CustomerForm", viewmodel)); } if (customer.CustomerId == 0) { _context.Customers.Add(customer); } else { var customerinDb = _context.Customers.Single(c => c.CustomerId == customer.CustomerId); customerinDb.CustomerName = customer.CustomerName; customerinDb.birthdate = customer.birthdate; customerinDb.MembershipTypeId = customer.MembershipTypeId; customerinDb.iscustomersuscribedtonewsletter = customer.iscustomersuscribedtonewsletter; } // try //{ _context.SaveChanges(); //} //catch (DbEntityValidationException e) //{ // Console.WriteLine(e); //} return(RedirectToAction("CustomerList", "Customer")); }