コード例 #1
0
 public override bool Equals(System.Object otherFavorite)
 {
     if (!(otherFavorite is Favorite))
     {
         return(false);
     }
     else
     {
         Favorite newFavorite       = (Favorite)otherFavorite;
         bool     idEquality        = (this.GetId() == newFavorite.GetId());
         bool     nameEquality      = (this.GetName() == newFavorite.GetName());
         bool     addressEquality   = this.GetAddress() == newFavorite.GetAddress();
         bool     latitudeEquality  = (this.GetLatitude() == newFavorite.GetLatitude());
         bool     longitudeEquality = (this.GetLongitude() == newFavorite.GetLongitude());
         bool     costEquality      = (this.GetCostForTwo() == newFavorite.GetCostForTwo());
         bool     cusineEquality    = (this.GetFavCusine() == newFavorite.GetFavCusine());
         bool     menuUrlEquality   = (this.GetMenuUrl() == newFavorite.GetMenuUrl());
         bool     pageUrlEquality   = (this.GetPageUrl() == newFavorite.GetPageUrl());
         return(idEquality && nameEquality && addressEquality && latitudeEquality && longitudeEquality && costEquality && cusineEquality && menuUrlEquality && pageUrlEquality);
     }
 }
コード例 #2
0
        public void AddFavoriteToUser(Favorite newFavorite)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();

            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"INSERT INTO users_favorites (user_id, restaurant_id) VALUES (@UserId, @FavoriteId);";
            MySqlParameter user_id = new MySqlParameter();

            cmd.Parameters.AddWithValue("@UserId", _id);
            MySqlParameter favorite_id = new MySqlParameter();

            cmd.Parameters.AddWithValue("@FavoriteId", newFavorite.GetId());
            cmd.ExecuteNonQuery();

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
コード例 #3
0
        public List <Favorite> AllRestaurantSortList()
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            MySqlCommand cmd = conn.CreateCommand() as MySqlCommand;

            //user location set to Epicodus for demo purposes - (long -122.677, lat 45.521)

            //   cmd.CommandText = @"SELECT * FROM restaurant_data WHERE (ST_DISTANCE_SPHERE(POINT(restaurant_location_longitude, restaurant_location_latitude), POINT(-122.677, 45.521)) * .000621371) < @selectDistance AND restaurant_average_cost_for_two <= @selectCost;";
            //Above Query does not work with epicodus computers; needs phpMyAdmin 5.7

            //Below is Haversine formula for computing the distance output between 2 ssts of lat and long
            cmd.CommandText = @"SELECT * FROM restaurant_data WHERE ( 3959 * acos( cos( radians( 45.521 ) ) * cos( radians( restaurant_location_latitude ) ) * cos( radians( restaurant_location_longitude ) - radians( -122.677 ) ) + sin( radians( 45.521 ) ) * sin( radians( restaurant_location_latitude ) ) ) ) < @selectDistance AND restaurant_average_cost_for_two <= @selectCost;";

            MySqlParameter userSelectDist = new MySqlParameter();

            cmd.Parameters.AddWithValue("@selectDistance", this._distance);
            MySqlParameter userSelectCost = new MySqlParameter();

            cmd.Parameters.AddWithValue("@selectCost", this._price);

            MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader;

            List <Favorite> RestFromAllRestWithinUserRange = new List <Favorite> {
            };
            string restaurantName    = "";
            string restaurantAddress = "";
            string menuUrl           = "";
            string pageUrl           = "";
            double regLat            = 0;
            double regLong           = 0;
            int    cost    = 0;
            string cuisine = "";

            while (rdr.Read())
            {
                restaurantName    = rdr.GetString(1);
                restaurantAddress = rdr.GetString(2);
                regLat            = rdr.GetDouble(3);
                regLong           = rdr.GetDouble(4);
                cost    = rdr.GetInt32(5);
                pageUrl = rdr.GetString(6);
                menuUrl = rdr.GetString(7);
                cuisine = rdr.GetString(10);

                Favorite selectedRestaurant = new Favorite(restaurantName, restaurantAddress, menuUrl, pageUrl, regLat, regLong, cost, cuisine);
                RestFromAllRestWithinUserRange.Add(selectedRestaurant);
            }

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }

            //   //logic to roll dice to get a random restaurant from selected restaurants based on distance and price
            //   // int selectedRestListIndex = RestFromAllRestWithinUserRange.Count;
            //   // int result;
            //   // Random rnd = new Random();
            //   // result = rnd.Next(0, selectedRestListIndex);
            //   // return RestFromAllRestWithinUserRange(result);
            //
            return(RestFromAllRestWithinUserRange);
        }