Ejemplo n.º 1
0
        public NewTicketSummery New(ITicketRequest ticket)
        {
            if (ticket.Guid != null)
            {
                IReservation reservation = reservationRepo.GetReservationByGuid(ticket.Guid);

                if (reservation == null)
                {
                    return(new NewTicketSummery(false, $"There is someting wrong with this reservation code: {ticket.Guid}"));
                }

                if (reservation.IsActive == false)
                {
                    return(new NewTicketSummery(false, $"This reservation is canceled. It is either used or expired!"));
                }

                return(newTicket.New(new TicketWithReservationtModel(
                                         reservation.ProjectionId,
                                         reservation.Row,
                                         reservation.Column
                                         )));
            }

            return(newTicket.New(ticket));
        }
Ejemplo n.º 2
0
        public NewTicketSummery New(ITicketRequest ticket)
        {
            if (ticket.Guid == null)
            {
                IEnumerable <ITicket> boughtSites = ticketRepo.BoughtSeats(ticket.ProjectionId);

                IEnumerable <IReservation> reservationsSits = reservationRepo.GetRowsColsById(ticket.ProjectionId);

                foreach (var sit in boughtSites)
                {
                    if (ticket.Row == sit.Row && ticket.Column == sit.Column)
                    {
                        return(new NewTicketSummery(false, "This seat is already taken!"));
                    }
                }

                foreach (var reserv in reservationsSits)
                {
                    if (ticket.Row == reserv.Row && ticket.Column == reserv.Column)
                    {
                        return(new NewTicketSummery(false, "This seat is Reserved!"));
                    }
                }
            }
            return(newTicket.New(ticket));
        }
Ejemplo n.º 3
0
        public IHttpActionResult Index(TicketRequestModel model)
        {
            NewTicketSummery summery = newTicket.New(new Ticket(
                                                         model.ProjectionId,
                                                         model.Row,
                                                         model.Column
                                                         ));

            if (summery.IsCreated)
            {
                return(Ok(summery.Ticket));
            }
            else
            {
                return(BadRequest(summery.Message));
            }
        }
        public async Task <NewCreationSummary> New(ITicketCreation ticket)
        {
            IReservation reservationDb = await reserveRepo.Get(ticket.Row, ticket.Column, ticket.ProjectionId);

            if (reservationDb != null)
            {
                return(new NewCreationSummary(false, "Cannot buy reserved seats"));
            }

            return(await newTicket.New(ticket));
        }
Ejemplo n.º 5
0
        public async Task <NewTicketSummary> New(ITicketCreation model)
        {
            IProjection projection = await this.projRepo.GetById(model.ProjectionId);

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

            return(await newTicket.New(model));
        }
Ejemplo n.º 6
0
        public async Task <NewTicketSummary> New(ITicketCreation model)
        {
            IProjection projection = await this.projRepo.GetById(model.ProjectionId);

            if (DateTime.Now > projection.StartDate)
            {
                return(new NewTicketSummary(false, StringConstants.MovieStarted));
            }

            return(await newTicket.New(model));
        }
        public async Task <NewCreationSummary> New(ITicketCreation ticket)
        {
            DateTime currentDate = DateTime.UtcNow;

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

            return(await newTicket.New(ticket));
        }
        public async Task <NewCreationSummary> New(ITicketCreation ticket)
        {
            ITicket ticketDb = ticketRepo.Get(ticket.Row, ticket.Column, ticket.ProjectionId);

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

            return(await newTicket.New(ticket));
        }
        public async Task <NewTicketSummary> New(ITicketCreation ticket)
        {
            var projection = await this.projRepo.GetById(ticket.ProjectionId);

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

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

            return(await newTicket.New(ticket));
        }
        public async Task <NewCreationSummary> New(ITicketCreation ticket)
        {
            var reservations = await reserveRepo.GetAllReservations();

            await reserveRepo.CancelExpiredReservations(reservations);

            DateTime currentDate = DateTime.UtcNow;
            TimeSpan ts          = ticket.ProjectionStartDate - currentDate;

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

            return(await newTicket.New(ticket));
        }
Ejemplo n.º 11
0
        public async Task <IHttpActionResult> Ticket([FromUri] TicketCreationModel model)
        {
            Projection dbProj = projRepo.GetById(model.Id);

            NewCreationSummary summary = await newTicket.New(new Ticket(dbProj.StartDate, dbProj.Movie.Name, dbProj.Room.Cinema.Name, dbProj.Room.Number, model.Row, model.Column, dbProj.Id));

            var ticket = ticketRepo.Get(model.Row, model.Column, model.Id);

            if (summary.IsCreated)
            {
                await projRepo.DecreaseSeatsCount(model.Id);

                return(Ok(ticket));
            }
            else
            {
                return(BadRequest(summary.Message));
            }
        }
        public NewTicketSummery New(ITicketRequest ticket)
        {
            IProjection projection = projectionRepo.GetById(ticket.ProjectionId);

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

            IMovie movie         = movieRepo.GetById(projection.MovieId);
            var    now           = DateTime.UtcNow;
            var    projectionEnd = projection.StartDate.AddMinutes(movie.DurationMinutes);

            if (projection.StartDate <= now || projectionEnd <= now)
            {
                return(new NewTicketSummery(false, $"Projection:{projection.Id} already started or finished!"));
            }

            return(newTicket.New(ticket));
        }
        public async Task <NewTicketSummary> New(ITicketCreation ticket)
        {
            IProjection projection = await this.projRepo.GetById(ticket.ProjectionId);

            DateTime projectionStartdate = await this.projRepo.GetProjectionStartDate(projection.Id);

            if (DateTime.Now.AddMinutes(10) >= projectionStartdate)
            {
                int count = await this.reservationRepository.RemoveAllReservations(projection.Id);

                await this.projRepo.IncreaseAvailableSeats(projection.Id, count);
            }

            bool available = await this.projRepo.CheckIfSeatIsAvailable
                                 (ticket.ProjectionId, ticket.Row, ticket.Column);

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

            return(await newTicket.New(ticket));
        }