public async Task <IActionResult> Create([Bind("Name,Email,Body")] Message message) { if (ModelState.IsValid) { message.SentDate = DateTime.Now; _context.Add(message); await _context.SaveChangesAsync(); var adminEmail = _configuration["adminEmail"]; await _emailSender.SendEmailAsync(adminEmail, "LinkFIT Contact us request", string.Format("Name: {0}, Email: {1}, Message: {2}", message.Name, message.Email, message.Body)); return(RedirectToAction(nameof(Sent))); } return(View(message)); }
public async Task <IActionResult> Create([Bind("Surname,FirstName,EnrollmentDate,Gender,EntrantCategory,DateOfBirth")] Athlete athlete) { try { if (ModelState.IsValid) { _context.Add(athlete); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(athlete)); }