Example #1
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 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 #3
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);
 }
 /// <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 #6
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>
 }
Example #7
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);
        }
        /// <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 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>
 /// 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 #11
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);
 }
        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);
        }