Exemple #1
0
        public void ReserveShow(MovieReservation reservation)
        {
            if (reservation == null)
            {
                throw new ArgumentNullException(nameof(reservation), $"{nameof(reservation)} is null.");
            }
            if (reservation.Seats.Count() == 0)
            {
                throw new ArgumentException("At least one seat must be selected to book a reservation.");
            }
            using (var context = new TheaterContext())
            {
                foreach (var seat in reservation.Seats)
                {
                    var existing = context.Reservations.SingleOrDefault(x => x.ShowingId == reservation.ShowingId && x.TheaterId == reservation.TheaterId && x.Row == seat.Row && x.SeatNumber == seat.Number);
                    if (existing != null)
                    {
                        throw new Exception($"Seat {seat.Row}-{seat.Number} has already been reserved.");
                    }
                    context.Reservations.Add(new Entities.Reservation
                    {
                        ShowingId  = reservation.ShowingId,
                        TheaterId  = reservation.TheaterId,
                        Row        = seat.Row,
                        SeatNumber = seat.Number
                    });
                }

                context.SaveChanges();
            }
        }
Exemple #2
0
        protected void ReserveSeats_Click(object sender, EventArgs e)
        {
            // Gather the info on the selected seats

            // 1) Get the Theater & Show info
            var selectedShow = ShowTimesListView.SelectedDataKey;
            int showingId, theaterId;

            int.TryParse(selectedShow["ShowingId"].ToString(), out showingId);
            int.TryParse(selectedShow["TheaterId"].ToString(), out theaterId);

            // 2) Get the seats that are being requested
            List <SeatReservation> seats = new List <SeatReservation>();

            foreach (ListViewDataItem userInputs in SeatingListView.Items)
            {
                var checkbox = userInputs.FindControl("SeatSelection") as CleanCheckBox;
                if (checkbox != null && checkbox.Enabled && checkbox.Checked)
                {
                    var    hiddenRow    = userInputs.FindControl("SeatRow") as HiddenField;
                    var    hiddenNumber = userInputs.FindControl("SeatNumber") as HiddenField;
                    string row          = hiddenRow.Value;
                    int    number       = int.Parse(hiddenNumber.Value);

                    seats.Add(new SeatReservation {
                        Row = row, Number = number
                    });
                }
            }

            var reservation = new MovieReservation
            {
                ShowingId = showingId,
                TheaterId = theaterId,
                Seats     = seats
            };

            // Process the reservation
            // NOTE: In a "real" system, I should be including info on the user...
            try
            {
                var controller = new BookingController();
                controller.ReserveShow(reservation);
                MessageLabel.Text               = $"The following seats have been reserved for you: <b>{string.Join("</b>, <b>", reservation.Seats)}</b>";
                MessageLabel.CssClass           = "alert alert-success";
                MessageLabel.Attributes["role"] = "alert";
            }
            catch (Exception ex)
            {
                MessageLabel.Text               = $"There's a problem with your reservation: {ex.Message}";
                MessageLabel.CssClass           = "alert alert-danger";
                MessageLabel.Attributes["role"] = "alert";
            }
            PopulateSeatingListView();
        }
        public IActionResult Create(MovieReservation reservation)
        {
            if (reservation != null)
            {
                var movie = _context.Movies.Include(x => x.Seats).FirstOrDefault(x => x.Id == reservation.MovieId);
                var seat  = movie.Seats.FirstOrDefault(x => x.Id == reservation.SeatId);

                //var seat = (from x in _context.Movies.Find(reservation.movieId).Seats
                //    where x.Id == reservation.seatId
                //    select x).FirstOrDefault();
                if (seat != null)
                {
                    seat.UserId   = reservation.UserId;
                    seat.Reserved = true;
                    _context.SaveChanges();

                    //TODO: fix sending multiple request fro parking reservation from one user -> on Front End
                    if (reservation.WantParking)
                    {
                        var parking = _context.Parking.FirstOrDefault(x => x.Reserved == false);

                        if (parking != null)
                        {
                            var startdate = DateTimeOffset.FromUnixTimeMilliseconds(reservation.StartDate).UtcDateTime;
                            var enddate   = DateTimeOffset.FromUnixTimeMilliseconds(reservation.EndDate).UtcDateTime;

                            parking.UserId    = reservation.UserId;
                            parking.StartDate = startdate;
                            parking.EndDate   = enddate;
                            parking.Reserved  = true;

                            _context.SaveChanges();

                            return(NoContent());
                        }

                        return(CreatedAtRoute("getMovieAndParking", reservation));
                    }

                    return(NoContent());
                }

                return(CreatedAtRoute("getMovie", reservation));
            }

            return(BadRequest());
        }
Exemple #4
0
        public void Execute(MovieReservationDto request)
        {
            validator.ValidateAndThrow(request);

            var movieId = request.MovieId;

            var reservation = new MovieReservation
            {
                MovieId         = request.MovieId,
                UserId          = request.UserId,
                ReservationDate = DateTime.Now
            };

            context.MovieReservations.Add(reservation);

            var movie = context.Movies.Where(m => m.Id == movieId).FirstOrDefault();

            movie.OnStock -= 1;

            context.SaveChanges();
        }