public ActionResult Edit([Bind(Include = "MovieFormatId,Price,Name")] RegisterMoviePriceViewModel moviePrice) { if (ModelState.IsValid) { MoviePrice moviePricedb = ConvertViewModelToMoviePrice(moviePrice); db.Entry(moviePricedb).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MovieFormatId = new SelectList(db.MovieFormat, "MovieFormatId", "Name", moviePrice.MovieFormatId); return(View(moviePrice)); }
// GET: MoviePrices/Edit/5 public ActionResult Edit(int id, string name) { MoviePrice moviePrice = db.MoviePrice. FirstOrDefault(item => item.MovieFormatId == id && item.Name == name); if (moviePrice == null) { return(HttpNotFound()); } RegisterMoviePriceViewModel moviePriceViewModel = ConvertMoviePriceToViewModel(moviePrice); ViewBag.MovieFormatId = new SelectList(db.MovieFormat, "MovieFormatId", "Name", moviePrice.MovieFormatId); return(View(moviePriceViewModel)); }
private MoviePrice ConvertViewModelToMoviePrice(RegisterMoviePriceViewModel moviePriceViewModel) { MoviePrice moviePrice = db.MoviePrice. FirstOrDefault(item => item.MovieFormatId == moviePriceViewModel.MovieFormatId && item.Name == moviePriceViewModel.Name); decimal.TryParse(moviePriceViewModel.Price, out decimal price); if (moviePrice == null) { moviePrice = new MoviePrice { MovieFormatId = moviePriceViewModel.MovieFormatId, Name = moviePriceViewModel.Name, Price = price }; } else { moviePrice.Price = price; } return(moviePrice); }