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"); }
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); }