Exemplo n.º 1
0
        public List <Trip> TripsFromInput(string inputPrice, string inputDepartureDate, string inputReturnDate, string inputHeight)
        {
            List <Trip> trips = new List <Trip>();

            bool isDeparture = false;
            int  departure   = 0;
            int  returning   = 0;
            int  price       = 0;
            int  both        = 0;
            int  height      = 0;

            if (inputPrice != "")
            {
                price = Int32.Parse(inputPrice);
            }
            if (inputHeight != "")
            {
                height = Int32.Parse(inputHeight);
            }
            DateTime departDate = DateAndTime.GetPastDate();

            if (inputDepartureDate != "" && inputReturnDate == "")
            {
                departDate  = DateTime.Parse(inputDepartureDate);
                isDeparture = true;
                departure++;
            }
            DateTime returnDate = DateAndTime.GetFutureDate();

            if (inputReturnDate != "" && inputDepartureDate != "")
            {
                returnDate = DateTime.Parse(inputReturnDate);
                departDate = DateTime.Parse(inputDepartureDate);
                both++;
            }
            if (inputDepartureDate == "" && inputReturnDate != "")
            {
                returnDate  = DateTime.Parse(inputReturnDate);
                isDeparture = false;
                returning++;
            }
            TripSqlDal tripSqlDal = new TripSqlDal(connectionString);

            if ((departure == 0 && returning == 0) || both > 0)
            {
                trips = tripSqlDal.GetTripsFromInput(height, departDate, returnDate, price);
            }
            if (departure > 0)
            {
                trips = tripSqlDal.GetTripsFromInputDepart(height, departDate, price);
            }
            if (returning > 0)
            {
                trips = tripSqlDal.GetTripsFromInputReturn(height, returnDate, price);
            }


            return(trips);
        }
Exemplo n.º 2
0
 public DateTime ReturnDateTime(string returnDate)
 {
     if (returnDate == "")
     {
         return(DateAndTime.GetFutureDate());
     }
     return(DateTime.Parse(returnDate));
 }
Exemplo n.º 3
0
        //trips with default input values (5 ft surf height and 500 max price)
        public List <Trip> GetTripsDefault()
        {
            List <Trip> trips = new List <Trip>();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand(SQL_GetTripsDefault, conn);

                    cmd.Parameters.AddWithValue("@inputMinSurfHeight", 500);
                    cmd.Parameters.AddWithValue("@inputMaxPrice", 5);
                    SqlDataReader reader = cmd.ExecuteReader();



                    while (reader.Read())
                    {
                        Trip t = new Trip();
                        t.InputDepartureDate = DateAndTime.GetPastDate();
                        t.InputMaxPrice      = 500;
                        t.InputMinSurfHeight = 5;
                        t.InputReturnDate    = DateAndTime.GetFutureDate();
                        t.DepartureDate      = Convert.ToDateTime(reader["departure_date"]).Date;
                        t.Latitude           = Convert.ToString(reader["latitude"]);
                        t.LocationName       = Convert.ToString(reader["name"]);
                        t.Longitude          = Convert.ToString(reader["longitude"]);
                        t.MaxSurfHeight      = Convert.ToDecimal(reader["max_height"]);
                        t.NumberOfSurfDays   = Convert.ToInt32(reader["num_of_days_with_surf"]);
                        t.Price                  = Convert.ToDecimal(reader["min_flight_price"]);
                        t.ReturnDate             = Convert.ToDateTime(reader["return_date"]).Date;
                        t.SpotName               = Convert.ToString(reader["spot_name"]);
                        t.SpotId                 = Convert.ToInt32(reader["spot_id"]);
                        t.FlightId               = Convert.ToInt32(reader["flight_id"]);
                        t.OriginAirportCode      = Convert.ToString(reader["origin_airport_code"]);
                        t.DestinationAirportCode = Convert.ToString(reader["airport_code"]);

                        trips.Add(t);
                    }
                }
            }
            catch (SqlException)
            {
                throw;
            }

            return(trips);
        }
Exemplo n.º 4
0
        //no set return date or
        //no set departure date
        public List <Trip> GetTripsFromInputDepart(int minSurfHeight, DateTime date, int maxPrice)
        {
            List <Trip> trips = new List <Trip>();

            //if no maxPrice is set (minSurfHeight will automatically be set to 0
            if (maxPrice == 0)
            {
                maxPrice = 99999;
            }

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();


                    SqlCommand cmd = new SqlCommand(SQL_GetTripsFromInputDepart, conn);



                    cmd.Parameters.AddWithValue("@inputDepartureDate", date);
                    cmd.Parameters.AddWithValue("@inputReturnDate", DateAndTime.GetFutureDate());


                    cmd.Parameters.AddWithValue("@inputMinSurfHeight", minSurfHeight);
                    cmd.Parameters.AddWithValue("@inputMaxPrice", maxPrice);

                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Trip t = new Trip();
                        t.DepartureDate      = date;
                        t.InputDepartureDate = date;
                        t.InputMaxPrice      = maxPrice;
                        t.InputMinSurfHeight = minSurfHeight;
                        t.Latitude           = Convert.ToString(reader["latitude"]);
                        t.Longitude          = Convert.ToString(reader["longitude"]);
                        t.MaxSurfHeight      = Convert.ToDecimal(reader["max_height"]);
                        t.NumberOfSurfDays   = Convert.ToInt32(reader["num_of_days_with_surf"]);
                        t.Price                  = Convert.ToDecimal(reader["min_flight_price"]);
                        t.SpotName               = Convert.ToString(reader["spot_name"]);
                        t.ReturnDate             = Convert.ToDateTime(reader["return_date"]).Date;
                        t.LocationName           = Convert.ToString(reader["name"]);
                        t.SpotId                 = Convert.ToInt32(reader["spot_id"]);
                        t.FlightId               = Convert.ToInt32(reader["flight_id"]);
                        t.OriginAirportCode      = Convert.ToString(reader["origin_airport_code"]);
                        t.DestinationAirportCode = Convert.ToString(reader["airport_code"]);

                        trips.Add(t);
                    }
                }
            }
            catch (SqlException)
            {
                throw;
            }

            return(trips);
        }