//Button to Commit changes made - Function checks Fields entered protected void submit_userchanges_Click(object sender, EventArgs e) { UserServicesSoapClient ws = new UserServicesSoapClient(); string username = Request.Cookies["User"].Value; int userID = ws.getUserID(username); if (edit_email_textBox.Text != "") { ws.updateEmail(userID, edit_email_textBox.Text); Response.Redirect("myProfile.aspx"); } if (edit_username_textbox.Text != "") { ws.updateUsername(userID, edit_username_textbox.Text); Response.Cookies["userId"].Value = null; Response.Cookies["User"].Value = null; Response.Cookies["LoggedIn"].Value = "false"; Response.Redirect("Login.aspx"); } if (edit_firstname_textbox.Text != "") { ws.updateFirstname(userID, edit_firstname_textbox.Text); Response.Redirect("myProfile.aspx"); } }
//Submitting new Security info protected void submit_security_Settings_Click(object sender, EventArgs e) { string security_question = security_questions_dropdown.SelectedValue; int userId = Int32.Parse(Request.Cookies["userId"].Value); if (change_security_answer_texbox.Text != "") { UserServicesSoapClient ws = new UserServicesSoapClient(); if (ws.changeSecurityInfo(security_question, change_security_answer_texbox.Text, userId) == true) { change_security_info_result.Text = "Security info changed."; change_security_info_result.Visible = true; } else { change_security_info_result.Text = "Failed to change Security Information"; change_security_info_result.Visible = true; } } else { change_security_info_result.Text = "Security Answer is manditory."; change_security_info_result.Visible = true; } }
// Login on user uplon click Logon button protected void login_button_click(object sender, EventArgs e) { if (Request.Cookies["LoggedIn"] != null && Request.Cookies["LoggedIn"].Value == "true") { Request.Cookies["LoggedIn"].Value = "false"; } UserServicesSoapClient login_ws = new UserServicesSoapClient(); if (login_ws.userLogin(username_textbox.Text, password_textbox.Text) == false) { login_label.Visible = true; } //USer logged in successfully else { HttpCookie loggedInCookie = new HttpCookie("LoggedIn", "true"); Response.Cookies.Add(loggedInCookie); HttpCookie userCookie = new HttpCookie("User", username_textbox.Text); Response.Cookies.Add(userCookie); string username = username_textbox.Text; int userId = login_ws.getUserID(username); HttpCookie userIdCookie = new HttpCookie("userId", userId.ToString()); Response.Cookies.Add(userIdCookie); Response.Redirect("MyRecipes.aspx"); } }
//Edit Recipe Method protected void edit_method_button_Click(object sender, EventArgs e) { if (recipe_edit_textbox.Text != "") { UserServicesSoapClient ws = new UserServicesSoapClient(); ws.updateRecipeMethod(int.Parse(recipe_edit_textbox.Text), edit_recipe_method_textbox.Text); Response.Redirect("myRecipes.aspx"); } }
//Submit new password, validating current password and making sure all fields // are entered. Editing current password when conditions are met. protected void submit_password_button_Click(object sender, EventArgs e) { empty_confirm_password_label.Visible = false; empty_newpassword_label.Visible = false; empty_password_label.Visible = false; int userID = Int32.Parse(Request.Cookies["userId"].Value); UserServicesSoapClient ws = new UserServicesSoapClient(); string retrieved_password = ws.retrievePassword(userID); if (current_password_textbox.Text != "" && new_password_textbox.Text != "" && Confirm_new_password_textbox.Text != "") { if (current_password_textbox.Text == retrieved_password) { if (new_password_textbox.Text == Confirm_new_password_textbox.Text) { ws.updatePassword(userID, Confirm_new_password_textbox.Text); empty_confirm_password_label.Visible = true; empty_confirm_password_label.Text = "Passwords changed"; Response.Cookies["userId"].Value = null; Response.Cookies["User"].Value = null; Response.Cookies["LoggedIn"].Value = "false"; Response.Redirect("Login.aspx"); } //Passwords do not match else { empty_confirm_password_label.Visible = true; empty_confirm_password_label.Text = "Passwords must Match"; empty_newpassword_label.Text = "Passwords must Match"; } } //Incorrect current password else { empty_password_label.Visible = true; empty_confirm_password_label.Visible = false; empty_newpassword_label.Visible = false; empty_password_label.Text = "Incorrect Current password"; } } //If any fields are left empty else { empty_newpassword_label.Text = "Please fill in all Fields"; empty_newpassword_label.Visible = true; } }
protected void recipes_listbox_SelectedIndexChanged(object sender, EventArgs e) { star_1.Visible = false; star_2.Visible = false; star_3.Visible = false; star_4.Visible = false; star_5.Visible = false; UserServicesSoapClient ws = new UserServicesSoapClient(); ArrayList recipe = new ArrayList(); foreach (object i in ws.get_recipe(recipes_listbox.SelectedValue)) { recipe.Add(i); } ingredientsTextArea.Text = recipe[2].ToString(); methodTextArea.Text = recipe[1].ToString(); decimal recipe_rating = (decimal)recipe[3]; recipe_owner_label_2.Text = recipe[4].ToString(); if (recipe_rating > 0M && recipe_rating < 0.2M) { star_1.Visible = true; } if (recipe_rating >= 0.2M && recipe_rating < 0.4M) { star_1.Visible = true; star_2.Visible = true; } if (recipe_rating >= 0.4M && recipe_rating < 0.6M) { star_1.Visible = true; star_2.Visible = true; star_3.Visible = true; } if (recipe_rating >= 0.6M && recipe_rating < 0.8M) { star_1.Visible = true; star_2.Visible = true; star_3.Visible = true; star_4.Visible = true; } if (recipe_rating >= 0.8M) { star_1.Visible = true; star_2.Visible = true; star_3.Visible = true; star_4.Visible = true; star_5.Visible = true; } }
//Checked if user is logged in protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["LoggedIn"] != null && Request.Cookies["LoggedIn"].Value == "true") { UserServicesSoapClient ws = new UserServicesSoapClient(); string username = Request.Cookies["User"].Value; int userID = ws.getUserID(username); } else { Response.Redirect("Index.aspx"); } }
//Add recipe, validation is done by validation controls protected void add_recipe_button_Click(object sender, EventArgs e) { UserServicesSoapClient ws = new UserServicesSoapClient(); int totalRatings = 0; int rating = 0; decimal avgRating = 0; string username = Request.Cookies["User"].Value; int userID = ws.getUserID(username); Console.WriteLine(userID); byte[] ingredients_bytes = System.Text.Encoding.ASCII.GetBytes(add_recipe_intgredients_textbox.Text); recipeAdded_label.Text = ingredients_bytes.ToString(); byte[] method_bytes = System.Text.Encoding.ASCII.GetBytes(add_recipe_method_textbox.Text); ws.InsertRecipeService(add_recipe_name_textbox.Text, add_recipe_intgredients_textbox.Text, add_recipe_method_textbox.Text, userID, totalRatings, rating, avgRating); recipeAdded_label.Text = "Recpie Added"; }
protected void register_button_click(object sender, EventArgs e) { UserServicesSoapClient ws = new UserServicesSoapClient(); string security_question = security_questions_listbox.SelectedValue; string security_answer = security_question_answer_textbox.Text; if (ws.RegisterUserService(register_username_textbox.Text, register_password_textbox.Text, register_email_textbox.Text, name_textbox.Text, surname_textbox.Text, security_question, security_answer) == false) { register_result_label.Visible = true; } else { Response.Redirect("Index.aspx"); } }
protected void submit_rating_button_Click(object sender, EventArgs e) { int userId = Int32.Parse(Request.Cookies["userId"].Value); UserServicesSoapClient ws = new UserServicesSoapClient(); if (ws.rate_recipe(recipes_listbox.SelectedValue, Int32.Parse(selectRating_dropdown.SelectedValue), userId) == true) { try { //Pass the filepath and filename to the StreamWriter Constructor StreamWriter sw = new StreamWriter("recipeRatingRecord.txt"); //Write a line of text sw.WriteLine($"User Email: {ws.getEmail(userId).ToString()} Recipe: {recipes_listbox.SelectedValue} Rating: {selectRating_dropdown.SelectedValue}"); //Write a second line of text //Close the file sw.Close(); } catch (Exception ee) { Console.WriteLine("Exception: " + ee.Message); } } }