public ActionResult UsersCreate(int contractorID) { RegisterContractorUserViewModel model = new RegisterContractorUserViewModel(); model.ContractorID = contractorID; return(View(model)); }
public async Task <ActionResult> UsersCreate(RegisterContractorUserViewModel model) { if (ModelState.IsValid) { ContractorUser user = (ContractorUser)model.GetUser(); user.ContractorID = model.ContractorID; var result = await userManager.CreateAsync(user, model.Password); if (result.Succeeded) { var resultRole = userManager.AddToRole(user.Id, "ContractorRole"); if (resultRole.Succeeded) { await workflowMessageService.SendContractorUserRegistrationNotificationMessageAsync(model); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link //string code = await userManager.GenerateEmailConfirmationTokenAsync(user.Id); //var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); //await userManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); await workflowMessageService.SendUserRegistrationMessageAsync(userManager, user.Id, Request.Url.Scheme, Url); return(RedirectToAction("Users", "Contractors", new { id = model.ContractorID })); } else { var errors = string.Join(",", resultRole.Errors); ModelState.AddModelError(string.Empty, errors); } } else { var errors = string.Join(",", result.Errors); ModelState.AddModelError(string.Empty, errors); } } // If we got this far, something failed, redisplay form return(View(model)); }