Пример #1
0
        public static List <Diner> GetAll()
        {
            List <Diner> allDiner = new List <Diner> {
            };
            MySqlConnection conn  = DB.Connection();

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

            cmd.CommandText = @"SELECT * FROM items;";
            var rdr = cmd.ExecuteReader() as MySqlDataReader;

            while (rdr.Read())
            {
                int    DinerId          = rdr.GetInt32(0);
                string DinerName        = rdr.GetString(1);
                string Location         = rdr.GetString(2);
                string Popularity       = rdr.GetString(3);
                string PriceRange       = rdr.GetString(4);
                int    Rating           = rdr.GetInt32(5);
                string DinerDescription = rdr.GetString(6);
                int    Cuisine_Id       = rdr.GetInt32(7);
                Diner  newDiner         = new Diner(DinerName, Location, Popularity, PriceRange, Rating, DinerDescription, Cuisine_Id, DinerId);
                allDiner.Add(newDiner);
            }
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(allDiner);
        }
Пример #2
0
        public static Diner Find(int id)
        {
            MySqlConnection conn = DB.Connection();

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

            cmd.CommandText = @"SELECT * FROM items WHERE id = (@searchId);";

            MySqlParameter searchId = new MySqlParameter();

            searchId.ParameterName = "@searchId";
            searchId.Value         = id;
            cmd.Parameters.Add(searchId);

            var    rdr              = cmd.ExecuteReader() as MySqlDataReader;
            int    DinerId          = 0;
            string DinerName        = "";
            string Location         = "";
            string Popularity       = "";
            string PriceRange       = "";
            int    Rating           = 0;
            string DinerDescription = "";
            int    Cuisine_Id       = 0;

            while (rdr.Read())
            {
                DinerId          = rdr.GetInt32(0);
                DinerName        = rdr.GetString(1);
                Location         = rdr.GetString(2);
                Popularity       = rdr.GetString(3);
                PriceRange       = rdr.GetString(4);
                Rating           = rdr.GetInt32(5);
                DinerDescription = rdr.GetString(6);
                Cuisine_Id       = rdr.GetInt32(7);
            }
            Diner newDiner = new Diner(DinerName, Location, Popularity, PriceRange, Rating, DinerDescription, Cuisine_Id, DinerId);

            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
            return(newDiner);
        }
Пример #3
0
        public override bool Equals(System.Object otherDiner)
        {
            if (!(otherDiner is Diner))
            {
                return(false);
            }
            else
            {
                Diner newDiner = (Diner)otherDiner;

                bool dinerNameEquality   = (this.GetDinerName() == newDiner.GetDinerName());
                bool locationEquality    = (this.GetLocation() == newDiner.GetLocation());
                bool popularityEquality  = (this.GetPopularity() == newDiner.GetPopularity());
                bool priceRangeEquality  = this.GetPriceRange() == newDiner.GetPriceRange();
                bool descriptionEquality = this.GetDescription() == newDiner.GetDescription();
                bool cuisine_IdEquality  = this.GetCuisine_Id() == newDiner.GetCuisine_Id();
                bool idEquality          = (this.GetDinerId() == newDiner.GetDinerId());
                //return (dinerNameEquality);
                return(idEquality && dinerNameEquality && locationEquality && popularityEquality && priceRangeEquality && descriptionEquality && cuisine_IdEquality);
            }
        }