コード例 #1
0
        public AdminEditMovieViewModel(Movie movie, IEnumerable<Category> categories)
        {
            Movie = movie;

            if(movie.Category == null) {
                Categories = new SelectList(categories,
                                        Category.PropertyNames.Id,
                                        Category.PropertyNames.Name);
            }
            else {
                Categories = new SelectList(categories,
                                        Category.PropertyNames.Id,
                                        Category.PropertyNames.Name,
                                        movie.Category.Id);
            }
        }
コード例 #2
0
        public void AddToCart(ref ShoppingCart shoppingCart, Movie movie)
        {
            Check.Require(shoppingCart != null);
            Check.Require(movie != null);

            var cartItem = shoppingCart.CartItems.FirstOrDefault(x => x.Movie.Id == movie.Id);

            if(cartItem == null) {
                cartItem = new CartItem {
                    Movie = movie,
                    Quantity = 1
                };

                shoppingCart.CartItems.Add(cartItem);
            }
            else {
                cartItem.Quantity++;
            }
        }
コード例 #3
0
        public void AddToCart(ref ShoppingCart shoppingCart, Movie movie)
        {
            Check.Require(shoppingCart != null);
            Check.Require(movie != null);

            var cartItem = shoppingCart.CartItems.FirstOrDefault(x => x.Movie.Id == movie.Id);

            if (cartItem == null) {
                cartItem = new CartItem
                               {
                                   Movie = movie,
                                   Quantity = 1
                               };

                shoppingCart.CartItems.Add(cartItem);
            }
            else {
                cartItem.Quantity++;
            }

            if (_authenticationService.IsAuthenticated())
                _cartItemRepository.SaveOrUpdate(cartItem);
        }
コード例 #4
0
 public void SaveOrUpdate(Movie movie)
 {
     if (_movies.Contains(movie)) {
         var index = _movies.IndexOf(movie);
         _movies.Remove(movie);
         _movies.Insert(index, movie);
     }
     else {
         _movies.Add(movie);
     }
 }
コード例 #5
0
 public void Delete(Movie movie)
 {
     _movies.Remove(movie);
 }
コード例 #6
0
        public void SaveOrUpdate(Movie movie)
        {
            Check.Require(null != movie);

            Session.SaveOrUpdate(movie);
        }
コード例 #7
0
        public void Delete(Movie movie)
        {
            Check.Require(null != movie);

            Session.Delete(movie);
        }
コード例 #8
0
        public ActionResult EditMovie(Movie movie, HttpPostedFileBase image)
        {
            if(ModelState.IsValid) {
                if(image != null) {
                    movie.ImageMimeType = image.ContentType;
                    movie.ImageData = new byte[image.ContentLength];
                    image.InputStream.Read(movie.ImageData, 0, image.ContentLength);
                }

                _moviesRepository.SaveOrUpdate(movie);

                TempData["message"] = string.Format("{0} has been saved", movie.Title);

                return RedirectToAction("Movies");
            }

            var categories = _categoriesRepository.GetAll();
            var viewModel = new AdminEditMovieViewModel(movie, categories);

            return View(viewModel);
        }