public ActionResult DeleteConfirmed(int id) { Models.ContactForm contactForm = _contactFormRepository.GetWhere(x => x.Id == id).FirstOrDefault(); _contactFormRepository.Delete(contactForm); return(RedirectToAction("Index")); }
public ActionResult Index(Models.ContactForm contactForm) { //sending an eamil //setp1. add using system.Net.Mail //step2. create a new message //first para is who it is from, and the second is who it's to. MailMessage mailmessage = new MailMessage("*****@*****.**", "*****@*****.**"); //step 3 Set the subject mailmessage.Subject = "Contact Request from " + contactForm.FirstName + " " + contactForm.LastName; //step 4 Contstruct eh body with a stringBuilder System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.AppendLine("You have a ew contact request"); sb.AppendLine("Name: " + contactForm.FirstName); sb.AppendLine("Email: " + contactForm.Email); sb.AppendLine("Message: " + contactForm.Message); sb.AppendLine("I love you,"); sb.AppendLine("The Robots"); //step5 Add teh body tot he message mailmessage.Body = sb.ToString(); //step6 Declare the SMTP client aka. The mail server SmtpClient smtpClient = new SmtpClient("mail.dustinkraft.com", 587); smtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "techIsFun1"); //step7 send the message smtpClient.Send(mailmessage); //done. //kick the user to the thank you page return(RedirectToAction("ThankYou", "Contact")); }
public ActionResult Contact() { //create a new contact form object to // pass to our view Models.ContactForm cf = new Models.ContactForm(); return(View(cf)); }
public ActionResult Contact() { //create a new contact form object to // pass to our view Models.ContactForm cf = new Models.ContactForm(); return View(cf); }
public ActionResult Contact(Int64 ContactID = 0, string Name = null, string Mobile = null, string Email = null, string Subject = null, string Message = null) { string status = ""; Models.ContactForm cf = new Models.ContactForm(); cf.ContactDate = DateTime.Now; cf.Email = Email; cf.Message = Message; cf.Mobile = Mobile; cf.Name = Name; cf.Subject = Subject; db.ContactForm.Add(cf); int i = db.SaveChanges(); if (i > 0) { status = "Succeeded"; } else { status = "UnSucceeded"; } return(View()); }
public ActionResult Index(Models.ContactForm contact) { //sending an email //step 1. adding using System.net.Mail; //step 2. create a new message MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**"); //step 3. set the subject message.Subject = "Message from " + contact.FirstName; //step 4. construct the body System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.AppendLine("Hey Bro, you have a new message."); sb.AppendLine(); sb.AppendLine("From: " + contact.FirstName + " " + contact.LastName); sb.AppendLine("Their Email: " + contact.Email); sb.AppendLine(); sb.AppendLine("The Message: " + contact.Comment); sb.AppendLine(); sb.AppendLine("I love you,"); sb.AppendLine(); sb.AppendLine("Barack Obama"); //step 5. add the body to the message message.Body = sb.ToString(); //step 6. Declare the SMTP client aka the mail server SmtpClient smtpClient = new SmtpClient("mail.dustinkraft.com", 587); smtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "techIsFun1"); //step 7. send the message smtpClient.Send(message); //done //kick the user to the thank you page return(RedirectToAction("ThankYou", "Contact")); }
public ActionResult Edit(int id, Models.ContactForm contactForm) { //tell the db context that the contact form needs to be updated db.Entry(contactForm).State = System.Data.EntityState.Modified; //save changes db.SaveChanges(); //kick the user back to the list return(RedirectToAction("Index", "Admin")); }
public ActionResult Contact() { if (Request.IsAjaxRequest()) { return PartialView(); } Models.ContactForm cf = new Models.ContactForm(); return View(cf); }
public ActionResult Contact(Models.ContactForm cf) { //create a new connection to our database Models.ContactFormEntities db = new Models.ContactFormEntities(); //add the contact info to the database db.ContactForms.Add(cf); //save changes to the db db.SaveChanges(); //Redirect user to the thank you page return(RedirectToAction("ThankYou")); }
public ActionResult Index(Models.ContactForm contactForm) { //create a connection to the database Models.ContactFormsEntities db = new Models.ContactFormsEntities(); //add our contact info to the database. db.ContactForms.Add(contactForm); //save the changes db.SaveChanges(); //kickk the user to the thankyou page return(RedirectToAction("ThankYou", "Contact")); }
public ActionResult DeleteConfirm(int id) { //get the form to delete from the database Models.ContactForm formToDelete = db.ContactForms.Find(id); //set form to be deleted db.ContactForms.Remove(formToDelete); //save changes db.SaveChanges(); //kick user back to list return(RedirectToAction("Index", "Admin")); }
public ActionResult Create(Models.ContactForm contactForm) { if (ModelState.IsValid) { _contactFormRepository.Create(contactForm); var message = _emailService.CreateMailMessage(contactForm); _emailService.SendEmail(message); return(RedirectToAction("Index")); } return(View(contactForm)); }
public ActionResult Index(Models.ContactForm cf) { //establish a connection to the database var db = new Models.ContactFormEntities(); //add our contact form to the database db.ContactForms.Add(cf); //save the changes to the database db.SaveChanges(); //kick the user to the thank you page return(RedirectToAction("ThankYou")); }
public ActionResult Contact(Models.ContactForm contactForm) { //add the form to the database try { //try doing something... //set the date created contactForm.DateCreated = DateTime.Now; //adding something to the database... //step 1: create the data context Models.ContactFormsEntities db = new Models.ContactFormsEntities(); //step 2: add the object to the table db.ContactForms.Add(contactForm); //step 3: SAVE db.SaveChanges(); } catch (Exception ex) { //if it blows up do this... ViewBag.Error = ex.Message; return(View("Error")); } //mail us a copy //SMTP: Simple Mail Transfer Protocol //host: mail.dustinkraft.com //port: 587 //user: [email protected] //password: techIsFun1 MailMessage mail = new MailMessage("*****@*****.**", "*****@*****.**"); //mail.From = new MailAddress("*****@*****.**"); //mail.To.Add("*****@*****.**"); mail.Subject = "AWESOME EMAIL FROM " + contactForm.Name; mail.Body = string.Format("{0} at {1} just sent you the following message: {2}", contactForm.Name, contactForm.Email, contactForm.Body); //connecting to actual email server SmtpClient client = new SmtpClient("mail.dustinkraft.com"); //client.Host = "mail.dustinkraft.com"; client.Port = 587; client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "techIsFun1"); client.Send(mail); //redirect user to the Thank You page return(RedirectToAction("ThankYou", "Home")); }
// POST: ContactForms/Edit/5 // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. // GET: ContactForms/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.ContactForm contactForm = _contactRepository.GetWhere(x => x.Id == id.Value).FirstOrDefault(); if (contactForm == null) { return(HttpNotFound()); } return(View(contactForm)); }
public MailMessage CreateMailMessage(Models.ContactForm model) { var mailMessage = new MailMessage { Sender = new MailAddress("*****@*****.**"), From = new MailAddress("*****@*****.**"), To = { "*****@*****.**" }, Subject = model.Subject, Body = model.Body, IsBodyHtml = true }; return(mailMessage); }
// GET: ContactForms/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //wyszukanie konkretnego obiektu do usunięcia Models.ContactForm contactForm = _contactFormRepository.GetWhere(x => x.Id == id.Value).FirstOrDefault(); if (contactForm == null) { return(HttpNotFound()); } return(View(contactForm)); }
// GET: ContactForms/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Models.ContactForm contactForm = _contactFormRepository.GetWhere(x => x.Id == id.Value).FirstOrDefault(); //po wykonaniu tego zapytania zwraca jeden element // znajdź mi w repozytorium obiekt, który ma określone ID. ID to nullable - dlatego podajemy value if (contactForm == null) { return(HttpNotFound()); } return(View(contactForm)); }
public ActionResult Index(Models.ContactForm contact) { MailMessage message = new MailMessage("*****@*****.**", "*****@*****.**"); message.Subject = "Message from " + contact.FirstName; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.AppendLine("Hey Bro, you have a new message."); sb.AppendLine(); sb.AppendLine("From: " + contact.FirstName + " " + contact.LastName); sb.AppendLine("Their Email: " + contact.Email); sb.AppendLine(); sb.AppendLine("The Message: " + contact.Comment); sb.AppendLine(); sb.AppendLine("I love you,"); sb.AppendLine(); message.Body = sb.ToString(); SmtpClient smtpClient = new SmtpClient("mail.dustinkraft.com", 587); smtpClient.Send(message); return(RedirectToAction("ThankYou", "Contact")); }
public ActionResult Contact() { Models.ContactForm cf = new Models.ContactForm(); return View(cf); }