コード例 #1
0
        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"));
        }
コード例 #2
0
        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"));
        }
コード例 #3
0
        public ActionResult New()
        {
            var genres    = MemoryCache.Data <GenreType>(this.dao);
            var viewModel = ViewMapper.Map(new Movie(), genres);

            return(View("MovieForm", viewModel));
        }
コード例 #4
0
        public ActionResult List()
        {
            var moviesView = ViewMapper.Map(this.dao.GetDetached());

            if (User.IsInRole(RoleName.CanManageMovies))
            {
                return(View("List", moviesView));
            }

            return(View("AnonymousList", moviesView));
        }
コード例 #5
0
        public ActionResult Details(int id)
        {
            var customer = dao.GetDetached(id);

            if (customer == null)
            {
                return(HttpNotFound());
            }

            return(View(ViewMapper.Map(customer, customer.Movies)));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        public ActionResult New()
        {
            var viewModel = ViewMapper.Map(new Customer(), this.dao.GetDetached <MembershipType>());

            return(View("CustomerForm", viewModel));
        }