示例#1
0
        public async Task <ActionResult> register(RegisterViewModel model)
        {
            var user = await _userManager.FindByEmailAsync(model.Email);

            if (user != null)
            {
                return(BadRequest("Email has been taken"));
            }
            MyUser myUser = model.Adapt <MyUser>();

            myUser.SecurityStamp = _userManager.GenerateNewAuthenticatorKey();
            var result = await _userManager.CreateAsync(myUser, model.Password);

            if (result.Succeeded)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest(result.Errors));
            }
        }
示例#2
0
        public IActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                AppUser user = model.Adapt <AppUser>();

                var result = _userManager.CreateAsync(user, model.Password).Result;

                if (result.Succeeded)
                {
                    bool roleCheck = model.IsDentist ? AddRole("Dentist").Result : AddRole("Secratary").Result;

                    if (!roleCheck)
                    {
                        return(View("Error"));
                    }

                    _userManager.AddToRoleAsync(user, user.IsDentist ? "Dentist" : "Secratary").Wait();
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(model));
        }