public ActionResult Save(MovieModelViewForm viewModel) { if (!ModelState.IsValid) { var genres = MemoryCache.Data <GenreType>(this.dao); var retViewModel = ViewMapper.Map(viewModel.Movie, genres); return(View("MovieForm", retViewModel)); } var movie = viewModel.Movie; if (movie.Id <= 0) { movie.DateAdded = DateTime.Now; this.dao.Add(movie); } else { var movieInDB = this.dao.Get(movie.Id); movieInDB.Name = movie.Name; movieInDB.ReleaseDate = movie.ReleaseDate; movieInDB.GenreTypeId = movie.GenreTypeId; movieInDB.NumberInStock = movie.NumberInStock; movieInDB.NumberAvailable = movieInDB.NumberInStock; } this.dao.SaveChanges(); return(RedirectToAction("list", "movies")); }
public ActionResult New() { var genres = MemoryCache.Data <GenreType>(this.dao); var viewModel = ViewMapper.Map(new Movie(), genres); return(View("MovieForm", viewModel)); }
public ActionResult Edit(int id) { var movie = this.dao.GetDetached(id); if (movie == null) { return(HttpNotFound()); } var genres = MemoryCache.Data <GenreType>(this.dao); var viewModel = ViewMapper.Map(movie, genres); return(View("MovieForm", viewModel)); }