public ActionResult Contact(ContactViewModels c) { ViewBag.Title = "Contact"; if (string.IsNullOrWhiteSpace(c.FullName) == false) { if (c.FullName.Contains(" ") == false) { ModelState.AddModelError(nameof(c.FullName), "Please input first and last name."); } if (string.IsNullOrWhiteSpace(c.Email) == false) { if (c.Email.Contains("@") == false) { ModelState.AddModelError(nameof(c.Email), "Not a valid email address"); } } } if (ModelState.IsValid) { return(RedirectToAction("ContactAcknowledgement")); } //I tried removing c to see if the form would still remember and it did. I put c back anyways. return(View(c)); }
public async Task <ActionResult> Contact(ContactViewModels contatti) { if (ModelState.IsValid) { MailMessage message = new MailMessage( "*****@*****.**", "[email protected],[email protected]", "Richiesta informazioni dal sito camen.org", "Il giorno " + DateTime.Now + "<br/><strong>" + contatti.Nome + " " + contatti.Cognome + "</strong> [" + contatti.Email + "] " + "<br/> ha inviato una richiesta di informazioni dal sito www.camen.org<hr/><ul><li> Indirizzo: <strong>" + contatti.Indirizzo + "</strong></li><li> Telefono: <strong>" + contatti.Telefono + "</strong></li><li> Professione: <strong>" + contatti.Professione + "</strong></li><li> Organizzazione: <strong>" + contatti.Organizzazione + "</strong></li><li> Richiesta: <strong>" + contatti.Richiesta + "</strong></li>" ); message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { await smtp.SendMailAsync(message); } return(RedirectToAction("FormOk", "Home")); } return(View(contatti)); }
// GET: Contact public ActionResult Index(int?id) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("Login", "Account")); } if (id == null) { return(RedirectToAction("Index", "Person")); } PhoneBookDbEntities db = new PhoneBookDbEntities(); List <ContactViewModels> contacts = new List <ContactViewModels>(); foreach (var item in db.Contacts.Where(c => c.PersonId == id).ToList()) { ContactViewModels obj = new ContactViewModels(); obj.ContactId = item.ContactId; obj.ContactNumber = item.ContactNumber; obj.Type = item.Type; obj.PersonId = item.PersonId; contacts.Add(obj); } ViewBag.PersonId = id; return(View(contacts)); }
/// <summary> /// Удаляет текущую VM контакта из списка /// </summary> public void RemoveSelectedContactViewModel() { if (SelectedContactViewModel != null) { ContactViewModels.Remove(SelectedContactViewModel); IsProjectSaved = false; } }
/// <summary> /// Заменят одну VM контакта на другую /// </summary> /// <param name="currentContactViewModel">Текущая VM контакта</param> /// <param name="newContactViewModel">Новая VM контакта</param> public void ReplaceContactViewModel( ContactViewModel currentContactViewModel, ContactViewModel newContactViewModel) { ContactViewModels.Remove(currentContactViewModel); ContactViewModels.Add(newContactViewModel); IsProjectSaved = false; }
public IActionResult Contact(ContactViewModels model) { if (ModelState.IsValid) { _mailService.SendMail(_config["MailSettings:ToAddress"], model.Email, "From theWorld", model.Message); } return(View()); }
public async Task <IActionResult> Contact(ContactViewModels models) { if (ModelState.IsValid) { await _emailSender.SendEmailContactAsync(models.Email, "Contact", models.Message, models.Firstname, models.Lastname, models.Comapny); return(View("View")); } return(View(models)); }
// GET: Contact/Details/5 public ActionResult Details(int id) { PhoneBookDbEntities db = new PhoneBookDbEntities(); var item = db.Contacts.SingleOrDefault(c => c.ContactId == id); ContactViewModels obj2 = new ContactViewModels(); obj2.ContactId = item.ContactId; obj2.ContactNumber = item.ContactNumber; obj2.Type = item.Type; obj2.PersonId = item.PersonId; return(View(obj2)); }
public IActionResult Contact(ContactViewModels model) { if (ModelState.IsValid) { _mailService.SendMessage("*****@*****.**", model.Observacao, $"From:{model.Email}, Messege:{model.Message}"); ViewBag.UserMessage = "Email Enviado"; } else { } return(View()); }
public ActionResult Contact(ContactViewModels cvm) { //validation check - if they did not pass, send them back to the Creat view, with the form still //filled out //This is done by passing the object back to the view (cvm) if (!ModelState.IsValid) { return(View(cvm)); } //Create the message (email body text) string message = $"You have received an email from {cvm.Name} with a subject <strong>{cvm.Subject}</strong>. Please respond to <em>{cvm.Email}</em> with your response to the following message: <br><br> {cvm.Message}"; //Create the MailMessage object MailMessage msg = new MailMessage("*****@*****.**", "*****@*****.**", /*$"{System.DateTime.Now.Date} - {cvm.Subject}", message);*/ cvm.Subject, message ); //Customize MailMessage //msg.CC.Add("*****@*****.**"); msg.Priority = MailPriority.High; msg.IsBodyHtml = true; //Create SmtpClient SmtpClient client = new SmtpClient("mail.loyadev.net"); //Verify Credentials for client client.Credentials = new NetworkCredential("*****@*****.**", "Jaguars70!"); //For AT&T or XFinity client.Port = 8889; //Attempt to send email try { client.Send(msg); } catch (System.Exception) { ViewBag.Error = "Sorry, there was an error handling your request. Please try again."; return(View(cvm)); } return(View("EmailConfirmation", cvm)); }
public ActionResult Delete(int id, ContactViewModels collection) { try { PhoneBookDbEntities db = new PhoneBookDbEntities(); var contact = db.Contacts.Where(c => c.ContactId == id).SingleOrDefault(); db.Contacts.Remove(contact); db.SaveChanges(); return(RedirectToAction("Index", "Contact", new { id = contact.PersonId })); } catch { return(View()); } }
public IActionResult Contact(ContactViewModels model) { if (model.Email.Contains("aol.com")) { ModelState.AddModelError("", "We dont support AOL addresses"); } if (ModelState.IsValid) { _mailService.SendMail(_config["MailSetting:ToAddress"], model.Email, "From TheWorld", model.Message); ModelState.Clear(); ViewBag.UserMessage = "Message Sent"; } return(View()); }
public ActionResult Create(ContactViewModels collection) { try { PhoneBookDbEntities db = new PhoneBookDbEntities(); Contact obj2 = new Contact(); obj2.ContactNumber = collection.ContactNumber; obj2.Type = collection.Type; obj2.PersonId = collection.PersonId; db.Contacts.Add(obj2); db.SaveChanges(); return(RedirectToAction("Index", "Contact", new { id = obj2.PersonId })); } catch { return(View()); } }
// GET: Contact/Edit/5 public ActionResult Edit(int?id) { PhoneBookDbEntities db = new PhoneBookDbEntities(); var item = db.Contacts.SingleOrDefault(c => c.ContactId == id); if (item == null) { return(HttpNotFound()); } ViewBag.PersonId = 0; ContactViewModels obj = new ContactViewModels(); obj.ContactId = item.ContactId; obj.ContactNumber = item.ContactNumber; obj.Type = item.Type; obj.PersonId = item.ContactId; return(View("Create", obj)); }
public ActionResult Edit(int id, ContactViewModels collection) { try { PhoneBookDbEntities db = new PhoneBookDbEntities(); var contact = db.Contacts.SingleOrDefault(c => c.ContactId == id); if (contact != null) { contact.ContactNumber = collection.ContactNumber; contact.Type = collection.Type; } db.SaveChanges(); return(RedirectToAction("Index", "Contact", new { id = contact.PersonId })); } catch { return(View()); } }
public ActionResult Contact(ContactViewModels cvm) { if (ModelState.IsValid) { string message = $"You have recieved a email from {cvm.Name} " + $"With the subject {(string.IsNullOrEmpty(cvm.Subject) ? "No Subject" : cvm.Subject)} " + $"Please respond to {cvm.Email} <br/>Message:<br/>" + $"<em>{cvm.Message}</em>"; MailMessage mm = new MailMessage( "*****@*****.**", "*****@*****.**", string.IsNullOrEmpty(cvm.Subject) ? "No Subject" : cvm.Subject, message ); mm.IsBodyHtml = true; mm.Priority = MailPriority.High; mm.ReplyToList.Add(cvm.Email); SmtpClient client = new SmtpClient("mail.kindledev.com"); client.Port = 8889; client.Credentials = new NetworkCredential( "*****@*****.**", "P@ssw0rd"); try { client.Send(mm); } catch (Exception e) { ViewBag.FailedEmailMessage = $"We're sorry your request was not completed at this time." + $" Please try again later. Error Message: <br/>{e.StackTrace}"; return(View(cvm)); } ViewBag.FailedSend = null; return(View("EmailConfirmation", cvm)); }//ModelStatIsValid return(View("Index")); }
public ActionResult Contact(ContactViewModels model) { var msg = String.Format("Contact from: {1}{0}Email: {2}{0}Comment: {3}", Environment.NewLine, model.Name, model.Email, model.Message ); if (_mailService.SendMail(model.Email, "*****@*****.**", "Contact from website", msg).Equals("")) { TempData["message"] = "Thanks for contacting me."; } else { TempData["message"] = "Oops! Something went wrong, please try again."; } return(View()); }
public ActionResult Contact(ContactViewModels contactViewModel) { ViewBag.Message = "If you have any problems with the managment system please feel free to get into contact with us via this contact page."; if (ModelState.IsValid) { try { MailMessage msz = new MailMessage(); msz.From = new MailAddress(contactViewModel.From); //Email which you are getting //from contact us page msz.To.Add("*****@*****.**"); //Where mail will be sent msz.Subject = contactViewModel.Subject; msz.Body = contactViewModel.Body; SmtpClient smtp = new SmtpClient(); smtp.Host = "nl1-wss2.a2hosting.com"; smtp.Port = 25; smtp.Credentials = new System.Net.NetworkCredential ("*****@*****.**", "3o3fE@k4"); smtp.EnableSsl = true; smtp.Send(msz); // ModelState.Clear(); //[email protected] upg$H101 //This is for an emal service Remeber this ! ViewBag.StatusMessage = $"Your Message has been sent successfully "; return(View(contactViewModel)); } catch (Exception ex) { // ModelState.Clear(); ViewBag.StatusMessage = $"Sorry we are facing a problem here" + ex; } } return(View(contactViewModel)); }
public ActionResult Contact(ContactViewModels vm) { if (ModelState.IsValid) { try { MailMessage msz = new MailMessage(); msz.From = new MailAddress(vm.Email); //Email which you are getting //from contact us page msz.To.Add("*****@*****.**"); //Where mail will be sent msz.Subject = vm.Subject; msz.Body = vm.Message; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.Credentials = new System.Net.NetworkCredential ("emirodriguezdev", "EmiRodriguezDev1"); smtp.EnableSsl = true; smtp.Send(msz); ModelState.Clear(); ViewBag.Message = "Su mensaje ha sido enviado correcctamente "; } catch (Exception ex) { ModelState.Clear(); ViewBag.Message = "Lo lamentamos, ha ocurrido un error. Intente nuevamente mas tard"; } } return(View()); }
public ActionResult Contact(ContactViewModels cvm) { //When a class has validation attributes, that validation should be checked BEFORE attempting to process any data if (!ModelState.IsValid) { //Send them back to the form by passing the object to the view, //the form returns with the original populated information return(View(cvm)); } //Only executes if the form(object) passes model validation #region Send Email functionality //Build the message - what we see when we receive the email //Step 1) Build the email message body(content for the email) string message = $"You have received an email from {cvm.Name} with the subject - {cvm.Subject}. Please respond to {cvm.Name}" + $"with your response to the following message: <br><cite>{cvm.Message}</cite>"; //The MailMessage Object takes several parameters and has 3 overloads /*This instance in particular takes 4 parameters: * from: [email protected] * to: [email protected] * subject: here is the subject */ //Step 2) Create the MailMessage object and customize it MailMessage msg = new MailMessage( //From - your domain email ([email protected]) "*****@*****.**", //TO - Where the email actually lands(should be sent to your personal email) "*****@*****.**", //SUBJECT cvm.Subject, //BODY message ); //MailMessage properties msg.IsBodyHtml = true; //Allow HTML formatting in the email (Message has HTML in it) msg.Priority = MailPriority.High; //The default is Normal //CC or BCC other recipients //msg.CC.ADD("Another2Email.com") //Response to the sender's email instead of our own SMTP client msg.ReplyToList.Add(cvm.Email); //Step 3) Create the SmtpClient that will send the email //The Client will need info from the host to route the email SmtpClient client = new SmtpClient("mail.yourdomain.com"); //Client credentials (smarterASP requires your email and password) client.Credentials = new NetworkCredential("*****@*****.**", "Password"); client.Port = 8889; //Step 4) Attempt to send the email //It is possible that the email server is down or we have configuration issues, //so we want to encapsulate our code in a try/catch try { //Attempt to send the email client.Send(msg); } catch (Exception ex) { ViewBag.CustomerMessage = $"Sorry, something went wrong, please try again later or review the stacktrace<br>.{ex.StackTrace}"; return(View(cvm)); } //If all goes well and the email is able to send, we will send them to a confirmation View //return View("Email Confirmation", cvm); ViewBag.CustomerMessage = "Message Sent"; return(View()); #endregion }
/// <summary> /// Создает список контактов из списка VM контактов /// </summary> /// <returns>Возвращает список контактов</returns> private List <Contact> GetAllContacts() { return(ContactViewModels.Select(contactViewModel => contactViewModel.Contact).ToList()); }
private bool CheckLists() { return(MachineViewModels.Any() || ContactViewModels.Any() || ManualViewModels.Any() || ProspectsViewModels.Any() || QuotationViewModels.Any() || SparePartViewModels.Any() || Customers.Any() || VisitsViewModels.Any()); }
public IActionResult Contact(ContactViewModels model) { ViewBag.Title = "Contact Us"; return(View()); }
/// <summary> /// Добавляет VM контакта в список /// </summary> /// <param name="contactViewModel">Новая VM контакта</param> public void AddContactViewModel( ContactViewModel contactViewModel) { ContactViewModels.Add(contactViewModel); IsProjectSaved = false; }