/// <summary>
        ///
        /// </summary>
        /// <param name="reservationId"></param>
        /// <returns></returns>
        public static Reservation ReadReservation(int reservationId)
        {
            Reservation reservation = null;

            DBUtility.HandleConnection((MySqlCommand command) =>
            {
                command.CommandText = "SELECT * FROM reservations WHERE id = @id;";

                command.Parameters.AddWithValue("@id", reservationId);

                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        reservation = new Reservation()
                        {
                            ReservationId  = reader.GetInt32("id"),
                            Customer       = CustomerHandler.GetCustomer(reader.GetInt32("customer_id")), //I made that method, is that okay?
                            NumberOfPeople = reader.GetInt32("number_of_people"),
                            TotalPrice     = reader.GetInt32("total_price"),
                            Trip           = TripHandler.GetTrip(reader.GetInt32("trip_id")),
                            Vehicle        = VehicleHandler.GetVehicle(reader.GetInt32("vehicle_id"))
                        };
                    }
                }
            });

            return(reservation);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="customer"></param>
        /// <returns></returns>
        public static List <Reservation> ReadAllCustomerReservations(Customer customer)
        {
            List <Reservation> reservations = new List <Reservation>();

            DBUtility.HandleConnection((MySqlCommand command) =>
            {
                command.CommandText = "SELECT * FROM reservations WHERE customer_id = @customer_id;";

                command.Parameters.AddWithValue("@customer_id", customer.CustomerId);

                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        reservations.Add(new Reservation()
                        {
                            ReservationId  = reader.GetInt32("id"),
                            Customer       = CustomerHandler.GetCustomer(reader.GetInt32("customer_id")), //I made that method, is that okay?
                            NumberOfPeople = reader.GetInt32("number_of_people"),
                            TotalPrice     = reader.GetInt32("total_price"),
                            Trip           = TripHandler.GetTrip(reader.GetInt32("trip_id")),
                            Vehicle        = VehicleHandler.GetVehicle(reader.GetInt32("vehicle_id"))
                        });
                    }
                }
            });

            return(reservations);
        }
示例#3
0
 public List <Trip> GetAllTrips()
 {
     return(TripHandler.GetAllTrips());
 }
 public bool DeleteTrip(Trip trip)
 {
     return(TripHandler.DeleteTrip(trip));
 }
 public Trip CreateTrip(Trip trip)
 {
     return(TripHandler.CreateTrip(trip));
 }
 public Trip UpdateTrip(Trip trip)
 {
     return(TripHandler.UpdateTrip(trip));
 }
 public Trip GetTrip(int tripId)
 {
     return(TripHandler.GetTrip(tripId));
 }