예제 #1
0
        //Adds tickets to history and removes them from regular, MUST happen after flights had been moved.
        public void MoveTicketsToHistory()
        {
            FlightDAOMSSQL flightDAO     = new FlightDAOMSSQL();
            List <Flight>  flightHistory = flightDAO.GetFlightHistory();

            List <Ticket> ticketsToMove = new List <Ticket>();

            //saves the tickets to move
            for (int i = 0; i < flightHistory.Count; i++)
            {
                List <Ticket> ticketsByFlight = GetTicketsByFlight(flightHistory[i]);
                for (int j = 0; j < ticketsByFlight.Count; j++)
                {
                    ticketsToMove.Add(ticketsByFlight[i]);
                }
            }

            using (Connection = new SqlConnection(_connectionString))
            {
                Connection.Open();

                using (SqlCommand command = new SqlCommand("MOVE_TICKET_TO_HISTORY", Connection))
                {
                    for (int i = 0; i < ticketsToMove.Count; i++)
                    {
                        command.Parameters.Add(new SqlParameter("ticket_id", ticketsToMove[i].ID));
                        command.CommandType = CommandType.StoredProcedure;

                        SqlDataReader reader = command.ExecuteReader();
                    }
                }
            }
        }
예제 #2
0
        public void Update(Ticket toUpdate)
        {
            CustomerDAOMSSQL customerDAO = new CustomerDAOMSSQL();
            FlightDAOMSSQL   flightDAO   = new FlightDAOMSSQL();

            if (toUpdate is null)
            {
                throw new NullReferenceException("Ticket providen does not exist or empty.");
            }
            if (toUpdate.ID <= 0)
            {
                throw new IllegalValueException("The ticket ID of the providen ticket is not valid.");
            }
            if (CheckTicketUniqueFieldsExistance(toUpdate))
            {
                throw new AlreadyExistsException("There is already a ticket for this flight and customer.");
            }
            if (toUpdate.CustomerID <= 0)
            {
                throw new IllegalValueException("Customer ID in the providen ticket is not valid.");
            }
            if (toUpdate.FlightID <= 0)
            {
                throw new IllegalValueException("Flight ID in the providen ticket is not valid.");
            }
            if (Get(toUpdate.ID) == null)
            {
                throw new TicketNotFoundException("Ticket does not exist");
            }
            if (customerDAO.Get(toUpdate.CustomerID) is null)
            {
                throw new CustomerNotFoundException("The customer could not be found.");
            }
            if (flightDAO.Get(toUpdate.FlightID) is null)
            {
                throw new FlightNotFoundException("Flight could not be found.");
            }

            using (Connection = new SqlConnection(_connectionString))
            {
                Connection.Open();
                using (SqlCommand command = new SqlCommand("UPDATE_TICKET", Connection))
                {
                    command.Parameters.Add(new SqlParameter("ticket_id", toUpdate.ID));
                    command.Parameters.Add(new SqlParameter("flight_id", toUpdate.FlightID));
                    command.Parameters.Add(new SqlParameter("customer_id", toUpdate.CustomerID));
                    command.CommandType = CommandType.StoredProcedure;

                    SqlDataReader reader = command.ExecuteReader();
                }
            }
        }//not used