public ActionResult UsersCreate(int customerID)
        {
            RegisterCustomerAuditorUserViewModel model = new RegisterCustomerAuditorUserViewModel();

            model.CustomerID = customerID;
            return(View(model));
        }
        public ActionResult UsersCreate(RegisterCustomerAuditorUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                AdminUser user = (AdminUser)model.GetUser();

                var result = userManager.Create((ApplicationUser)user, model.Password);

                if (result.Succeeded)
                {
                    var customerAuditor = new CustomerAuditor(null, base.CurrentCustomerID, user.Id);
                    customerAuditorRepository.Create(customerAuditor);

                    //workflowMessageService.SendContractorUserRegistrationNotificationMessage(model);
                    return(RedirectToAction("Users", "CustomerAuditors"));
                }
                else
                {
                    var errors = string.Join(",", result.Errors);
                    ModelState.AddModelError(string.Empty, errors);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 3
0
        public async Task <ActionResult> UsersCreate(RegisterCustomerAuditorUserViewModel model)
        {
            if (ModelState.IsValid)
            {
                AdminUser user = (AdminUser)model.GetUser();

                var result = await userManager.CreateAsync((ApplicationUser)user, model.Password);

                if (result.Succeeded)
                {
                    //var customerAuditor = new CustomerAuditor(null, model.CustomerID, user.Id);
                    //customerAuditorRepository.Create(customerAuditor);

                    //Lo agregamos al Rol "CustomerAuditorRole"
                    customerAuditorRepository.SetRole(user.Id);

                    // 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);

                    //workflowMessageService.SendContractorUserRegistrationNotificationMessage(model);
                    return(RedirectToAction("Users", "CustomerAdminAuditors"));
                }
                else
                {
                    var errors = string.Join(",", result.Errors);
                    ModelState.AddModelError(string.Empty, errors);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }