Example #1
0
        protected void btnSend_Click(object sender, EventArgs e)
        {
            Tools tool = new Tools();

            string from    = txtEmail.Text;
            string subject = txtName.Text;
            string email   = txtEmail.Text;
            string body    = txtMessage.Value;

            if (!string.IsNullOrEmpty(subject) && !string.IsNullOrEmpty(from) && !string.IsNullOrEmpty(body) && tool.IsValidEmail(email))
            {
                using (Sv_Eksamen_Entities db = new Sv_Eksamen_Entities())
                {
                    Svendeproeve.Models.Contact contact = new Svendeproeve.Models.Contact();

                    contact.Name    = txtName.Text;
                    contact.Email   = txtEmail.Text;
                    contact.Message = txtMessage.Value;

                    db.Contact.Add(contact);
                    db.SaveChanges();

                    string to   = "*****@*****.**";
                    string SMTP = "10.138.22.47";

                    tool.SendMail(to, from, subject, body, SMTP);

                    txtEmail.Text    = "";
                    txtName.Text     = "";
                    txtMessage.Value = "";

                    lblMessage.Text = "Thank you for your message !";

                    lblFillout.Visible = false;
                    lblMessage.Visible = true;
                }
            }

            else
            {
                lblFillout.Text    = "Please fill out all fields !";
                lblMessage.Visible = false;
                lblFillout.Visible = true;
            }
        }
Example #2
0
        // This is the Insert method to insert the entered Contact item
        // USAGE: <asp:FormView InsertMethod="InsertItem">
        public void InsertItem()
        {
            using (_db)
            {
                var item = new Svendeproeve.Models.Contact();

                TryUpdateModel(item);

                if (ModelState.IsValid)
                {
                    // Save changes
                    _db.Contact.Add(item);
                    _db.SaveChanges();

                    Response.Redirect("Default");
                }
            }
        }