Ejemplo n.º 1
0
        public AirTicketOfficeContext GetAvailableFlight(Customer customer)
        {
            AirTicketOfficeContext availableFlight = new AirTicketOfficeContext();

            for (int i = 0; i < context.Flights.Length; i++)
            {
                bool     isEmpty     = true;
                string[] customersId = context.GetFlightByIndex(i).CustomersId;
                if (context.GetFlightByIndex(i).CustomersId.Length == 0)
                {
                    availableFlight.Flights = AddFlightToArray(availableFlight, i).Flights;
                    isEmpty = false;
                }
                for (int j = 0; j < context.GetFlightByIndex(i).CustomersId.Length; j++)
                {
                    if (customer.Id.Equals(customersId[j]))
                    {
                        isEmpty = false;
                    }
                }
                if (isEmpty)
                {
                    availableFlight.Flights = AddFlightToArray(availableFlight, i).Flights;
                }
            }
            if (availableFlight.Flights.Length == 0)
            {
                throw new BookingException("You haven't available flight. Sorry(");
            }
            logger.Info("Got list of available flights");
            return(availableFlight);
        }
Ejemplo n.º 2
0
        public AirTicketOfficeContext GetFlightsBookedByCustomer(Customer customer)
        {
            AirTicketOfficeContext occupiedCars = new AirTicketOfficeContext();

            for (int i = 0; i < context.SizeOfFlight(); i++)
            {
                String[] customersId = context.GetFlightByIndex(i).CustomersId;
                if (context.GetFlightByIndex(i).CustomersId.Length == 0)
                {
                    continue;
                }
                for (int j = 0; j < context.GetFlightByIndex(i).CustomersId.Length; j++)
                {
                    if (customer.Id.Equals(customersId[j]))
                    {
                        occupiedCars.Flights = AddFlightToArray(occupiedCars, i).Flights;
                        break;
                    }
                }
            }
            if (occupiedCars.Flights.Length == 0)
            {
                throw new BookingException("You haven't booked flight.");
            }
            logger.Info("Got list of booked by customer flights");
            return(occupiedCars);
        }
Ejemplo n.º 3
0
 private AirTicketOfficeContext AddFlightToArray(AirTicketOfficeContext airTicketOfficeContext, int index)
 {
     Flight[] flights = airTicketOfficeContext.Flights;
     Array.Resize(ref flights, flights.Length + 1);
     flights[flights.Length - 1]    = context.GetFlightByIndex(index);
     airTicketOfficeContext.Flights = flights;
     return(airTicketOfficeContext);
 }
Ejemplo n.º 4
0
 public static void SerializeeJson(AirTicketOfficeContext contex)
 {
     using (StreamWriter file = new StreamWriter(PATH_TO_FILE))
     {
         var json = JsonConvert.SerializeObject(contex);
         file.WriteLine(json);
     }
 }
        public void getTicketsBookedExistingCustomerByLength()
        {
            CustomerController customerController   = new CustomerController();
            int                    isActual         = 2;
            Customer               customer         = customerController.AddNewCustomerOrGetExisting("Helena", "lenka_bokshic");
            FlightController       flightController = new FlightController();
            AirTicketOfficeContext availableFlight  = flightController.GetFlightsBookedByCustomer(customer);

            Assert.AreEqual(availableFlight.Flights.Length, isActual);
        }
        public void getAvailableFlightOfExistingCustomerByLength()
        {
            CustomerController customerController   = new CustomerController();
            int                    isActual         = 1;
            Customer               customer         = customerController.AddNewCustomerOrGetExisting("Matvey", "matvey_anisovich");
            FlightController       flightController = new FlightController();
            AirTicketOfficeContext availableFlight  = flightController.GetAvailableFlight(customer);

            Assert.AreEqual(availableFlight.Flights.Length, isActual);
        }
        public void getAvailableFlightOfNewCustomerByLength()
        {
            CustomerController     customerController = new CustomerController();
            Customer               customer           = customerController.AddNewCustomerOrGetExisting("Ivan", "ivan_ivanov");
            FlightController       flightController   = new FlightController();
            AirTicketOfficeContext context            = AirTicketOfficeContext.Context;
            AirTicketOfficeContext availableFlight    = flightController.GetAvailableFlight(customer);

            Assert.AreEqual(availableFlight.Flights.Length, context.SizeOfFlight());
        }
Ejemplo n.º 8
0
 public static void ChoicebyCustomer(FlightController flightController, Customer customer, int action)
 {
     try
     {
         if (action == 1)
         {
             AirTicketOfficeContext availableFlight = flightController.GetAvailableFlight(customer);
             Printer.print(availableFlight.ToString());
             Printer.print("Choose flight");
             int index = Convert.ToInt32(UserInput.input());
             flightController.BookTicket(availableFlight.Flights[index - 1], customer);
             logger.Info("Ticket is booked");
         }
         else if (action == 2)
         {
             AirTicketOfficeContext occupiedCars = flightController.GetFlightsBookedByCustomer(customer);
             Printer.print(occupiedCars.ToString());
             Printer.print("Choose flight");
             int index = Convert.ToInt32(UserInput.input());
             flightController.ReturnTicket(occupiedCars.Flights[index - 1], customer);
             logger.Info("Ticket is booked");
         }
         else
         {
             throw new InputException("You should enter 1 or 2");
         }
     }
     catch (Exception ex)
     {
         if (ex is BookingException || ex is InputException)
         {
             System.Console.WriteLine($"Error: {ex.Message}");
         }
         logger.Error(ex.Message);
     }
 }
Ejemplo n.º 9
0
 public FlightController()
 {
     context = AirTicketOfficeContext.Context;
 }
Ejemplo n.º 10
0
 public CustomerController()
 {
     context = AirTicketOfficeContext.Context;
 }