// On clicking the submit button of complaint. protected void btnsubmit_Click(object sender, EventArgs e) { Utilities.clearAllPlaceHolders(viewComplaints); using (DatabaseDataContext con = new DatabaseDataContext()) { try { #region checks if (SessionManager.UserID == 0) { showError("You must be logged in to submit a complaint!"); clearAllViews(); return; } string EncodedResponse = Request.Form["g-Recaptcha-Response"]; bool IsCaptchaValid = (ReCaptcha.Validate(EncodedResponse) == "true" ? true : false); if (!IsCaptchaValid) { showError("Prove that you are not a robot!", 0); return; } if (string.IsNullOrEmpty(txtTitle.Text) || string.IsNullOrEmpty(txtdescription.Text)) { showError("Fill in all text boxes!"); return; } #endregion tblComplaint complaint = new tblComplaint() { ComplaintDate = DateTime.Now, ComplaintTitle = txtTitle.Text, ComplaintDescription = txtdescription.Text, CategoryID = Convert.ToInt32(ddlcategory.SelectedValue), UserID = SessionManager.UserID, ComplaintStatus = "Unresolved", IsSeen = false }; con.tblComplaints.InsertOnSubmit(complaint); con.SubmitChanges(); showSuccess("Complaint submitted! Your complaint ID is: <b>" + complaint.ComplaintID + "</b>"); clearAllViews(); NotificationManager.complaintSent(); } catch (Exception ex) { showError("Error: " + ex); clearAllViews(); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { using (DatabaseDataContext con = new DatabaseDataContext()) { #region checks hideAllPlaceholders(); if (SessionManager.UserID == 0) { showError("You must be logged in to use this feature!"); Utilities.clearAllTextBoxes(viewMain); return; } string EncodedResponse = Request.Form["g-Recaptcha-Response"]; bool IsCaptchaValid = (ReCaptcha.Validate(EncodedResponse) == "true" ? true : false); if (!IsCaptchaValid) { showError("Prove that you are not a robot!"); return; } if (string.IsNullOrEmpty(txtEmergTitle.Text)) { showError("Emergency title is empty!"); return; } #endregion tblSession session = con.tblSessions.Where(x => x.SessionID == SessionManager.SessionID).FirstOrDefault(); try { tblEmergency emergency = new tblEmergency { EmergencyTitle = txtEmergTitle.Text, EmergencyLatitude = session.SessionLatitude, EmergencyLongitude = session.SessionLongitude, EmergencyStatus = "Pending", IsSeen = false, EmergencyDate = DateTime.UtcNow, UserID = SessionManager.UserID }; con.tblEmergencies.InsertOnSubmit(emergency); con.SubmitChanges(); showSuccess("Emergency notification has been issued successfully!"); Utilities.clearAllTextBoxes(viewMain); NotificationManager.emergencySent(); } catch (Exception ex) { showError("Error: " + ex); Utilities.clearAllTextBoxes(viewMain); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { using (DatabaseDataContext con = new DatabaseDataContext()) { #region checks hideAllPlaceholders(); if (SessionManager.UserID == 0) { showError("You must be logged in to use this feature!"); return; } string EncodedResponse = Request.Form["g-Recaptcha-Response"]; bool IsCaptchaValid = (ReCaptcha.Validate(EncodedResponse) == "true" ? true : false); if (!IsCaptchaValid) { showError("Prove that you are not a robot!"); return; } if (string.IsNullOrEmpty(txtFeeddescription.Text)) { showError("Description is empty!"); return; } #endregion try { tblFeedback feedback = new tblFeedback { FeedbackDescription = txtFeeddescription.Text, FeedbackDate = DateTime.Now, IsSeen = false, UserID = SessionManager.UserID }; con.tblFeedbacks.InsertOnSubmit(feedback); con.SubmitChanges(); showSuccess("Feeback submitted!"); Utilities.clearAllTextBoxes(viewMain); NotificationManager.feedbackSent(); } catch (Exception ex) { showError("Error: " + ex); } } }
// Register button in register view[1] of mvMain. protected void btnRegister_Click(object sender, EventArgs e) { hideAllPlaceholders(); using (DatabaseDataContext con = new DatabaseDataContext()) { #region checks // Checking if user has clicked on captcha string EncodedResponse = Request.Form["g-Recaptcha-Response"]; bool IsCaptchaValid = (ReCaptcha.Validate(EncodedResponse) == "true" ? true : false); if (!IsCaptchaValid) { showError("Prove that you are not a robot!", 1); return; } // Checks for existing records with the same Email and Phonenumber if (con.tblUsers.Where(x => x.UserEmail.Equals(txtEmail.Text)).FirstOrDefault() != null) { showError("A user with this email already exists!", 1); return; } else if (con.tblUsers.Where(x => x.UserContact.Equals(txtContact.Text)).FirstOrDefault() != null) { showError("A user with this Phone number already exists!", 1); return; } // Checking the lenghts of inputs if (txtPassword.Text.Length > 15) { showError("Password size is too large!", 1); return; } else if (txtContact.Text.Length > 15) { showError("Enter a valid Phone number!", 1); return; } // Checking if there is a proof file or not. if (!imgProof.HasFile) { showError("No proof file found!", 1); return; } // Checking if the proof is a .jpg or .png image. if (!Utilities.isImage(Path.GetExtension(imgProof.FileName))) { showError("Proof is not an image!", 1); return; } // Checking if any of the textboxes are empty if (string.IsNullOrEmpty(txtFName.Text) || string.IsNullOrEmpty(txtLName.Text) || string.IsNullOrEmpty(txtContact.Text) || string.IsNullOrEmpty(txtEmail.Text) || string.IsNullOrEmpty(txtPassword.Text) || string.IsNullOrEmpty(txtAddress.Text)) { showError("Fill in all textboxes!", 1); return; } #endregion tblUser user = new tblUser { UserFName = txtFName.Text, UserLName = txtLName.Text, UserEmail = txtEmail.Text, UserPassword = SecurityManager.encrypt(txtPassword.Text, txtEmail.Text), UserContact = txtContact.Text, UserAddress = txtAddress.Text, UserRegDateTime = DateTime.UtcNow, UserTypeID = Convert.ToInt32(ddlUserType.SelectedValue), UserProof = txtContact.Text + Path.GetExtension(imgProof.FileName), IsVerified = false, IsVisible = true }; try { // Default save path of the image. string savePath = Server.MapPath("~/Forms/Proof"); // Specify the path with saved file name. string imgPath = Path.Combine(savePath, user.UserProof); // Actually saving the proof image on server after the object has been successfully submitted. imgProof.SaveAs(imgPath); // Saving the object of the user. con.tblUsers.InsertOnSubmit(user); con.SubmitChanges(); } catch (Exception ex) { showError("Error: " + ex, 1); } // If user has been created, show success message. showSuccess("User " + txtFName.Text + "'s registration has been submitted! <a href=\"LoginRegister.aspx\">Click Here</a> to go to login page", 1); NotificationManager.requestSent(); Utilities.clearAllTextBoxes(viewRegister); } }