protected void btnEnquiry_Click(object sender, EventArgs e) { int enquiryID = 0; using (GESEntities db = new GESEntities()) { try { //Create a visitor user ID if not already logged in //------------------------------------------------------------------------+ // Add New User Record | //------------------------------------------------------------------------+ User newUser = new User(); newUser.UserName = "******" + Guid.NewGuid().ToString(); newUser.Password = "******"; newUser.FirstName = txtFirstName.Text.ToString(); newUser.LastName = txtSurname.Text.ToString(); newUser.Email = txtEmail.Text.ToString(); newUser.CellNo = txtCellNo.Text.ToString(); newUser.AddrCity = txtTown.Text.ToString(); newUser.RoleID = 1; //Visitor db.Users.AddObject(newUser); db.SaveChanges(); //------------------------------------------------------------------------+ // Add New Enquiry Record | //------------------------------------------------------------------------+ Enquiry newEnquiry = new Enquiry(); newEnquiry.UserID = newUser.UserID; newEnquiry.DateInserted = DateTime.Now; newEnquiry.Comments = txtComments.Text.ToString(); newEnquiry.MachineID = 0; db.Enquiries.AddObject(newEnquiry); db.SaveChanges(); enquiryID = newEnquiry.EnquiryID; } catch (Exception exp) { throw new Exception("ERROR: Unable to Submit Enquiry - " + exp.Message.ToString(), exp); } } //------------------------------------------------------------------------+ // Send off the email notification | //------------------------------------------------------------------------+ string body = ""; string subject = ""; using (GESEntities db = new GESEntities()) { try { subject = "GES Website Enquiry # " + enquiryID.ToString() + " from the JCB Parts Lead Page"; body = body + "Lead Detail" + Environment.NewLine + "-----------" + Environment.NewLine + "First Name : " + txtFirstName.Text.ToString() + Environment.NewLine + "Surname : " + txtSurname.Text.ToString() + Environment.NewLine + "Email : " + txtEmail.Text.ToString() + Environment.NewLine + "Cell No : " + txtCellNo.Text.ToString() + Environment.NewLine + "Town : " + txtTown.Text.ToString() + Environment.NewLine + "Comments/Requirements : " + txtComments.Text.ToString(); //Send Mail MailMessage mailObj = new MailMessage("*****@*****.**", "*****@*****.**", subject, body); mailObj.To.Add("*****@*****.**"); mailObj.CC.Add("*****@*****.**"); mailObj.Body = body.ToString(); SmtpClient SMTPServer = new SmtpClient(); SMTPServer.Host = "smtp.gmail.com"; SMTPServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "reevesie007"); SMTPServer.EnableSsl = true; try { SMTPServer.Send(mailObj); Response.Redirect("~/LeadManagement/Lead-Enquiry-Confirmation.aspx", false); } catch (Exception ex) { string error = ex.ToString(); } } catch (Exception exp) { throw new Exception("ERROR: Unable to send mail - " + exp.Message.ToString(), exp); } } }
/// <summary> /// Create a new Enquiry object. /// </summary> /// <param name="enquiryID">Initial value of the EnquiryID property.</param> /// <param name="userID">Initial value of the UserID property.</param> /// <param name="dateInserted">Initial value of the DateInserted property.</param> /// <param name="machineID">Initial value of the MachineID property.</param> public static Enquiry CreateEnquiry(global::System.Int32 enquiryID, global::System.Int32 userID, global::System.DateTime dateInserted, global::System.Int32 machineID) { Enquiry enquiry = new Enquiry(); enquiry.EnquiryID = enquiryID; enquiry.UserID = userID; enquiry.DateInserted = dateInserted; enquiry.MachineID = machineID; return enquiry; }
protected void btnEnquiry_Click(object sender, EventArgs e) { bool proceed = true; lblFirstName.Text = ""; lblSurname.Text = ""; lblEmailRequired.Text = ""; lblCellNo.Text = ""; //do normal checks if (txtFirstName.Text == "") { lblFirstName.Text = "Oops.... First Name please"; proceed = false; } if (txtSurname.Text == "") { lblSurname.Text = "Oops.... Surname please"; proceed = false; } if (txtEmail.Text == "") { lblEmailRequired.Text = "Oops.... Email Address please"; proceed = false; } else { if (!Regex.IsMatch(txtEmail.Text, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*")) { lblEmailRequired.Text = "Oops.... Please provide the correct email format"; proceed = false; } } if (txtCellNo.Text == "") { lblCellNo.Text = "Oops.... Cell # please"; proceed = false; } else { if (!Regex.IsMatch(txtCellNo.Text, @"^[0-9]+$")) { lblCellNo.Text = "Oops.... Please provide a numeric only number i.e. no spaces, hyphens, brackets, etc"; proceed = false; } } if (proceed) { btnEnquiry.Attributes.Add("onclick", "javascript:" + btnEnquiry.ClientID + ".disabled=true;" + ClientScript.GetPostBackEventReference(btnEnquiry, "")); int machineID = Int32.Parse(hfMachineID.Value); int enquiryID = 0; string source = ""; try { source = Request["source"].ToString(); } catch { source = "Unknown"; } string body = ""; string subject = ""; using (GESEntities db = new GESEntities()) { try { //Create a visitor user ID if not already logged in //------------------------------------------------------------------------+ // Add New User Record | //------------------------------------------------------------------------+ User newUser = new User(); newUser.UserName = "******" + Guid.NewGuid().ToString(); newUser.Password = "******"; newUser.FirstName = txtFirstName.Text.ToString(); newUser.LastName = txtSurname.Text.ToString(); newUser.Email = txtEmail.Text.ToString(); newUser.CellNo = txtCellNo.Text.ToString(); newUser.AddrCity = txtTown.Text.ToString(); newUser.RoleID = 1; //Visitor newUser.Comments = txtComments.Text.ToString(); db.Users.AddObject(newUser); db.SaveChanges(); //------------------------------------------------------------------------+ // Add New Enquiry Record | //------------------------------------------------------------------------+ Enquiry newEnquiry = new Enquiry(); newEnquiry.UserID = newUser.UserID; newEnquiry.DateInserted = DateTime.Now; newEnquiry.Comments = txtComments.Text.ToString(); newEnquiry.MachineID = machineID; newEnquiry.Source = source; db.Enquiries.AddObject(newEnquiry); db.SaveChanges(); enquiryID = newEnquiry.EnquiryID; if (source == "grease-gun-ad") { subject = "GES Enquiry # " + enquiryID.ToString() + " - Grease Gun Advert"; } else if (source == "post-ad") { subject = "GES Enquiry # " + enquiryID.ToString() + " - Advertising Banners"; } else if (source == "roller-320d-ad") { subject = "GES Enquiry # " + enquiryID.ToString() + " - 320D Roller for sale"; } else if (source == "140h-rim-for-sale-ad") { subject = "GES Enquiry # " + enquiryID.ToString() + " - 140H Rim for sale"; } else if (source == "used-equipment") { subject = "GES Enquiry # " + enquiryID.ToString() + " - Used Equipment page"; } else if (source == "shantui-forklift-promo") { subject = "GES Enquiry # " + enquiryID.ToString() + " - Shantui Forklift Promotion page"; } else if (source == "shantui-list-page") { subject = "GES Enquiry # " + enquiryID.ToString() + " - Shantui list page"; } else if (source == "contact-us") { subject = "GES Enquiry # " + enquiryID.ToString() + " - Contact Us page"; } else if (source == "equipment-to-sell") { subject = "GES Enquiry # " + enquiryID.ToString() + " - Equipment To Sell Banner"; } else { subject = "GES Enquiry # " + enquiryID.ToString() + " - Page source unknown"; } } catch (Exception exp) { throw new Exception("ERROR: Unable to Submit Enquiry - " + exp.Message.ToString(), exp); } } //------------------------------------------------------------------------+ // Send off the email notification | //------------------------------------------------------------------------+ //body = hfBody.Value; body = body + "Lead Detail" + Environment.NewLine + "-----------" + Environment.NewLine + "Lead Source : " + source + Environment.NewLine + "First Name : " + txtFirstName.Text.ToString() + Environment.NewLine + "Surname : " + txtSurname.Text.ToString() + Environment.NewLine + "Email : " + txtEmail.Text.ToString() + Environment.NewLine + "Cell No : " + txtCellNo.Text.ToString() + Environment.NewLine + "Town : " + txtTown.Text.ToString() + Environment.NewLine + "Comments/Requirements : " + Environment.NewLine + Environment.NewLine + txtComments.Text.ToString(); try { string SMTPHost = WebConfigurationManager.AppSettings["SMTPHost"]; string SMTPUsername = WebConfigurationManager.AppSettings["SMTPUsername"]; string SMTPPassword = WebConfigurationManager.AppSettings["SMTPPassword"]; //string SMTPFrom = WebConfigurationManager.AppSettings["SMTPFrom"]; string SMTPFrom = txtEmail.Text.ToString(); string SMTPTo = WebConfigurationManager.AppSettings["SMTPTo"]; string SMTPCc = WebConfigurationManager.AppSettings["SMTPCc"]; #if DEBUG SMTPFrom = WebConfigurationManager.AppSettings["SMTPFromTest"]; SMTPTo = WebConfigurationManager.AppSettings["SMTPToTest"]; SMTPCc = WebConfigurationManager.AppSettings["SMTPCcTest"]; #endif //Send Mail MailMessage mailObj = new MailMessage(); MailAddress from = new MailAddress(SMTPFrom, txtFirstName.Text.ToString() + " " + txtSurname.Text.ToString()); mailObj.From = from; mailObj.Subject = subject + " | " + txtFirstName.Text.ToString() + " " + txtSurname.Text.ToString(); mailObj.Body = body.ToString(); //Get the To receipients char[] separator = new char[] { ';' }; string[] strToSplit = SMTPTo.Split(separator); foreach (string arrStr in strToSplit) { mailObj.To.Add(arrStr); } //Get the CC receipients string[] strCCSplit = SMTPCc.Split(separator); foreach (string arrStr in strCCSplit) { mailObj.CC.Add(arrStr); } SmtpClient SMTPServer = new SmtpClient(); SMTPServer.Host = SMTPHost; SMTPServer.Credentials = new System.Net.NetworkCredential(SMTPUsername, SMTPPassword); //SMTPServer.EnableSsl = true; try { SMTPServer.Send(mailObj); Response.Redirect("EnquiryConfirmation.aspx", false); } catch (Exception ex) { lblError.Text = ex.ToString(); } } catch (Exception exp) { throw new Exception("ERROR: Unable to send mail - " + exp.Message.ToString(), exp); } //Send lead to ZOHO insertZOHOLead(enquiryID.ToString(), body, subject); } }
/// <summary> /// Deprecated Method for adding a new object to the Enquiries EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToEnquiries(Enquiry enquiry) { base.AddObject("Enquiries", enquiry); }