public static List <FavRestaurant> FindByName(string byName) { List <FavRestaurant> foundRestaurants = new List <FavRestaurant> { }; MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM fav_restaurant WHERE name LIKE @Name;"; MySqlParameter searchName = new MySqlParameter(); searchName.ParameterName = "@Name"; searchName.Value = byName + '%'; cmd.Parameters.Add(searchName); MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { int id = rdr.GetInt32(0); string name = rdr.GetString(1); string description = rdr.GetString(2); string location = rdr.GetString(3); string cuisine = rdr.GetString(4); FavRestaurant newRestaurant = new FavRestaurant(name, cuisine, location, description, id); foundRestaurants.Add(newRestaurant); } conn.Close(); if (conn != null) { conn.Dispose(); } return(foundRestaurants); }
public static List <FavRestaurant> GetAll() { List <FavRestaurant> allRestaurants = new List <FavRestaurant> { }; MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM fav_restaurant;"; MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { int id = rdr.GetInt32(0); string name = rdr.GetString(1); string description = rdr.GetString(2); string location = rdr.GetString(3); string cuisine = rdr.GetString(4); FavRestaurant newRestaurant = new FavRestaurant(name, cuisine, location, description, id); allRestaurants.Add(newRestaurant); } conn.Close(); if (conn != null) { conn.Dispose(); } return(allRestaurants); }
public override bool Equals(System.Object otherRestaurant) { if (!(otherRestaurant is FavRestaurant)) { return(false); } else { FavRestaurant newRestaurant = (FavRestaurant)otherRestaurant; bool idEqual = (this.GetId() == newRestaurant.GetId()); bool nameEqual = (this.GetName() == newRestaurant.GetName()); bool descriptionEqual = (this.GetDescription() == newRestaurant.GetDescription()); bool locationEqual = (this.GetLocation() == newRestaurant.GetLocation()); bool cuisineEqual = (this.GetCuisine() == newRestaurant.GetCuisine()); return(idEqual && nameEqual && descriptionEqual && locationEqual && cuisineEqual); } }
public static FavRestaurant FindById(int byId) { int id = 0; string name = ""; string description = ""; string location = ""; string cuisine = ""; MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM fav_restaurant WHERE id = @idPara;"; MySqlParameter paraId = new MySqlParameter(); paraId.ParameterName = "@idPara"; paraId.Value = byId; cmd.Parameters.Add(paraId); MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { id = rdr.GetInt32(0); name = rdr.GetString(1); description = rdr.GetString(2); location = rdr.GetString(3); cuisine = rdr.GetString(4); } FavRestaurant newRestaurant = new FavRestaurant(name, cuisine, location, description, id); conn.Close(); if (conn != null) { conn.Dispose(); } return(newRestaurant); }