コード例 #1
0
        public async Task<ActionResult> CreateSeance(int? cinemaId)
        {
            if (cinemaId == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            Cinema hall = await db.Cinemas.FindAsync(c => c.Id == cinemaId);
            SeanceViewModel svm = new SeanceViewModel();

            if (hall == null)
            {
                return HttpNotFound();
            }

            svm.CinemaName = hall.Name;
            await PopulateSvmDropdownLists(cinemaId);
            return View(svm);
        }
コード例 #2
0
        public async Task<ActionResult> CreateSeance(SeanceViewModel svm)
        {
            if (ModelState.IsValid)
            {
                Hall hall = await db.Halls.FindAsync(h => h.Id == svm.Hall_ID);
                Movie movie = await db.Movies.FindAsync(m => m.Id == svm.Movie_ID);
                if (hall == null || movie == null)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.NotFound);
                }
                for (; svm.StartDate <= svm.EndDate; svm.StartDate = svm.StartDate.AddDays(1))
                {
                    Seance seance = new Seance
                    {
                        Date = svm.StartDate,
                        Time = svm.Time,
                        SeatsLeft = hall.Seats,
                        Price = svm.Price,
                        MovieId = svm.Movie_ID,
                        HallId = svm.Hall_ID
                    };
                    seance.Movie = movie;
                    seance.Hall = hall;
                    await db.Seances.InsertAsync(seance);
                }
                //Create seats to order for seances
                await CreateSeats();

                TempData["message"] = string.Format("Seances have been saved");
                return RedirectToAction("ViewSeances", new { cinemaId = hall.CinemaId });
            }
            else
            {
                TempData["message"] = string.Format("Seance hasn't been saved");
                return View();
            }
        }