/// <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); }
/// <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 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); }
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); }
/// <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); }
/// <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); }
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); }