Esempio n. 1
0
        protected void CreateUserButton_Click(object sender, EventArgs e)
        {
            lblError.Text = "";

            using (GESEntities db = new GESEntities())
            {
                try
                {
                    //Check that email doesn't exist
                    var getUser = (from c in db.Users where c.Email == Email.Text.ToString() select c).FirstOrDefault();

                    if (getUser != null)
                    {
                        lblError.Text = "This Email address has already been registered";
                    }
                    else
                    {

                        //Register user
                        User newUser = new User();
                        newUser.UserName = Guid.NewGuid().ToString();
                        newUser.Password = Password.Text.ToString();
                        newUser.Email = Email.Text.ToString();
                        //newUser.FirstName = txtFirstName.Text.ToString();
                        //newUser.LastName = txtSurname.Text.ToString();
                        //newUser.CellNo = txtCellNo.Text.ToString();
                        //newUser.AddrCity = txtTown.Text.ToString();
                        newUser.RoleID = 2;
                        db.Users.AddObject(newUser);
                        db.SaveChanges();

                        //Send Welcome Email
                        SendWelcomeMail(Email.Text.ToString());

                        Response.Redirect("~/MyQuip.aspx");
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to register New User - " + exp.Message.ToString(), exp);
                }
            }
        }
Esempio n. 2
0
        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);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUsers(User user)
 {
     base.AddObject("Users", user);
 }
Esempio n. 4
0
        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);
             }
        }
Esempio n. 5
0
 /// <summary>
 /// Create a new User object.
 /// </summary>
 /// <param name="userID">Initial value of the UserID property.</param>
 /// <param name="userName">Initial value of the UserName property.</param>
 /// <param name="password">Initial value of the Password property.</param>
 /// <param name="roleID">Initial value of the RoleID property.</param>
 public static User CreateUser(global::System.Int32 userID, global::System.String userName, global::System.String password, global::System.Int32 roleID)
 {
     User user = new User();
     user.UserID = userID;
     user.UserName = userName;
     user.Password = password;
     user.RoleID = roleID;
     return user;
 }