public async Task <IActionResult> Create([Bind("ID,Voornaam,Achternaam,Geslacht,Land,Email")] Nieuwsbriefmodel nieuwsbriefmodel) { if (ModelState.IsValid) { string bericht = ". Bedankt voor het aanmelden, vanaf nu ontvangt u wekelijks onze nieuwsbrief, afmelden kan door te mailen naar dit emailadres."; string to = nieuwsbriefmodel.Email; string from = "*****@*****.**"; string subject = "Nieuwsbrief"; string body = @"Geachte" + " " + nieuwsbriefmodel.Voornaam + " " + nieuwsbriefmodel.Achternaam + bericht; MailMessage message = new MailMessage(from, to, subject, body); SmtpClient client = new SmtpClient("smtp.gmail.com", 587); client.EnableSsl = true; client.Credentials = new NetworkCredential("*****@*****.**", "project2019"); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; client.Send(message); _context.Add(nieuwsbriefmodel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(nieuwsbriefmodel)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Voornaam,Achternaam,Geslacht,Land,Email")] Nieuwsbriefmodel nieuwsbriefmodel) { if (id != nieuwsbriefmodel.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(nieuwsbriefmodel); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NieuwsbriefmodelExists(nieuwsbriefmodel.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(nieuwsbriefmodel)); }