public void ModifyCustomerDetails(LoginToken <Customer> token, Customer customer)
 {
     if (token.CheckToken())
     {
         if (token.User.Password == customer.Password)
         {
             if (token.User.Username == customer.Username)
             {
                 customer = new Customer(token.User.Id, customer.FirstName, customer.LastName, token.User.Username, token.User.Password, customer.Address, customer.PhoneNo, customer.CreditCardNumber);
                 _customerDAO.Update(customer);
                 LoginToken.User = customer;
             }
             else
             {
                 throw new UnauthorizedActionException("Usernames cannot be changed.");
             }
         }
         else
         {
             throw new WrongPasswordException("Incorrect Password.");
         }
     }
 }
Exemplo n.º 2
0
        public IList <Ticket> GetAllTicketsByFlight(LoginToken <AirlineCompany> token, int flightId)
        {
            List <Ticket> tickets = new List <Ticket>();

            if (token.CheckToken())
            {
                if (_flightDAO.DoesFlightExistById(flightId) == 1)
                {
                    if (_flightDAO.Get(flightId).AirlineCompanyId == token.User.Id)
                    {
                        tickets = (List <Ticket>)_ticketDAO.GetAllTicketsByFlight(flightId);
                    }
                    else
                    {
                        throw new UnauthorizedActionException("Cannot see flights of other companies.");
                    }
                }
                else
                {
                    throw new NullReferenceException("Flight not found");
                }
            }
            return(tickets);
        }
Exemplo n.º 3
0
 public void CancelFlight(LoginToken <AirlineCompany> token, int flightId)
 {
     if (token.CheckToken())
     {
         if (_flightDAO.DoesFlightExistById(flightId) == 1)
         {
             Flight flight = _flightDAO.Get(flightId);
             if (flight.AirlineCompanyId != token.User.Id)
             {
                 throw new UnauthorizedActionException("Cannot cancel flights of other companies.");
             }
             List <Ticket> tickets = (List <Ticket>)_ticketDAO.GetAllTicketsByFlight(flightId);
             foreach (Ticket ticket in tickets)
             {
                 _ticketDAO.Remove(ticket);
             }
             _flightDAO.Remove(flight);
         }
         else
         {
             throw new NullReferenceException("Flight not found.");
         }
     }
 }