// GET: TheaterMovies/Create
        public ActionResult Create(int TheaterID)
        {
            ViewBag.MovieID = new SelectList(db.Movies, "MovieID", "Name");

            var model = new ShowtimeViewModel();

            model.Action    = "Create";
            model.TheaterID = TheaterID;
            model.Showtime  = DateTime.Now.AddDays(1);
            model.NewMovie  = false;
            return(View(model));
        }
        public async Task <ActionResult> Create([Bind(Include = "MovieID,Movie,NewMovie,TheaterID,Showtime")] ShowtimeViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (viewModel.NewMovie)
                {
                    db.Movies.Add(viewModel.Movie);
                    await db.SaveChangesAsync();
                }

                var theaterMovie = new TheaterMovie();
                theaterMovie.TheaterID = viewModel.TheaterID;
                theaterMovie.MovieID   = viewModel.NewMovie ? viewModel.Movie.MovieID : viewModel.MovieID;
                theaterMovie.Showtime  = viewModel.Showtime;

                db.TheaterMovies.Add(theaterMovie);
                await db.SaveChangesAsync();

                return(RedirectToAction("Details", "Theaters", new { id = theaterMovie.TheaterID }));
            }

            ViewBag.MovieID = new SelectList(db.Movies, "MovieID", "Name", viewModel.MovieID);
            return(View(viewModel));
        }
        // GET: TheaterMovies/Edit/5
        public async Task <ActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TheaterMovie theaterMovie = await db.TheaterMovies.FindAsync(id);

            if (theaterMovie == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MovieID = new SelectList(db.Movies, "MovieID", "Name", theaterMovie.MovieID);

            ShowtimeViewModel viewModel = new ShowtimeViewModel();

            viewModel.Action    = "Update";
            viewModel.Id        = theaterMovie.Id;
            viewModel.MovieID   = theaterMovie.MovieID;
            viewModel.TheaterID = theaterMovie.TheaterID;
            viewModel.Showtime  = theaterMovie.Showtime;

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