Esempio n. 1
0
        public ActionResult MakeReservation(ReservationFlowViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { success = false }));
            }

            var showing = db.Repo <Showing>().Get(model.Showing.ID);

            if (showing.Time < DateTime.Now)
            {
                return(Json(new { success = false }));
            }

            var takenPlaces = (db.Repo <Place>() as IPlacesRepo).GetTakenPlaces(model.Showing.ID);

            if (takenPlaces.Intersect(model.SelectedPlaces, new PlacePosition.Comparer()).Count() != 0)
            {
                return(Json(new { success = false }));
            }

            var reservation = new Reservation
            {
                ShowingID    = model.Showing.ID,
                CinemaUserID = User.Identity.GetUserId(),

                Places = model.SelectedPlaces.ConvertAll(p => new Place {
                    x = p.x, y = p.y
                }),
                ReservationDate = DateTime.Now
            };

            db.Repo <Reservation>().Add(reservation);
            db.Save();

            mail.SendMail(User.Identity.Name, "Potwierdzenie rezerwacji",
                          string.Format("Dziękujemy za rezerwacje filmu {0}, {1}. Seans odbędzie się o {2}. Nr rezerwacji {3}",
                                        showing.Movie.Title,
                                        showing.GetMetadataString(),
                                        showing.Time.ToString("HH:mm, dddd dd.MM"),
                                        reservation.ID));

            return(Json(new { success = true, redirect_url = Url.Action("Index", "Manage") }));
        }
Esempio n. 2
0
        public ActionResult Index(int?id)
        {
            if (!id.HasValue)
            {
                return(View("Error"));
            }

            Showing showing = db.Repo <Showing>().Get(id.Value);

            if (showing.Time < DateTime.Now)
            {
                return(View("Error"));
            }

            var takenPlaces = (db.Repo <Place>() as IPlacesRepo).GetTakenPlaces(showing.ID);

            var movie = new Movie
            {
                Title       = showing.Movie.Title,
                Description = showing.Movie.Description,
                Runtime     = showing.Movie.Runtime,
                PosterUrl   = Url.Content(showing.Movie.PosterUrl),
            };

            showing.Movie = null;

            var viewModel = new ReservationFlowViewModel
            {
                Showing = showing,
                Movie   = movie,

                SelectedPlaces = new List <PlacePosition>(),
                TakenPlaces    = takenPlaces,

                PostUrl = Url.Action("MakeReservation"),
            };

            return(View(viewModel));
        }
Esempio n. 3
0
        private JsonResult MakeReservationHelper(ReservationFlowViewModel model)
        {
            var db = new MockUnitOfWork();

            model.Movie         = model.Movie ?? new Movie();
            model.Showing       = model.Showing ?? db.Repo <Showing>().Get(0);
            model.Showing.Movie = model.Showing.Movie ?? new Movie();

            model.TakenPlaces    = model.TakenPlaces ?? (db.Repo <Place>() as IPlacesRepo).GetTakenPlaces(0);
            model.SelectedPlaces = model.SelectedPlaces ?? new List <PlacePosition> {
                new PlacePosition {
                    x = 0, y = 1
                }
            };
            model.PostUrl = model.PostUrl ?? "test";

            (db.Repo <Showing>() as MockShowingsRepo).Showing = model.Showing;

            var reservationFlow = CreateController(db);

            return(reservationFlow.MakeReservation(model) as JsonResult);
        }