Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tripId"></param>
        /// <returns></returns>
        public static Trip GetTrip(int tripId)
        {
            Trip trip = null;

            DBUtility.HandleConnection((MySqlCommand command) =>
            {
                command.CommandText = "SELECT * FROM trips WHERE id = @id;";
                command.Parameters.AddWithValue("@id", tripId);

                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        trip = new Trip()
                        {
                            TripId       = reader.GetInt32("id"),
                            DepatureTime = reader.GetDateTime("departure_time"),
                            Ferry        = FerryHandler.GetFerry(reader.GetInt32("ferry_id")),
                            Route        = RouteHandler.GetRoute(reader.GetInt32("route_id")),
                            TripPrice    = reader.GetDouble("price") // Possible loss of precision, use decimal instead
                        };
                    }
                }
            });

            return(trip);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static List <Trip> GetAllTrips()
        {
            List <Trip> trips = new List <Trip>();

            DBUtility.HandleConnection((MySqlCommand command) =>
            {
                command.CommandText = "SELECT * FROM trips;";

                using (MySqlDataReader reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        trips.Add(new Trip()
                        {
                            TripId       = reader.GetInt32("id"),
                            DepatureTime = reader.GetDateTime("departure_time"),
                            Ferry        = FerryHandler.GetFerry(reader.GetInt32("ferry_id")),
                            Route        = RouteHandler.GetRoute(reader.GetInt32("route_id")),
                            TripPrice    = reader.GetDouble("price") // Possible loss of precision, use decimal instead
                        });
                    }
                }
            });

            return(trips);
        }
Esempio n. 3
0
 public Route GetRoute(int routeId)
 {
     return(RouteHandler.GetRoute(routeId));
 }