Exemplo n.º 1
0
 public Ticket(long number, FilmScreening filmScreening, Seat seat, Viewer viewer, decimal price)
 {
     this.Number        = number;
     this.FilmScreening = filmScreening;
     this.Seat          = seat;
     this.Viewer        = viewer;
     this.Price         = price;
 }
Exemplo n.º 2
0
        public Ticket BuyTicket(int filmId, int filmScreeningId, int seatNumber, decimal price, Viewer viewer)
        {
            FilmScreening filmScreening = GetFilmScreening(filmId, filmScreeningId);

            try
            {
                if (filmScreening != null && GetFilmScreeningPrice(filmId, filmScreeningId, seatNumber) == price)
                {
                    if (filmScreening.Film.MinAge <= viewer.Age)
                    {
                        if (filmScreening.SeatPlaces[seatNumber].Busy != true)
                        {
                            Money += price;

                            Ticket ticket = new Ticket(Tickets.Length, filmScreening, filmScreening.SeatPlaces[seatNumber], viewer, price);
                            //Повернення грошей, за 3 години до сеансу.
                            //if (filmScreening.DateTime < DateTime.Now&& DateTime.Now < filmScreening.DateTime.AddHours(-3))
                            if (filmScreening.DateTime > new DateTime(2021, 2, 25, 17, 30, 00) && new DateTime(2021, 2, 25, 17, 30, 00) > filmScreening.DateTime.AddHours(-3))
                            {
                                Money -= price;
                                Console.WriteLine($"The money {price} has been turned");
                            }
                            else
                            {
                                filmScreening.SeatPlaces[seatNumber].Busy = true;
                                Console.WriteLine("Ticket purchased successfully");
                                return(ticket);
                            }
                        }
                        else
                        {
                            throw new BusySeatException("Place is taken!");
                        }
                    }
                    else
                    {
                        throw new InvalidAgeException("Your age is restricted");
                    }
                }
                else
                {
                    throw new NotExistException("No such film found!");
                }
            }
            catch (ApplicationException e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }


            return(null);
        }
Exemplo n.º 3
0
        public decimal GetFilmScreeningPrice(int filmId, int filmScreeningId, int seatNumber)
        {
            FilmScreening filmScreening = GetFilmScreening(filmId, filmScreeningId);

            try
            {
                if (filmScreening != null)
                {
                    decimal price = filmScreening.Film.Price + filmScreening.Hall.Price;
                    return(price);
                }
                else
                {
                    throw new NotExistException("No such film found!");
                }
            }
            catch (NotExistException e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }

            return(-1);
        }