public void UpdateFoodBlog(int foodblogid, FoodBlog new_foodblog) { string query = "update foodblogpages set foodblogtitle='{0}', chefname='{1}', foodblogbody='{2}' where foodblogid={3}"; query = String.Format(query, new_foodblog.GetFoodBlogTitle(), new_foodblog.GetChefName(), new_foodblog.GetFoodBlogBody(), foodblogid); MySqlConnection Connect = new MySqlConnection(ConnectionString); MySqlCommand cmd = new MySqlCommand(query, Connect); try { //Try to update a food blog with the information provided to us. Connect.Open(); cmd.ExecuteNonQuery(); Debug.WriteLine("Executed query " + query); } catch (Exception ex) { Debug.WriteLine("Something went wrong in the UpdateFoodBlog Method!"); Debug.WriteLine(ex.ToString()); } Connect.Close(); }
protected void ShowFoodBlogInfo(FoodDriftersdb db) { bool valid = true; string foodblogid = Request.QueryString["foodblogid"]; if (String.IsNullOrEmpty(foodblogid)) { valid = false; } if (valid) { Debug.WriteLine("show the data"); FoodBlog foodblog_record = db.FindFoodBlog(Int32.Parse(foodblogid)); foodblogtitle.Text = foodblog_record.GetFoodBlogTitle(); chefname.Text = foodblog_record.GetChefName(); foodblogbody.Text = foodblog_record.GetFoodBlogBody(); } if (!valid) { ErrorBox.InnerHtml = "There was an error finding that foodblog."; } }
protected void Add_Recipe(object sender, EventArgs e) { FoodDriftersdb db = new FoodDriftersdb(); //create a new particular FoodBlog FoodBlog new_recipe = new FoodBlog(); //set that FoodBlog data new_recipe.SetFoodBlogTitle(foodblogtitle.Text); new_recipe.SetChefName(chefname.Text); new_recipe.SetFoodBlogBody(foodblogbody.Text); //add the food blog to the database db.AddFoodBlog(new_recipe); Response.Redirect("FoodBlogList.aspx"); }
public void AddFoodBlog(FoodBlog new_recipe) { string query = "insert into foodblogpages (foodblogtitle, chefname, foodblogbody) values ('{0}','{1}','{2}')"; query = String.Format(query, new_recipe.GetFoodBlogTitle(), new_recipe.GetChefName(), new_recipe.GetFoodBlogBody()); MySqlConnection Connect = new MySqlConnection(ConnectionString); MySqlCommand cmd = new MySqlCommand(query, Connect); try { Connect.Open(); cmd.ExecuteNonQuery(); } catch (Exception ex) { Debug.WriteLine("Something went wrong in the AddFoodBlog Method!"); Debug.WriteLine(ex.ToString()); } Connect.Close(); }
protected void Update_FoodBlog(object sender, EventArgs e) { Debug.WriteLine("Please allow me to update"); FoodDriftersdb db = new FoodDriftersdb(); bool valid = true; string foodblogid = Request.QueryString["foodblogid"]; if (String.IsNullOrEmpty(foodblogid)) { valid = false; } if (valid) { FoodBlog new_foodblog = new FoodBlog(); //set that food blog data new_foodblog.SetFoodBlogTitle(foodblogtitle.Text); new_foodblog.SetChefName(chefname.Text); new_foodblog.SetFoodBlogBody(foodblogbody.Text); //add the food blog to the database try { db.UpdateFoodBlog(Int32.Parse(foodblogid), new_foodblog); Response.Redirect("ShowFoodBolg.aspx?foodblogid=" + foodblogid); } catch { valid = false; } } if (!valid) { foodblog.InnerHtml = "There was an error updating that student."; } }
public FoodBlog FindFoodBlog(int id) { MySqlConnection Connect = new MySqlConnection(ConnectionString); FoodBlog result_foodblog = new FoodBlog(); try { string query = "select * from foodblogpages where foodblogid = " + id; Debug.WriteLine("Connection Initialized..."); Connect.Open(); MySqlCommand cmd = new MySqlCommand(query, Connect); MySqlDataReader resultset = cmd.ExecuteReader(); List <FoodBlog> foodblogs = new List <FoodBlog>(); while (resultset.Read()) { FoodBlog currentfoodblog = new FoodBlog(); for (int i = 0; i < resultset.FieldCount; i++) { string key = resultset.GetName(i); string value = resultset.GetString(i); Debug.WriteLine("Attempting to transfer " + key + " data of " + value); switch (key) { case "foodblogtitle": currentfoodblog.SetFoodBlogTitle(value); break; case "chefname": currentfoodblog.SetChefName(value); break; case "foodblogbody": currentfoodblog.SetFoodBlogBody(value); break; } } foodblogs.Add(currentfoodblog); } result_foodblog = foodblogs[0]; } catch (Exception ex) { Debug.WriteLine("Something went wrong in the find Student method!"); Debug.WriteLine(ex.ToString()); } Connect.Close(); Debug.WriteLine("Database Connection Terminated."); return(result_foodblog); }