/// <summary>
        /// cancels one of your flights
        /// </summary>
        /// <param name="token"></param>
        /// <param name="flight">deletes using this parameter's ID</param>
        public void CancelFlight(LoginToken <AirlineCompany> token, Flight flight)
        {
            LoginHelper.CheckToken <AirlineCompany>(token);
            POCOValidator.FlightValidator(flight, true);
            if (_flightDAO.Get(flight.ID) == null)
            {
                throw new FlightNotFoundException($"Failed to cancel flight! There is no flight with ID [{flight.ID}]");
            }
            if (flight.AirlineCompanyId != token.User.ID)
            {
                throw new InaccessibleFlightException($"Failed to cancel flight! You do not own flight [{flight}]");
            }
            if (_flightDAO.Get(flight.ID).DepartureTime < DateTime.Now) //was sql current date supposed to be involved? probably not?
            {
                throw new FlightAlreadyTookOffException($"Failed to cancel flight! Flight [{flight}] already took off at [{flight.DepartureTime}]");
            }
            _ticketDAO.RemoveTicketsByFlight(flight); //doesn't notify the customers but it'll be too much decoration for this project
            _flightDAO.Remove(flight);

            // to delete a poco ==> i need to delete those
            //4 airlineCompany ==> flights ==> what if it's flying? please ignore
            //5 country ==> airlineCompanies, flights ==> umm... bermuda triangle stuff right here? please ignore - don't really need to remove countries
            //3 customer ==> tickets
            //2 flight ==> tickets
            //1 ticket ==> none
        }
Example #2
0
        /// <summary>
        /// cancels one of your flights
        /// </summary>
        /// <param name="token"></param>
        /// <param name="flight">deletes using this parameter's ID</param>
        public void CancelFlight(LoginToken <AirlineCompany> token, Flight flight)
        {
            LoginHelper.CheckToken <AirlineCompany>(token);
            POCOValidator.FlightValidator(flight, true);
            if (_flightDAO.Get(flight.ID) == null)
            {
                throw new FlightNotFoundException($"failed to cancel flight! there is no flight with id [{flight.ID}]");
            }
            if (flight.AirlineCompanyId != token.User.ID)
            {
                throw new InaccessibleFlightException($"failed to cancel flight! you do not own flight [{flight}]");
            }
            if (_flightDAO.Get(flight.ID).DepartureTime < DateTime.Now) //was sql current date supposed to be involved?
            {
                throw new FlightAlreadyTookOffException($"failed to cancel flight! flight [{flight}] already took off at [{flight.DepartureTime}]");
            }
            _ticketDAO.RemoveTicketsByFlight(flight);
            _flightDAO.Remove(flight);


            //need to add functions to to remove Poco lists:

            // to delete a poco ==> you need to delete those
            //airlineCompany ==> flights ==> what if it's flying? please ignore
            //country ==> airlineCompanies, flights ==> umm... bermuda triangle stuff right here? please ignore
            //customer ==> tickets
            //flight ==> tickets
            //ticket ==> none
        }
 /// <summary>
 /// creates a flight
 /// </summary>
 /// <param name="token"></param>
 /// <param name="flight">id and airline company id will be generated upon creation, leave them at 0</param>
 public void CreateFlight(LoginToken <AirlineCompany> token, Flight flight)
 {
     LoginHelper.CheckToken <AirlineCompany>(token);
     POCOValidator.FlightValidator(flight, false);
     //if (flight.AirlineCompanyId != token.User.ID)
     //    throw new InaccessibleFlightException($"failed to create flight [{flight}], you do not own this flight!"); //probably won't happen unless something goes wrong
     if (_airlineDAO.Get(flight.AirlineCompanyId) == null)
     {
         throw new AirlineNotFoundException($"Failed to create flight [{flight}]! Airline [{flight.AirlineCompanyId}] was not found!");
     }
     if (DateTime.Compare(flight.DepartureTime, flight.LandingTime) > 0)
     {
         throw new InvalidFlightDateException($"Failed to create 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 create 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 create flight [{flight}]! Origin country with id [{flight.OriginCountryCode}] was not found!");
     }
     if (_countryDAO.Get(flight.DestinationCountryCode) == null)
     {
         throw new CountryNotFoundException($"Failed to create flight [{flight}]! Destination country with id [{flight.DestinationCountryCode}] was not found!");
     }
     //yes, there can technically be flights with 0 seats available, can easily change it in the POCOValidator but i prefer it to be an option
     flight.AirlineCompanyId = token.User.ID;
     _flightDAO.Add(flight);
 }
        public Ticket PurchaseTicket(LoginToken <Customer> token, Flight flight)
        {
            LoginHelper.CheckToken <Customer>(token);
            POCOValidator.FlightValidator(flight, false);
            if (_flightDAO.Get(flight.ID) == null)
            {
                throw new FlightNotFoundException($"failed to purchase ticket, there is no flight with id of [{flight.ID}]");
            }
            IList <Ticket> tickets = _ticketDAO.GetTicketsByCustomerId(token.User);

            foreach (var item in tickets) //again.... feels inefficient...
            {
                if (item.FlightId == flight.ID)
                {
                    throw new TicketAlreadyExistsException($"failed to purchase ticket, you already purchased a ticket to flight [{flight}]");
                }
            }
            if (_flightDAO.Get(flight.ID).RemainingTickets == 0)
            {
                throw new NoMoreTicketsException($"failed to purchase ticket to flight [{flight}], there are no more tickets left!");
            }
            //do i even need to check if the flight in the parameter is legit?
            Ticket newTicket = new Ticket(0, flight.ID, token.User.ID);

            _ticketDAO.Add(newTicket);
            flight.RemainingTickets--; //do i do this with the parameter flight or with the one from the database?
            _flightDAO.Update(flight);
            return(newTicket);
        }
Example #5
0
 /// <summary>
 /// updates an airline company
 /// </summary>
 /// <param name="token"></param>
 /// <param name="airline">updates the airline company with this parameter's ID</param>
 public void UpdateAirlineDetails(LoginToken <Administrator> token, AirlineCompany airline)
 {
     LoginHelper.CheckToken <Administrator>(token);
     POCOValidator.AirlineCompanyValidator(airline, true);
     if (_airlineDAO.Get(airline.ID) == null)
     {
         throw new UserNotFoundException($"Failed to update airline! Airline with ID [{airline.ID}] was not found!");
     }
     if (_airlineDAO.GetAirlineByAirlineName(airline.AirlineName) != null)
     {
         if (_airlineDAO.Get(airline.ID).AirlineName != airline.AirlineName)
         {
             throw new AirlineNameAlreadyExistsException($"Failed to modify details! There is already an airline with the name [{airline.AirlineName}]");
         }
     }
     if (_airlineDAO.GetAirlineByUsername(airline.UserName) != null)
     {
         if (_airlineDAO.Get(airline.ID).UserName != airline.UserName)
         {
             throw new UsernameAlreadyExistsException($"Failed to modify details! Username [{airline.UserName}] is already taken!");
         }
     }
     if (airline.Password.Trim() == "" || airline.Password == "{}")
     {
         throw new EmptyPasswordException($"Failed to change password! The new password is empty!"); //did i even need this? POCOValidator already checks this
     }
     if (_countryDAO.Get(airline.CountryCode) == null)
     {
         throw new CountryNotFoundException($"Failed to update airline! There is no country with ID [{airline.CountryCode}]");
     }
     _airlineDAO.Update(airline);
 }
        public void CancelFlight(LoginToken <AirlineCompany> token, Flight flight)
        {
            //what if it's in the air? how do i know the current date?
            LoginHelper.CheckToken <AirlineCompany>(token);
            POCOValidator.FlightValidator(flight, true);
            if (_flightDAO.Get(flight.ID) == null)
            {
                throw new FlightNotFoundException($"failed to cancel flight! there is no flight with id [{flight.ID}]");
            }
            if (flight.AirlineCompanyId != token.User.ID)
            {
                throw new InaccessibleFlightException($"failed to cancel flight! you do not own flight [{flight}]");
            }
            _ticketDAO.RemoveTicketsByFlight(flight);
            _flightDAO.Remove(flight);


            //need to add functions to to remove Poco lists
            //if customer is deleted then flight's vacancy is increased

            // to delete a poco ==> you need to delete those
            //airlineCompany ==> flights ==> what if it's flying?
            //country ==> airlineCompanies, flights ==> umm... bermuda triangle stuff right here? please ignore
            //customer ==> tickets
            //flight ==> tickets
            //ticket ==> none
        }
Example #7
0
        /// <summary>
        /// purchases a ticket to a flight
        /// </summary>
        /// <param name="token"></param>
        /// <param name="flight">the flight you want to purchase a ticket for</param>
        /// <returns></returns>
        public Ticket PurchaseTicket(LoginToken <Customer> token, Flight flight)
        {
            LoginHelper.CheckToken <Customer>(token);
            POCOValidator.FlightValidator(flight, false);
            if (_flightDAO.Get(flight.ID) == null)
            {
                throw new FlightNotFoundException($"failed to purchase ticket, there is no flight with id of [{flight.ID}]");
            }
            IList <Ticket> tickets = _ticketDAO.GetTicketsByCustomerId(token.User);

            if (tickets.Any(item => item.FlightId == flight.ID)) //boolean
            {
                throw new TicketAlreadyExistsException($"failed to purchase ticket, you already purchased a ticket to flight [{flight}]");
            }
            if (_flightDAO.Get(flight.ID).RemainingTickets == 0)
            {
                throw new NoMoreTicketsException($"failed to purchase ticket to flight [{flight}], there are no more tickets left!");
            }
            Ticket newTicket = new Ticket(0, flight.ID, token.User.ID);

            _ticketDAO.Add(newTicket);
            flight.RemainingTickets--;
            _flightDAO.Update(flight);
            return(newTicket);
        }
        /// <summary>
        /// purchases a ticket to a flight
        /// </summary>
        /// <param name="token"></param>
        /// <param name="flight">the flight you want to purchase a ticket for</param>
        /// <returns></returns>
        public Ticket PurchaseTicket(LoginToken <Customer> token, Flight flight)
        {
            LoginHelper.CheckToken <Customer>(token);
            POCOValidator.FlightValidator(flight, true);
            if (_flightDAO.Get(flight.ID) == null)
            {
                throw new FlightNotFoundException($"Failed to purchase ticket! There is no flight with ID of [{flight.ID}]");
            }
            IList <Ticket> tickets = _ticketDAO.GetTicketsByCustomerId(token.User);

            if (tickets.Any(item => item.FlightId == flight.ID)) //boolean
            {
                throw new TicketAlreadyExistsException($"Failed to purchase ticket! You already purchased a ticket to flight [{flight}]");
            }
            if (flight.DepartureTime < DateTime.Now)
            {
                throw new FlightAlreadyTookOffException($"Failed to cancel ticket! Flight [{flight.ID}] already took off!");
            }
            if (_flightDAO.Get(flight.ID).RemainingTickets == 0)
            {
                throw new NoMoreTicketsException($"Failed to purchase ticket to flight [{flight}]! There are no more tickets left!");
            }
            Ticket newTicket = new Ticket(0, flight.ID, token.User.ID);

            _ticketDAO.Add(newTicket);
            flight.RemainingTickets--;
            _flightDAO.Update(flight);
            return(newTicket); //yes, it has the id too!
        }
 public void UpdateFlight(LoginToken <AirlineCompany> token, Flight flight)
 {
     LoginHelper.CheckToken <AirlineCompany>(token);
     POCOValidator.FlightValidator(flight, true);
     if (_flightDAO.Get(flight.ID) == 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!");
     }
     _flightDAO.Update(flight);
 }
 public void CreateFlight(LoginToken <AirlineCompany> token, Flight flight)
 {
     LoginHelper.CheckToken <AirlineCompany>(token);
     POCOValidator.FlightValidator(flight, false);
     if (flight.AirlineCompanyId != token.User.ID)
     {
         throw new InaccessibleFlightException($"failed to create flight [{flight}], you do not own this flight!"); //probably won't happen unless something goes wrong
     }
     if (DateTime.Compare(flight.DepartureTime, flight.LandingTime) > 0)
     {
         throw new InvalidFlightDateException($"failed to create 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 create 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 create flight [{flight}], origin country with id [{flight.OriginCountryCode}] was not found!");
     }
     if (_countryDAO.Get(flight.DestinationCountryCode) == null)
     {
         throw new CountryNotFoundException($"failed to create flight [{flight}], destination country with id [{flight.DestinationCountryCode}] was not found!");
     }
     _flightDAO.Add(flight);
 }
 /// <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)
 {
     LoginHelper.CheckToken <AirlineCompany>(token);
     POCOValidator.AirlineCompanyValidator(airline, true);
     if (airline.ID != token.User.ID)
     {
         throw new InaccessibleAirlineCompanyException($"Failed to modify details! This is not your account!"); //will it ever happen? who knows...
     }
     if (_airlineDAO.GetAirlineByAirlineName(airline.AirlineName) != null)
     {
         if (_airlineDAO.GetAirlineByAirlineName(airline.AirlineName) != token.User)
         {
             throw new AirlineNameAlreadyExistsException($"Failed to modify details! There is already an airline with the name [{airline.AirlineName}]");
         }
     }
     if (_airlineDAO.GetAirlineByUsername(airline.UserName) != null)
     {
         if (_airlineDAO.GetAirlineByUsername(airline.UserName) != token.User)
         {
             throw new UsernameAlreadyExistsException($"Failed to modify details! Username [{airline.UserName}] is already taken!");
         }
     }
     if (_countryDAO.Get(airline.CountryCode) == null)
     {
         throw new CountryNotFoundException($"Failed to update airline! There is no country with id [{airline.CountryCode}]");
     }
     airline.Password = _airlineDAO.Get(airline.ID).Password; // i guess..
     _airlineDAO.Update(airline);
 }
 public void CreateNewCustomer(Customer customer)
 {
     POCOValidator.CustomerValidator(customer, false);
     if (_airlineDAO.GetAirlineByUsername(customer.UserName) != null || _customerDAO.GetCustomerByUsername(customer.UserName) != null || customer.UserName == "admin")
     {
         throw new UsernameAlreadyExistsException($"failed to create customer! Username '{customer.UserName}' is already taken!");
     }
     _customerDAO.Add(customer);
 }
Example #13
0
 /// <summary>
 /// temporary, supposed to be in admin facade (?)
 /// </summary>
 /// <param name="customer">updates the customer with this parameter's ID</param>
 public void UpdateCustomerDetails(Customer customer)
 {
     POCOValidator.CustomerValidator(customer, true);
     if (_customerDAO.Get(customer.ID) == null)
     {
         throw new UserNotFoundException($"Failed to update customer! Customer with username [{customer.UserName}] was not found!");
     }
     _customerDAO.Update(customer);
 }
 public void CreateNewCountry(Country country)
 {
     POCOValidator.CountryValidator(country, false);
     if (_countryDAO.GetCountryByName(country.CountryName) != null)
     {
         throw new CountryAlreadyExistsException($"failed to create country! Country name '{country.CountryName}' already exists!");
     }
     _countryDAO.Add(country);
 }
 public void RemoveAirline(LoginToken <Administrator> token, AirlineCompany airline)
 {
     LoginHelper.CheckToken <Administrator>(token);
     POCOValidator.AirlineCompanyValidator(airline, true);
     if (_airlineDAO.Get(airline.ID) == null) //doesn't mean the airline in the parameter has the same values as the airline in the database with the same id
     {
         throw new UserNotFoundException($"failed to remove airline! airline with username [{airline.UserName}] was not found!");
     }
     _airlineDAO.Remove(airline);
 }
 /// <summary>
 /// updates a customer
 /// </summary>
 /// <param name="token"></param>
 /// <param name="customer">updates the customer with this parameter's ID</param>
 public void UpdateCustomerDetails(LoginToken <Administrator> token, Customer customer)
 {
     LoginHelper.CheckToken <Administrator>(token);
     POCOValidator.CustomerValidator(customer, true);
     if (_customerDAO.Get(customer.ID) == null)
     {
         throw new UserNotFoundException($"failed to update customer! customer with username [{customer.UserName}] was not found!");
     }
     _customerDAO.Update(customer);
 }
 public void UpdateCustomerDetails(LoginToken <Administrator> token, Customer customer)
 {
     LoginHelper.CheckToken <Administrator>(token);
     POCOValidator.CustomerValidator(customer, true);
     if (_customerDAO.Get(customer.ID) == null) //doesn't mean the customer in the parameter has the same values as the customer in the database with the same id
     {
         throw new UserNotFoundException($"failed to update customer! customer with username [{customer.UserName}] was not found!");
     }
     _customerDAO.Update(customer);
 }
Example #18
0
 /// <summary>
 /// creates a new customer
 /// </summary>
 /// <param name="token"></param>
 /// <param name="customer">id is generated upon creation, leave it at 0</param>
 public void CreateNewCustomer(LoginToken <Administrator> token, Customer customer)
 {
     LoginHelper.CheckToken <Administrator>(token);
     POCOValidator.CustomerValidator(customer, false);
     if (_airlineDAO.GetAirlineByUsername(customer.UserName) != null || _customerDAO.GetCustomerByUsername(customer.UserName) != null || customer.UserName == "admin")
     {
         throw new UsernameAlreadyExistsException($"Failed to create customer! Username '{customer.UserName}' is already taken!");
     }
     _customerDAO.Add(customer);
 }
 public void RemoveAirline(LoginToken <Administrator> token, AirlineCompany airline)
 {
     LoginHelper.CheckToken <Administrator>(token);
     POCOValidator.AirlineCompanyValidator(airline, true);
     if (_airlineDAO.Get(airline.ID) == null)
     {
         throw new UserNotFoundException($"failed to remove airline! airline with username [{airline.UserName}] was not found!");
     }
     _airlineDAO.Remove(airline);
 }
Example #20
0
 /// <summary>
 /// updates a customer using the template design pattern
 /// </summary>
 /// <param name="token"></param>
 /// <param name="customer">updates the customer with this parameter's ID</param>
 public void UpdateCustomerDetailsUsingTemplateDP(LoginToken <Administrator> token, Customer customer)
 {
     LoginHelper.CheckToken <Administrator>(token);
     POCOValidator.CustomerValidator(customer, true);
     if (_customerDAO.Get(customer.ID) == null)
     {
         throw new UserNotFoundException($"Failed to update customer! Customer with username [{customer.UserName}] was not found!");
     }
     //_customerDAO.Update(customer);
     new QueryUpdate(this.testMode).Run <Customer>(customer); //apparently i don't need the <Customer>
 }
        /// <summary>
        /// removes an airline company
        /// </summary>
        /// <param name="token"></param>
        /// <param name="airline">removes an airline company that has this parameter's ID</param>
        public void RemoveAirline(LoginToken <Administrator> token, AirlineCompany airline)
        {
            LoginHelper.CheckToken <Administrator>(token);
            POCOValidator.AirlineCompanyValidator(airline, true);
            if (_airlineDAO.Get(airline.ID) == null)
            {
                throw new UserNotFoundException($"failed to remove airline! airline with username [{airline.UserName}] was not found!");
            }
            IList <Flight> flights = _flightDAO.GetFlightsByAirlineCompanyId(airline);

            flights.ToList().ForEach(f => _ticketDAO.RemoveTicketsByFlight(f));
            flights.ToList().ForEach(f => _flightDAO.Remove(f)); //i think it's ok?
            _airlineDAO.Remove(airline);
        }
 /// <summary>
 /// updates an airline company
 /// </summary>
 /// <param name="token"></param>
 /// <param name="airline">updates the airline company with this parameter's ID</param>
 public void UpdateAirlineDetails(LoginToken <Administrator> token, AirlineCompany airline)
 {
     LoginHelper.CheckToken <Administrator>(token);
     POCOValidator.AirlineCompanyValidator(airline, true);
     if (_airlineDAO.Get(airline.ID) == null)
     {
         throw new UserNotFoundException($"failed to update airline! airline with username [{airline.UserName}] was not found!");
     }
     if (_countryDAO.Get(airline.CountryCode) == null)
     {
         throw new CountryNotFoundException($"failed to update airline! there is no country with id [{airline.CountryCode}]");
     }
     _airlineDAO.Update(airline);
 }
Example #23
0
        /// <summary>
        /// temporary, supposed to be in admin facade with auth (actually exists there already) (?)
        /// </summary>
        /// <param name="customer"></param>
        public void RemoveCustomer(Customer customer)
        {
            POCOValidator.CustomerValidator(customer, true);
            if (_customerDAO.Get(customer.ID) == null)
            {
                throw new UserNotFoundException($"Failed to remove customer! Customer with username [{customer.UserName}] was not found!");
            }
            IList <Flight> flights = _flightDAO.GetFlightsByCustomer(customer);

            flights.ToList().ForEach(f => f.RemainingTickets++);
            flights.ToList().ForEach(f => _flightDAO.Update(f));
            _ticketDAO.RemoveTicketsByCustomer(customer);
            _customerDAO.Remove(customer);
        }
        public void RemoveCustomer(LoginToken <Administrator> token, Customer customer)
        {
            LoginHelper.CheckToken <Administrator>(token);
            POCOValidator.CustomerValidator(customer, true);
            if (_customerDAO.Get(customer.ID) == null) //doesn't mean the customer in the parameter has the same values as the customer in the database with the same id
            {
                throw new UserNotFoundException($"failed to remove customer! customer with username [{customer.UserName}] was not found!");
            }
            IList <Flight> flights = _flightDAO.GetFlightsByCustomer(customer);

            flights.ToList().ForEach(f => f.RemainingTickets++); //is this how i should do it?
            flights.ToList().ForEach(f => _flightDAO.Update(f)); // feels like it's super inefficient
            _ticketDAO.RemoveTicketsByCustomer(customer);
            _customerDAO.Remove(customer);
        }
        /// <summary>
        /// removes a customer
        /// </summary>
        /// <param name="token"></param>
        /// <param name="customer">removes a customer that has this parameter's ID</param>
        public void RemoveCustomer(LoginToken <Administrator> token, Customer customer)
        {
            LoginHelper.CheckToken <Administrator>(token);
            POCOValidator.CustomerValidator(customer, true);
            if (_customerDAO.Get(customer.ID) == null)
            {
                throw new UserNotFoundException($"failed to remove customer! customer with username [{customer.UserName}] was not found!");
            }
            IList <Flight> flights = _flightDAO.GetFlightsByCustomer(customer);

            flights.ToList().ForEach(f => f.RemainingTickets++);
            flights.ToList().ForEach(f => _flightDAO.Update(f)); //i think it's ok
            _ticketDAO.RemoveTicketsByCustomer(customer);
            _customerDAO.Remove(customer);
        }
 public void CreateNewAirline(AirlineCompany airline)
 {
     POCOValidator.AirlineCompanyValidator(airline, false);
     if (_airlineDAO.GetAirlineByAirlineName(airline.AirlineName) != null)
     {
         throw new AirlineNameAlreadyExistsException($"failed to create airline! there is already an airline with the name '{airline.AirlineName}'");
     }
     if (_airlineDAO.GetAirlineByUsername(airline.UserName) != null || _customerDAO.GetCustomerByUsername(airline.UserName) != null || airline.UserName == "admin")
     {
         throw new UsernameAlreadyExistsException($"failed to create airline! Username '{airline.UserName}' is already taken!");
     }
     if (_countryDAO.Get(airline.CountryCode) == null)
     {
         throw new CountryNotFoundException($"failed to create airline! there is no country with id [{airline.CountryCode}]");
     }
     _airlineDAO.Add(airline);
 }
Example #27
0
 /// <summary>
 /// updates a customer
 /// </summary>
 /// <param name="token"></param>
 /// <param name="customer">updates the customer with this parameter's ID</param>
 public void UpdateCustomerDetails(LoginToken <Administrator> token, Customer customer)
 {
     LoginHelper.CheckToken <Administrator>(token);
     POCOValidator.CustomerValidator(customer, true);
     if (_customerDAO.Get(customer.ID) == null)
     {
         throw new UserNotFoundException($"Failed to update customer! Customer with ID [{customer.ID}] was not found!");
     }
     if (_customerDAO.GetCustomerByUsername(customer.UserName) != null)
     {
         if (_customerDAO.Get(customer.ID).UserName != customer.UserName) //i think i did this right?
         {
             throw new UsernameAlreadyExistsException($"Failed to modify details! Username [{customer.UserName}] is already taken!");
         }
     }
     _customerDAO.Update(customer);
 }
 /// <summary>
 /// can change all the customer's details except ID
 /// </summary>
 /// <param name="token"></param>
 /// <param name="customer"></param>
 public void ModifyCustomerDetails(LoginToken <Customer> token, Customer customer)
 {
     LoginHelper.CheckToken <Customer>(token);
     POCOValidator.CustomerValidator(customer, true);
     if (customer.ID != token.User.ID)
     {
         throw new InaccessibleCustomerException($"Failed to modify details! This is not your account!"); //will it ever happen? who knows...
     }
     if (_customerDAO.GetCustomerByUsername(customer.UserName) != null)
     {
         if (_customerDAO.GetCustomerByUsername(customer.UserName) != token.User)
         {
             throw new UsernameAlreadyExistsException($"Failed to modify details! Username [{customer.UserName}] is already taken!");
         }
     }
     _customerDAO.Update(customer);
 }
Example #29
0
        /// <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);
            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}]");
            }
            Flight updatedFlight = _flightDAO.Get(ticket.FlightId);

            updatedFlight.RemainingTickets++;
            _flightDAO.Update(updatedFlight);
            _ticketDAO.Remove(ticket);
        }
 public void CreateFlight(Flight flight)
 {
     POCOValidator.FlightValidator(flight, false);
     if (DateTime.Compare(flight.DepartureTime, flight.LandingTime) > 0)
     {
         throw new InvalidFlightDateException($"failed to create 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 create 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 create flight [{flight}], origin country with id [{flight.OriginCountryCode}] was not found!");
     }
     if (_countryDAO.Get(flight.DestinationCountryCode) == null)
     {
         throw new CountryNotFoundException($"failed to create flight [{flight}], destination country with id [{flight.DestinationCountryCode}] was not found!");
     }
     _flightDAO.Add(flight);
 }