/// <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 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); }
/// <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 }
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> /// 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); }
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 }
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); }
/// <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> /// 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 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); }
/// <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); }
public void CreateTicket(Customer customer, Flight flight) { POCOValidator.CustomerValidator(customer, false); 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(customer); if (tickets.Any(item => item.FlightId == flight.ID)) //boolean { throw new TicketAlreadyExistsException($"failed to purchase ticket, you already purchased a ticket to flight [{flight}]"); //must be before checking if all seats are taken } 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, customer.ID); _ticketDAO.Add(newTicket); flight.RemainingTickets--; _flightDAO.Update(flight); }