public IActionResult Create([ModelBinder(binderType: typeof(SponsorModelBinder))] Sponsor sponsor) { List <Kid> kids = new List <Kid>(); foreach (var vKid in sponsor.SponsoredKids) { var kid = _context.Kids.Find(vKid.Id); kids.Add(kid); } sponsor.SponsoredKids = kids; _context.Sponsors.Add(sponsor); _context.SaveChanges(); bool isEmailSent = SendEmailToSponsor(sponsor); if (isEmailSent) { sponsor.LastConfirmationEmail = DateTime.Now; _context.Sponsors.Update(sponsor); _context.SaveChangesAsync(); } ViewBag.SponsorName = sponsor.Name; ViewBag.Kids = sponsor.SponsoredKids; ViewBag.IsEmailSent = isEmailSent; return(View("SubmissionResult")); }
public async Task <IActionResult> Create([Bind("Id,Name,DateOfBirth,Description")] Kid kid) { if (ModelState.IsValid) { _context.Add(kid); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(kid)); }