Exemplo n.º 1
0
        private ICustomerDAO _customerDAO; //= new CustomerDAOMSSQL();

        public bool TryAdminLogin(string userName, string password, out LoginToken <Administrator> token)
        {
            if (userName == AirlineProjectConfig.ADMIN_USERNAME)
            {
                if (password != AirlineProjectConfig.ADMIN_PASSWORD)
                {
                    throw new WrongPasswordException($"failed to login as [{AirlineProjectConfig.ADMIN_USERNAME}], you entered a wrong password! [{password}]");
                }
                token = new LoginToken <Administrator>(new Administrator());
                return(true);
            }
            if (userName == AirlineProjectConfig.TEST_ADMIN_USERNAME)
            {
                if (password != AirlineProjectConfig.TEST_ADMIN_PASSWORD)
                {
                    throw new WrongPasswordException($"failed to login as [{AirlineProjectConfig.TEST_ADMIN_USERNAME}], you entered a wrong password! [{password}]");
                }
                token = new LoginToken <Administrator>(new Administrator());
                return(true);
            }

            token = null;
            return(false);
        }
        /// <summary>
        /// update one of your airline company's flights
        /// </summary>
        /// <param name="token"></param>
        /// <param name="flight">make sure it has the same id as the flight you want to update</param>
        public void UpdateFlight(LoginToken <AirlineCompany> token, Flight flight)
        {
            LoginHelper.CheckToken <AirlineCompany>(token);
            POCOValidator.FlightValidator(flight, true);
            Flight flightBeforeChange = _flightDAO.Get(flight.ID);

            if (flightBeforeChange == null)
            {
                throw new FlightNotFoundException($"Failed to update flight! Flight with id of [{flight.ID}] was not found!");
            }
            if (flight.AirlineCompanyId != token.User.ID)
            {
                throw new InaccessibleFlightException($"Failed to update flight! You do not own flight [{flight}]");
            }
            if (DateTime.Compare(flight.DepartureTime, flight.LandingTime) > 0)
            {
                throw new InvalidFlightDateException($"Failed to update flight [{flight}]! Cannot fly back in time from [{flight.DepartureTime}] to [{flight.LandingTime}]");
            }
            if (DateTime.Compare(flight.DepartureTime, flight.LandingTime) == 0)
            {
                throw new InvalidFlightDateException($"Failed to update flight [{flight}]! Departure time and landing time are the same [{flight.DepartureTime}], and as you know, teleportation isn't invented yet");
            }
            if (_countryDAO.Get(flight.OriginCountryCode) == null)
            {
                throw new CountryNotFoundException($"Failed to update flight [{flight}]! Origin country with id [{flight.OriginCountryCode}] was not found!");
            }
            if (_countryDAO.Get(flight.DestinationCountryCode) == null)
            {
                throw new CountryNotFoundException($"Failed to update flight [{flight}]! Destination country with id [{flight.DestinationCountryCode}] was not found!");
            }
            //decided to not add this because flights might get updated because of delayed departure time
            //if(flightBeforeChange.DepartureTime < DateTime.Now)
            //    if(flightBeforeChange.OriginCountryCode != flight.OriginCountryCode || flightBeforeChange.DepartureTime != flight.DepartureTime || flightBeforeChange.RemainingTickets != flight.RemainingTickets)
            //        throw new FlightAlreadyTookOffException($"failed to update flight [{flight}], can only update destination country and landing time after the flight took off!");
            _flightDAO.Update(flight);
        }
        /// <summary>
        /// cancels one of your tickets
        /// </summary>
        /// <param name="token"></param>
        /// <param name="ticket">removes a ticket based on this parameter's ID</param>
        public void CancelTicket(LoginToken <Customer> token, Ticket ticket)
        {
            LoginHelper.CheckToken <Customer>(token);
            POCOValidator.TicketValidator(ticket, true);
            Flight flight = _flightDAO.Get(ticket.FlightId);

            if (_ticketDAO.Get(ticket.ID) == null)
            {
                throw new TicketNotFoundException($"Failed to cancel ticket [{ticket}]! Ticket with ID of [{ticket.ID}] was not found!");
            }
            if (ticket.CustomerId != token.User.ID)
            {
                throw new InaccessibleTicketException($"Failed to cancel ticket! You do not own ticket [{ticket}]");
            }
            if (flight.DepartureTime < DateTime.Now)
            {
                throw new FlightAlreadyTookOffException($"Failed to cancel ticket! Flight [{flight.ID}] already took off!");
            }
            Flight updatedFlight = _flightDAO.Get(ticket.FlightId);

            updatedFlight.RemainingTickets++;
            _flightDAO.Update(updatedFlight);
            _ticketDAO.Remove(ticket);
        }
 public IList <Ticket> GetAllTickets(LoginToken <AirlineCompany> token)
 {
     //does that mean all tickets of all of my flights?
     throw new NotImplementedException();
 }
 public IList <Flight> GetAllFlights(LoginToken <AirlineCompany> token)
 {
     //my flights
     //if there are no flights, empty list
     throw new NotImplementedException();
 }
 public void UpdateFlight(LoginToken <AirlineCompany> token, Flight flight)
 {
     throw new NotImplementedException();
 }
 public void ModifyAirlineDetails(LoginToken <AirlineCompany> token, AirlineCompany airline)
 {
     throw new NotImplementedException();
 }
 public IList <Ticket> GetAllTickets(LoginToken <AirlineCompany> token)
 {
     throw new NotImplementedException();
 }
 public void ChangeMyPassword(LoginToken <AirlineCompany> token, string oldPassword, string newPassword)
 {
     throw new NotImplementedException();
 }
 public void UpdateCustomerDetails(LoginToken <Administrator> token, Customer customer)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// gets all the tickets of all the flights belonging to this airline company
 /// </summary>
 /// <param name="token"></param>
 /// <returns></returns>
 public IList <Ticket> GetAllTickets(LoginToken <AirlineCompany> token)
 {
     return(_ticketDAO.GetTicketsByAirlineCompany(token.User));
 }
 public IList <Ticket> GetAllMyTickets(LoginToken <Customer> token)
 {
     LoginHelper.CheckToken <Customer>(token);
     return(_ticketDAO.GetTicketsByCustomerId(token.User));
 }
Exemplo n.º 13
0
 public Ticket PurchaseTicket(LoginToken <Customer> token, Flight flight)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 14
0
 public IList <Flight> GetAllMyFlights(LoginToken <Customer> token)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
 public void CancelTicket(LoginToken <Customer> token, Ticket ticket)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
 public IList <Flight> GetAllFlights(LoginToken <AirlineCompany> token)
 {
     //all flights or my flights?
     //what if there are no flights? exception or empty list?
     throw new NotImplementedException();
 }
 /// <summary>
 /// can change all the airline's details except ID and Password
 /// </summary>
 /// <param name="token"></param>
 /// <param name="airline"></param>
 public void ModifyAirlineDetails(LoginToken <AirlineCompany> token, AirlineCompany airline)
 {
     //leave password and id alone
     throw new NotImplementedException();
 }
 public void RemoveCustomer(LoginToken <Administrator> token, Customer customer)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// gets all the flights belonging to this airline company
 /// </summary>
 /// <param name="token"></param>
 /// <returns></returns>
 public IList <Flight> GetAllFlights(LoginToken <AirlineCompany> token)
 {
     LoginHelper.CheckToken <AirlineCompany>(token);
     return(_flightDAO.GetFlightsByAirlineCompanyId(token.User));
 }
 public void UpdateAirlineDetails(LoginToken <Administrator> token, AirlineCompany airline)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 21
0
 /// <summary>
 /// gets all of your flights
 /// </summary>
 /// <param name="token">gets flights based on the user inside this token</param>
 /// <returns></returns>
 public IList <Flight> GetAllMyFlights(LoginToken <Customer> token)
 {
     LoginHelper.CheckToken <Customer>(token);
     return(_flightDAO.GetFlightsByCustomer(token.User));
 }
 public void RemoveAirline(LoginToken <Administrator> token, AirlineCompany airline)
 {
     throw new NotImplementedException();
 }