Example #1
0
        public ActionResult Create([Bind(Include = "Id,Name")] Genre genre)
        {
            if (ModelState.IsValid)
            {
                db.Genres.Add(genre);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(genre));
        }
        public IHttpActionResult CreateCustomer(CustomerDto customersDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var customer = Mapper.Map <CustomerDto, Customers>(customersDto);

            _context.Customers.Add(customer);
            _context.SaveChanges();

            customersDto.Id = customer.Id;
            return(Created(new Uri(Request.RequestUri + "/" + customer.Id), customersDto));
        }
Example #3
0
        public IHttpActionResult CreateMovie(MovieDto movieDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var movie = Mapper.Map <MovieDto, Movie>(movieDto);

            _context.Movies.Add(movie);
            _context.SaveChanges();

            movieDto.Id = movie.Id;
            return(Created(new Uri(Request.RequestUri + "/" + movie.Id), movieDto));
        }
        public ActionResult Save(Customers customers)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new CustomerFormViewModel
                {
                    Customers       = customers,
                    memberShipTypes = _context.MembershipTypes.ToList()
                };
                return(View("CustomerForm", viewModel));
            }
            if (customers.Id == 0)
            {
                _context.Customers.Add(customers);
            }
            else
            {
                var customerInDb = _context.Customers.Single(c => c.Id == customers.Id);
                customerInDb.Name                    = customers.Name;
                customerInDb.Birthdate               = customers.Birthdate;                 //Updating Customer
                customerInDb.MembershipTypeId        = customers.MembershipTypeId;
                customerInDb.IsSubscribeToNewsletter = customers.IsSubscribeToNewsletter;
            }
            // _context.Customers.Add(customers);
            _context.SaveChanges();

            return(RedirectToAction("Customers", "Customers"));
        }
Example #5
0
        public ActionResult Save()
        {
            Movie movie = new Movie();

            movie.Name          = Request.Form["Movie.Name"];
            movie.Id            = Request.Form["Movie.Id"] != string.Empty ? Convert.ToInt32(Request.Form["Movie.Id"]) : 0;
            movie.GenreId       = Convert.ToByte(Request.Form["Movie.GenreId"]);
            movie.ReleaseDate   = DateTime.Parse(Request.Form["Movie.ReleaseDate"]);
            movie.NumberInStock = Convert.ToByte(Request.Form["Movie.NumberInStock"]);

            if (movie.Id == 0)
            {
                movie.DateAdded = DateTime.Now;
                _context.Movies.Add(movie);
            }
            else
            {
                var movieInDb = _context.Movies.Single(m => m.Id == movie.Id);
                movieInDb.Name          = movie.Name;
                movieInDb.GenreId       = movie.GenreId;
                movieInDb.NumberInStock = movie.NumberInStock;
                movieInDb.ReleaseDate   = movie.ReleaseDate;
            }
            _context.SaveChanges();

            return(RedirectToAction("Index", "Movie"));
        }
        public ActionResult Save(NewCustomerViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                var Model = new NewCustomerViewModel
                {
                    Customer        = viewModel.Customer,
                    MembershipTypes = _Context.MembershipTypes.ToList()
                };

                return(View("NewCustomer", Model));
            }
            if (viewModel.Customer.Id == 0)
            {
                _Context.Customers.Add(viewModel.Customer);
            }
            else
            {
                var CustomerInDb = _Context.Customers.Single(x => x.Id == viewModel.Customer.Id);
                CustomerInDb.Name = viewModel.Customer.Name;
                CustomerInDb.IsSubscribedToNewsLetter = viewModel.Customer.IsSubscribedToNewsLetter;
                CustomerInDb.MembershipTypeId         = viewModel.Customer.MembershipTypeId;
            }
            _Context.SaveChanges();

            return(RedirectToAction("Index", "Customer"));
        }
        public IHttpActionResult CreateNewRentals(NewRentalDto newRental)
        {
            var customer = _context.Customers.Single(
                c => c.Id == newRental.CustomerId);

            var movies = _context.Movies.Where(
                m => newRental.MovieIds.Contains(m.Id)).ToList();

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

                movie.NumberAvailable--;

                var rental = new Rental
                {
                    Customer   = customer,
                    Movie      = movie,
                    DateRented = DateTime.Now
                };

                _context.Rentals.Add(rental);
            }

            _context.SaveChanges();
            return(Ok());
        }
Example #8
0
 public ActionResult Create(Customer customer)
 {
     _context.Customers.Add(customer);
     _context.SaveChanges();
     return(RedirectToAction("Index"));
 }