예제 #1
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);
        }
        /// <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);
            Flight flight = _flightDAO.Get(ticket.FlightId);

            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}]");
            }
            if (flight.DepartureTime < DateTime.Now)
            {
                throw new FlightAlreadyTookOffException($"Failed to cancel ticket! Flight [{flight.ID}] already took off!");
            }
            Flight updatedFlight = _flightDAO.Get(ticket.FlightId);

            updatedFlight.RemainingTickets++;
            _flightDAO.Update(updatedFlight);
            _ticketDAO.Remove(ticket);
        }