public ActionResult Save(CustomerMovieRental customerMovieRental)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new CustomerMovieRentalViewModel
                {
                    CustomerMovieRental = customerMovieRental,
                    Movies = _context.Movies.ToList()
                };
                return(View("CustomerMovieRentalForm", viewModel));
            }
            if (customerMovieRental.Id == 0)
            {
                _context.CustomerMovieRentals.Add(customerMovieRental);
            }

            else
            {
                var customerMovieRentalInDb = _context.CustomerMovieRentals.Single(m => m.Id == customerMovieRental.Id);
                customerMovieRentalInDb.CustomerId = customerMovieRental.CustomerId;
                customerMovieRentalInDb.MovieId    = customerMovieRental.MovieId;
                customerMovieRentalInDb.Checkin    = customerMovieRental.Checkin;
                customerMovieRentalInDb.Checkout   = customerMovieRental.Checkout;
            }


            _context.SaveChanges();
            return(RedirectToAction("Details", "Customers", new { id = customerMovieRental.CustomerId }));
        }
        public ActionResult Save(Customer cust)
        {
            bool Messages      = cust.Name == "" || cust.Subscription == "" || cust.Age < 18;
            bool CustomerExist = CustomerMovieRental.GetCustomer(cust.Name);



            //if (ModelState.IsValid)
            //    return RedirectToAction("Index");
            //else
            //    return View("New");

            if (Messages)
            {
                if (cust.Name == "")
                {
                    ViewBag.EnterName = "Enter Name";;
                }
                if (cust.Subscription == "")
                {
                    ViewBag.EnterSubscription = "Enter Subscription";
                }
                if (cust.Age == 0)
                {
                    ViewBag.EnterAge = "Enter Age";
                }
                return(View("New"));
            }
            else
            {
                if (CustomerExist)// expected true if user Exist in Table
                {
                    ViewBag.UserExist = "this user alredy exist";
                    return(View("New"));
                }

                if (cust.Age < 18)
                {
                    ViewBag.EnterAge = "your age is less then 18";
                    return(View("New"));
                }
                else
                {
                    //add into Table
                    StorageHelper.AddNewCustomerIntoTable(cust.Name, cust.Subscription, cust.Age);
                }
            }
            return(RedirectToAction("Index"));
        }
        public ActionResult Save(string MovieName, string MovieCategory) //NewMovie
        {
            bool bIsValid   = MovieName == "" || MovieCategory == "";
            bool MovieExist = CustomerMovieRental.GetMovie(MovieName);

            if (bIsValid)
            {
                ViewBag.Error = "Enter movie name";
                return(View("New"));
            }
            else
            {
                if (MovieExist)//if true this movie alredy exist in the table DB
                {
                    ViewBag.Error = "This Movie alredy exist";
                    return(View("New"));
                }

                StorageHelper.AddNewMovieIntoTable(MovieName, MovieCategory);

                return(RedirectToAction("Index"));
            }
        }
        public ActionResult CreateNewRentals(string MovieNameRental, string UserNameRental)
        {
            bool   IsSucessed = true;
            string MovieAlreadyRented = "", customerNotFound = "",
                   movieNotFound = "", RentSucsses = "";

            List <Movy>     listMovie    = StorageHelper.GetMovieList();
            List <Customer> listCustomer = StorageHelper.GetCustomerList();

            bool MovieExists   = listMovie.Exists(item => item.Name == MovieNameRental);
            bool CustomerExist = listCustomer.Exists(item => item.Name == UserNameRental);

            int  MovieId    = CustomerMovieRental.GetMovieId(MovieNameRental);
            int  CustomerId = CustomerMovieRental.GetCustomerId(UserNameRental);
            bool IdMovieExistInRentalTable = CustomerMovieRental.MovieIdExistInRental(MovieId);

            if (MovieNameRental == "" || UserNameRental == "")
            {
                if (MovieNameRental == "")
                {
                    movieNotFound = "Enter Movie";
                }
                if (UserNameRental == "")
                {
                    customerNotFound = "Enter Customer";
                }
                IsSucessed = false;
            }
            else
            {
                if (!CustomerExist || !MovieExists)
                {
                    if (!CustomerExist)
                    {
                        movieNotFound = "This Movie not exist";
                    }
                    if (!MovieExists)
                    {
                        customerNotFound = "This Customer not exist";
                    }
                    IsSucessed = false;
                }
                else
                {
                    if (IdMovieExistInRentalTable)
                    {
                        IsSucessed         = false;
                        MovieAlreadyRented = "This movied already rented";
                    }
                    else
                    {
                        CustomerMovieRental.InsertIntoRentalTable(MovieId, CustomerId);
                        IsSucessed  = true;
                        RentSucsses = "your rental sucsses";
                    }
                }
            }
            var obj = new { key  = customerNotFound, key2 = movieNotFound,
                            key3 = MovieAlreadyRented, key4 = RentSucsses, key1 = IsSucessed };

            return(Json(obj, JsonRequestBehavior.AllowGet));
        }