コード例 #1
0
        public async Task <IActionResult> Register(LoginVM loginVm)
        {
            if (ModelState.IsValid)
            {
                var identityUser = Transformation.Convert <LoginVM, IdentityUser>(loginVm);
                var result       = await _userManagementBs.Register(identityUser, loginVm.Password);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(loginVm));
        }
コード例 #2
0
        public async Task <IActionResult> Add(UserVM userVm)
        {
            if (!ModelState.IsValid)
            {
                return(View(userVm));
            }

            var            identityUser = Transformation.Convert <UserVM, IdentityUser>(userVm);
            IdentityResult result       = await _userManagementBs.Register(identityUser, userVm.Password);

            if (result.Succeeded)
            {
                return(RedirectToAction("Index"));
            }

            foreach (IdentityError error in result.Errors)
            {
                ModelState.AddModelError("", error.Description);
            }
            return(View("_Add", userVm));
        }