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 Save(CustomerFormViewModel viewModel) { var customer = viewModel.Customer; if (!ModelState.IsValid) { var returnViewModel = ViewMapper.Map(customer, this.dao.GetDetached <MembershipType>()); return(View("CustomerForm", returnViewModel)); } if (customer.Id <= 0) { this.dao.Add(customer); } else { var customerInDB = this.dao.Get(customer.Id); customerInDB.Name = customer.Name; customerInDB.BirthDate = customer.BirthDate; customerInDB.MembershipTypeId = customer.MembershipTypeId; customerInDB.IsSubscribedToNewsletter = customer.IsSubscribedToNewsletter; } this.dao.SaveChanges(); return(RedirectToAction("list", "customers")); }
public ActionResult New() { var genres = MemoryCache.Data <GenreType>(this.dao); var viewModel = ViewMapper.Map(new Movie(), genres); return(View("MovieForm", viewModel)); }
public ActionResult List() { var moviesView = ViewMapper.Map(this.dao.GetDetached()); if (User.IsInRole(RoleName.CanManageMovies)) { return(View("List", moviesView)); } return(View("AnonymousList", moviesView)); }
public ActionResult Details(int id) { var customer = dao.GetDetached(id); if (customer == null) { return(HttpNotFound()); } return(View(ViewMapper.Map(customer, customer.Movies))); }
public ActionResult Edit(int id) { var customer = this.dao.GetDetached(id); if (customer == null) { return(HttpNotFound()); } var viewModel = ViewMapper.Map(customer, this.dao.GetDetached <MembershipType>()); return(View("CustomerForm", 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)); }
public ActionResult Details(int id) { var movie = this.dao.GetDetached(id); if (movie == null) { return(HttpNotFound()); } var viewModel = ViewMapper.Map(movie, movie.Customers); if (User.IsInRole(RoleName.CanManageMovies)) { return(View("Details", viewModel)); } return(View("AnonymousDetails", viewModel)); }
public ActionResult New() { var viewModel = ViewMapper.Map(new Customer(), this.dao.GetDetached <MembershipType>()); return(View("CustomerForm", viewModel)); }