public async Task <ActionResult> Create([Bind(Include = "Id,Email,Code,HouseholdId")] Invitation invitation) { if (ModelState.IsValid) { invitation.household = db.Households.Where(h => h.Id == invitation.HouseholdId).First(); invitation.Code = Membership.GeneratePassword(12, 2); var callbackUrl = Url.Action("JoinHousehold", "Households", new { code = invitation.Code }, protocol: Request.Url.Scheme); if (invitation.Email != null) { await helper.InviteToHousehold(invitation.household.Name, invitation.Email, invitation.Code, callbackUrl); } db.Invitations.Add(invitation); db.SaveChanges(); ViewBag.InvitationSent = "An invitation has been sent."; return(RedirectToAction("Details", "Households", new { Id = invitation.HouseholdId })); } ViewBag.HouseholdId = new SelectList(db.Households, "Id", "Name", invitation.HouseholdId); return(View(invitation)); }