コード例 #1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                IRegisterUser regUser  = new RegisterUser();
                int           entityID = regUser.Create(model.Person);
                var           user     = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, BusinessEntityID = entityID
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    var role = UserManager.AddToRole(user.Id, "Customer");
                    if (role.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToAction("PurchaseHeader", "Order"));
                    }
                    AddErrors(role);
                }
                AddErrors(result);
            }

            return(View(model));
        }