public void AddItem(Restaurants newRestaurant) { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"INSERT INTO cuisine_restaurants (cuisine_id, restaurant_id) VALUES (@CusineId, @RestaurantId);"; MySqlParameter cuisine_id = new MySqlParameter(); cuisine_id.ParameterName = "@CategoryId"; cuisine_id.Value = id; cmd.Parameters.Add(cuisine_id); MySqlParameter restaurant_id = new MySqlParameter(); restaurant_id.ParameterName = "@ItemId"; restaurant_id.Value = newRestaurant.Id; cmd.Parameters.Add(restaurant_id); cmd.ExecuteNonQuery(); conn.Close(); if (conn != null) { conn.Dispose(); } }
public static List <Restaurants> GetAll() { List <Restaurants> allItems = new List <Restaurants> { }; MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM Restaurants;"; MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; while (rdr.Read()) { int newId = rdr.GetInt32(0); string newName = rdr.GetString(1); Restaurants newItem = new Restaurants(newName, newId); allItems.Add(newItem); } conn.Close(); if (conn != null) { conn.Dispose(); } return(allItems); }
public List <Restaurants> GetRestaurant() { MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT restaurant_id FROM cuisine_restaurants WHERE cuisine_id = @CuisineId;"; MySqlParameter cuisineIdParameter = new MySqlParameter(); cuisineIdParameter.ParameterName = "@CuisineId"; cuisineIdParameter.Value = id; cmd.Parameters.Add(cuisineIdParameter); MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; List <Restaurants> restaurants = new List <Restaurants> { }; while (rdr.Read()) { int restaurant_Id = rdr.GetInt32(2); Restaurants newRestaurant = Restaurants.Find(restaurant_Id); restaurants.Add(newRestaurant); } conn.Close(); if (conn != null) { conn.Dispose(); } return(restaurants); }
public static void GetCuisineJoin() { MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM Restaurants JOIN cuisine_restaurants ON (Restaurants.id = cuisine_restaurants.restaurant_id) JOIN Cuisine ON (cuisine_restaurants.cuisine_id = Cuisine.id);"; MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; //List<ViewModel> modelList = new List<ViewModel> { }; while (rdr.Read()) { string restaurantName = rdr.GetString(1); int restaurantId = rdr.GetInt32(4); string cuisineName = rdr.GetString(6); int cuisineId = rdr.GetInt32(3); Restaurants newRestaurant = new Restaurants(restaurantName, restaurantId); Cuisine newCuisine = new Cuisine(cuisineName, cuisineId); ViewModel newList = new ViewModel(newRestaurant, newCuisine); } conn.Close(); if (conn != null) { conn.Dispose(); } //return modelList; }
public override bool Equals(System.Object otherItem) { if (!(otherItem is Restaurants)) { return(false); } else { Restaurants newItem = (Restaurants)otherItem; bool idEquality = (this.Id == newItem.Id); bool nameEquality = (this.Name == newItem.Name); return(idEquality && nameEquality); } }
public static List <ViewModel> SearchByCuisine(int Id) { MySqlConnection conn = DB.Connection(); conn.Open(); MySqlCommand cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM Restaurants JOIN cuisine_restaurants ON (Restaurants.id = cuisine_restaurants.restaurant_id) JOIN Cuisine ON (cuisine_restaurants.cuisine_id = Cuisine.id) WHERE Cuisine.id = @Id;"; MySqlParameter thisId = new MySqlParameter(); thisId.ParameterName = "@Id"; thisId.Value = Id; cmd.Parameters.Add(thisId); MySqlDataReader rdr = cmd.ExecuteReader() as MySqlDataReader; List <ViewModel> modelList = new List <ViewModel> { }; while (rdr.Read()) { string restaurantName = rdr.GetString(1); int restaurantId = rdr.GetInt32(4); string cuisineName = rdr.GetString(6); int cuisineId = rdr.GetInt32(3); Restaurants newRestaurant = new Restaurants(restaurantName, restaurantId); Cuisine newCuisine = new Cuisine(cuisineName, cuisineId); ViewModel newList = new ViewModel(newRestaurant, newCuisine); modelList.Add(newList); } conn.Close(); if (conn != null) { conn.Dispose(); } return(modelList); }
public static Restaurants Find(int id) { MySqlConnection conn = DB.Connection(); conn.Open(); var cmd = conn.CreateCommand() as MySqlCommand; cmd.CommandText = @"SELECT * FROM `Restaurants` WHERE id = @thisId;"; MySqlParameter thisId = new MySqlParameter(); thisId.ParameterName = "@thisId"; thisId.Value = id; cmd.Parameters.Add(thisId); var rdr = cmd.ExecuteReader() as MySqlDataReader; int newId = 0; string newName = ""; while (rdr.Read()) { newId = rdr.GetInt32(0); newName = rdr.GetString(1); } Restaurants foundItem = new Restaurants(newName, newId); conn.Close(); if (conn != null) { conn.Dispose(); } return(foundItem); }
public static List <ViewModel> GetCuisines(int id) { Restaurants.SearchByCuisine(id); return(list); }
public static List <ViewModel> GetObjects() { Restaurants.GetCuisineJoin(); return(list); }
public ViewModel(Restaurants restaurant, Cuisine cuisine) { this.restaurant = restaurant; this.cuisine = cuisine; list.Add(this); }