Exemplo n.º 1
0
        public IHttpActionResult PostRental(CustomerMovieVM customerMovieVM)
        {
            var Customer = _context.customers.Single(c => c.id == customerMovieVM.customerId);

            var movies = _context.movies.Where(
                m => customerMovieVM.movieIds.Contains(m.ID));

            foreach (var movy in movies)
            {
                if (movy.NumberAvailable == 0)
                {
                    return(BadRequest("Movie is not available."));
                }

                movy.NumberAvailable--;

                var CustomerMovie = new CustomerMovie
                {
                    customer   = Customer,
                    movie      = movy,
                    DateRented = DateTime.Now
                };

                _context.CustomerMovies.Add(CustomerMovie);
            }
            _context.SaveChanges();


            return(Ok());
        }
Exemplo n.º 2
0
        // GET: Customer
        public ActionResult Index()
        {
            var movie = new Movie()
            {
                Name = "Movie 1"
            };

            CustomerMovieVM customerMovieVM = new CustomerMovieVM
            {
                movie     = movie,
                customers = _db.customers.ToList(),
            };

            return(View(customerMovieVM));
        }