示例#1
0
        public void Insert(IReservationCreation reservation)
        {
            Reservation newReservation = new Reservation(reservation.Row, reservation.Column, reservation.ProjectionId);

            db.Reservations.Add(newReservation);
            db.SaveChanges();
        }
        public async Task <NewReservationSummary> NewAsync(IReservationCreation reservation)
        {
            var currProjection = await projectionRepo.GetProjectionByIdAsync(reservation.ProjectionId);

            var reservationExpiration = currProjection.StartDate - TimeSpan.FromMinutes(10);

            IReservation newReservation = await reservationRepo.InsertAsync(
                new Reservation(
                    reservation.ProjectionId,
                    reservation.Row,
                    reservation.Column,
                    reservationExpiration));

            await projectionRepo.DecreaseAvailableSeatsAsync(reservation.ProjectionId);

            //prepearing for reservation ticket
            var currMovie = await movieRepo.GetByIdAsync(currProjection.MovieId);

            var currRoom = await roomRepo.GetByIdAsync(currProjection.RoomId);

            var currCinema = await cinemaRepo.GetByIdAsync(currRoom.CinemaId);

            ReservationTicket reservationTicket = new ReservationTicket(
                newReservation.Id,
                currProjection.StartDate,
                currMovie.Name,
                currCinema.Name,
                currRoom.Number,
                newReservation.Row,
                newReservation.Column);

            return(new NewReservationSummary(true, reservationTicket));
        }
示例#3
0
        public IReservation Insert(IReservationCreation reserv)
        {
            Reservation newReserv = new Reservation(
                reserv.ProjectionId,
                reserv.Guid,
                reserv.ProjectionStartDate,
                reserv.MovieName,
                reserv.CinemaName,
                reserv.RoomNum,
                reserv.Row,
                reserv.Column,
                reserv.IsActive);

            db.Reservations.Add(newReserv);
            //List<Projection> results = (from p in db.Projections
            //                            where p.Id == reserv.ProjectionId
            //                            select p).ToList();

            //foreach (Projection p in results)
            //{
            //    p.AvailableSeatsCount--;
            //}

            db.Projections
            .Where(p => p.Id == reserv.ProjectionId)
            .ToList()
            .ForEach(x => x.AvailableSeatsCount--);

            db.SaveChanges();
            return(newReserv);
        }
        public async Task <NewReservationSummary> New(IReservationCreation reservation)
        {
            IProjection projection = await this.projRepo.GetById(reservation.ProjectionId);

            await this.projRepo.DecreaseAvailableSeats(projection.Id);

            string movieName = await this.movieRepo.GetMovieNameById(projection.MovieId);

            var room = await this.roomRepo.GetById(projection.RoomId);

            string cinemaName = await this.cinemaRepo.GetCinemaNameById(room.CinemaId);

            var newReservation = new Reservation(
                projection.StartDate,
                movieName,
                cinemaName,
                room.Number,
                reservation.Row,
                reservation.Column,
                projection.Id);

            await this.reservationRepo.Insert(newReservation);

            newReservation.Id = newReservation.Id;

            var result = new NewReservationSummary(true)
            {
                Reservation = newReservation
            };

            return(result);
        }
        public async Task <IReservation> Insert(IReservationCreation reservation)
        {
            Reservation newReservation = new Reservation(reservation.ProjectionStartDate, reservation.Movie, reservation.Cinema, reservation.Room, reservation.Row, reservation.Column, reservation.ProjectionId);

            db.Reservations.Add(newReservation);
            await db.SaveChangesAsync();

            return(newReservation);
        }
        public MakeReservationTicketSummary Make(IReservationCreation ticket)
        {
            if (DateTime.Compare(ticketsRepo.TicketStartTime(ticket.ProjId), DateTime.Now) < 0)
            {
                return(new MakeReservationTicketSummary(false, $"Can't make reservation. Projection {ticket.ProjId} has already started."));
            }

            return(new MakeReservationTicketSummary(true, ticketsRepo.MakeReservation(ticket)));
        }
示例#7
0
        public MakeReservationTicketSummary Make(IReservationCreation ticket)
        {
            // global constant for timespan
            if (ticketsRepo.TicketStartTime(ticket.ProjId) - DateTime.Now <= new TimeSpan(0, 10, 0))
            {
                return new MakeReservationTicketSummary(false, $"Can't make reservation. Projection {ticket.ProjId} is about to start.");
            }

            return new MakeReservationTicketSummary(true, ticketsRepo.MakeReservation(ticket));
        }
        public async Task <NewReservationSummary> New(IReservationCreation model)
        {
            IProjection projection = await this.projRepo.GetById(model.ProjectionId);

            if (projection == null)
            {
                return(new NewReservationSummary(false, $"Projection with id {model.ProjectionId} does not exist"));
            }

            return(await newReservation.New(model));
        }
示例#9
0
        //TODO: Check for minutes.
        public async Task <NewReservationSummary> New(IReservationCreation model)
        {
            DateTime projectionStartDate = await this.projRepo.GetProjectionStartDate(model.ProjectionId);

            if (DateTime.Now > projectionStartDate)
            {
                return(new NewReservationSummary(false, StringConstants.MovieStarted));
            }

            return(await newReservation.New(model));
        }
        public async Task <NewCreationSummary> New(IReservationCreation reservation)
        {
            DateTime currentDate = DateTime.UtcNow;

            if (currentDate > reservation.ProjectionStartDate)
            {
                return(new NewCreationSummary(false, "Cannot reserve seats for finished projection"));
            }

            return(await newReservation.New(reservation));
        }
示例#11
0
        public NewReservationSummary New(IReservationCreation reservation)
        {
            IProjection projection = projectionRepo.GetById(reservation.ProjectionId);

            if (projection == null)
            {
                return(new NewReservationSummary(HttpStatusCode.BadRequest, "Projection doesn't exist"));
            }

            return(newReservation.New(reservation));
        }
示例#12
0
        public async Task <NewCreationSummary> New(IReservationCreation reservation)
        {
            IReservation reservationDb = await reserveRepo.Get(reservation.Row, reservation.Column, reservation.ProjectionId);

            if (reservationDb != null)
            {
                return(new NewCreationSummary(false, "The seats are already reserved"));
            }

            return(await newReservation.New(reservation));
        }
        public async Task <NewCreationSummary> New(IReservationCreation reservation)
        {
            var projection = projRepo.GetById(reservation.ProjectionId);

            if (reservation.Row > projection.Room.Rows || reservation.Column > projection.Room.SeatsPerRow)
            {
                return(new NewCreationSummary(false, "The seats does not exist in this room"));
            }

            return(await newReservation.New(reservation));
        }
示例#14
0
        public NewReservationSummary New(IReservationCreation reservation)
        {
            IReservation foundReservation = reservationRepo.Get(reservation.Row, reservation.Column, reservation.ProjectionId);

            if (foundReservation == null)
            {
                return(newReservation.New(reservation));
            }

            return(new NewReservationSummary(System.Net.HttpStatusCode.Forbidden, "Seat is not available"));
        }
示例#15
0
        public async Task <NewCreationSummary> New(IReservationCreation reservation)
        {
            DateTime currentDate = DateTime.UtcNow;
            TimeSpan ts          = reservation.ProjectionStartDate - currentDate;

            if (ts.TotalMinutes > 0 && ts.TotalMinutes < 10)
            {
                return(new NewCreationSummary(false, "Cannot reserve seats for projection starting in less than 10 minutes"));
            }

            return(await newReservation.New(reservation));
        }
        public async Task <NewReservationSummary> New(IReservationCreation model)
        {
            DateTime projectionStartDate = await this.projRepo.GetProjectionStartDate(model.ProjectionId);

            //DONE: Check minutes?
            if (DateTime.Now.AddMinutes(10) > projectionStartDate)
            {
                return(new NewReservationSummary(false, StringConstants.ProjectionIsStarting));
            }

            return(await newReservation.New(model));
        }
示例#17
0
        public async Task <NewReservationSummary> New(IReservationCreation reservation)
        {
            bool available = await this.projRepo.CheckIfSeatIsAvailable
                                 (reservation.ProjectionId, reservation.Row, reservation.Column);

            if (available == false)
            {
                return(new NewReservationSummary(false, StringConstants.OccupiedPlace));
            }

            return(await newReservation.New(reservation));
        }
示例#18
0
        public NewReservationSummary New(IReservationCreation reservation)
        {
            IEnumerable <IReservation> reservedSeats = reservationRepo.GetReservedSeats(reservation.ProjectionId);

            bool checkSeat = reservedSeats.Any(x => x.Row == reservation.Row && x.Column == reservation.Column);

            if (checkSeat)
            {
                return(new NewReservationSummary(false, "This seat is already reserved"));
            }

            return(newRes.New(reservation));
        }
        public NewReservationSummary New(IReservationCreation reservation)
        {
            IProjection projection = projRepo.GetById(reservation.ProjectionId);

            DateTime now = DateTime.UtcNow.AddMinutes(ActionConstants.MinutesToProjection);

            if (projection.StartDate < now)
            {
                return(new NewReservationSummary(false, "You have to make a reservation at least 10 minutes prior to the begining of the projection!"));
            }

            return(newRes.New(reservation));
        }
        public async Task Insert(IReservationCreation reservation)
        {
            Reservation newReservation = new Reservation(
                reservation.ProjectionStartDate,
                reservation.MovieName,
                reservation.CinemaName,
                reservation.RoomNumber,
                reservation.Row,
                reservation.Column,
                reservation.ProjectionId);

            this.db.Reservations.Add(newReservation);

            await this.db.SaveChangesAsync();
        }
示例#21
0
        public NewReservationSummary New(IReservationCreation reservation)
        {
            int   roomId = projectionRepo.GetById(reservation.ProjectionId).RoomId;
            IRoom room   = roomRepo.GetById(roomId);

            if (reservation.Row > room.Rows)
            {
                return(new NewReservationSummary(HttpStatusCode.BadRequest, "Row doesn't exist for the room of the projection"));
            }
            else if (reservation.Column > room.SeatsPerRow)
            {
                return(new NewReservationSummary(HttpStatusCode.BadRequest, "Column doesn't exist for the room of the projection"));
            }

            return(newReservation.New(reservation));
        }
        public NewReservationSummary New(IReservationCreation reservation)
        {
            IRoom room = reservationRepo.GetRoomById(reservation.ProjectionId);

            bool checkSeatExistence = room.Rows < reservation.Row ||
                                      room.SeatsPerRow < reservation.Column ||
                                      reservation.Row <= 0 ||
                                      reservation.Column <= 0;

            if (checkSeatExistence)
            {
                return(new NewReservationSummary(false, "This seat does not exist"));
            }

            return(newRes.New(reservation));
        }
        public async Task <NewReservationSummary> NewAsync(IReservationCreation reservation)
        {
            var currProjection = await projectionsRepo.GetProjectionByIdAsync(reservation.ProjectionId);

            var endingTimeToReserve = currProjection.StartDate - TimeSpan.FromMinutes(10);

            if (endingTimeToReserve <= DateTime.Now)
            {
                var constraintMessage = "It is too late to make reservations for this projection! Seats are no longer available.";

                return(new NewReservationSummary(false, constraintMessage));
            }
            else
            {
                return(await newReservation.NewAsync(reservation));
            }
        }
        public async Task <NewReservationSummary> NewAsync(IReservationCreation reservation)
        {
            var currProjection = await projectionRepo.GetProjectionByIdAsync(reservation.ProjectionId);

            var currRoom = await roomRepo.GetByIdAsync(currProjection.RoomId);

            if ((currRoom.Rows < reservation.Row) || (currRoom.SeatsPerRow < reservation.Column))
            {
                var constraintMessage = "This seat not exist in this room!";

                return(new NewReservationSummary(false, constraintMessage));
            }
            else
            {
                return(await newReservation.NewAsync(reservation));
            }
        }
        public MakeReservationTicketSummary Make(IReservationCreation ticket)
        {
            int roomRows = ticketsRepo.RoomRows(ticket.ProjId);
            int roomCols = ticketsRepo.RoomSeatsPerRow(ticket.ProjId);

            if (ticketsRepo.SeatTaken(ticket.SeatRow, ticket.SeatCol))
            {
                return(new MakeReservationTicketSummary(false, $"Can't make reservation. Seat at {ticket.SeatRow} {ticket.SeatCol} is taken."));
            }

            if (ticket.SeatCol <= 0 || ticket.SeatCol > roomCols || ticket.SeatRow <= 0 || ticket.SeatRow > roomRows)
            {
                return(new MakeReservationTicketSummary(false, $"Can't make reservation. Seat at {ticket.SeatRow} {ticket.SeatCol} doesn't exist."));
            }

            return(new MakeReservationTicketSummary(true, ticketsRepo.MakeReservation(ticket)));
        }
示例#26
0
        public async Task <NewReservationSummary> New(IReservationCreation reservation)
        {
            var projection = await this.projRepo.GetById(reservation.ProjectionId);

            var room = await this.roomRepo.GetById(projection.RoomId);

            //TODO get room ID

            if (reservation.Row < 0 || reservation.Row > room.SeatsPerRow ||
                reservation.Column < 0 || reservation.Column > room.Rows)
            {
                return(new NewReservationSummary(false, $"Seat with position row: {reservation.Row}" +
                                                 $" and column: {reservation.Column} does not exist"));
            }

            return(await newReservation.New(reservation));
        }
        public async Task <NewReservationSummary> NewAsync(IReservationCreation reservation)
        {
            var reservationFromAnother = await reservationRepo
                                         .GetAsync(reservation.ProjectionId, reservation.Row, reservation.Column);

            var TicketFromAnother = await ticketRepo
                                    .GetAsync(reservation.ProjectionId, reservation.Row, reservation.Column);

            if (reservationFromAnother != null || TicketFromAnother != null)
            {
                var constraintMessage = "This seat is already reserved!";

                return(new NewReservationSummary(false, constraintMessage));
            }
            else
            {
                return(await newReservation.NewAsync(reservation));
            }
        }
示例#28
0
        public IReservationTicket MakeReservation(IReservationCreation reservation)
        {
            ReservationTicket reservationTicket = new ReservationTicket(reservation.ProjId, reservation.SeatRow,
                                                                        reservation.SeatCol);

            reservationTicket.Projection             = db.Projections.FirstOrDefault((p) => p.Id == reservation.ProjId);
            reservationTicket.Projection.Movie       = db.Movies.FirstOrDefault((m) => m.Id == reservationTicket.Projection.MovieId);
            reservationTicket.Projection.Room        = db.Rooms.FirstOrDefault((r) => r.Id == reservationTicket.Projection.RoomId);
            reservationTicket.Projection.Room.Cinema = db.Cinemas.FirstOrDefault(
                (c) => c.Id == reservationTicket.Projection.Room.CinemaId);

            --reservationTicket.Projection.AvailableSeatsCount;

            db.ReservationTickets.Add(reservationTicket);
            db.SaveChanges();

            return(new MakeReservationTicket(reservationTicket.Id, reservationTicket.Projection.StartDate,
                                             reservationTicket.Projection.Movie.Name, reservationTicket.Projection.Room.Cinema.Name,
                                             reservationTicket.Projection.Room.Number, reservationTicket.SeatRow, reservationTicket.SeatCol));
        }
        public ReservationTicket Insert(IReservationCreation reservation)
        {
            Reservation newReservaton = new Reservation(reservation.ProjectionStartDate,
                                                        reservation.MovieName, reservation.CinemaName, reservation.RoomNumber, reservation
                                                        .Row, reservation.Column, reservation.ProjectionId);

            var projection = this.projectionRepository.GetProjectionById(reservation.ProjectionId);

            db.Reservations.Add(newReservaton);

            projection.AvailableSeatsCount--;
            db.SaveChanges();

            return(new ReservationTicket
            {
                UniqueKeyOfReservation = newReservaton.Id,
                ProjectionStartDate = newReservaton.ProjectionStartDate,
                MovieName = newReservaton.MovieName,
                CinemaName = newReservaton.CinemaName,
                RoomNumber = newReservaton.RoomNumber,
                Row = newReservaton.Row,
                Column = newReservaton.Column
            });
        }
示例#30
0
        public NewReservationSummary New(IReservationCreation reservation)
        {
            reservationsRepo.Insert(new Reservation(reservation.ProjectionId, reservation.Column, reservation.Row));

            return(new NewReservationSummary(true));
        }