Пример #1
0
        public async Task <IActionResult> CreateOrEdit(ApplicationUserVM boVM)
        {
            var functionName = "新建系统用户数据";

            if (ModelState.IsValid)
            {
                if (boVM.IsNew)
                {
                    // 检验用户名的唯一性
                    var isUniquelyForUserName = await _boVMService.IsUniquelyForUserName(boVM.UserName);

                    if (!isUniquelyForUserName)
                    {
                        ModelState.AddModelError("UserName", "用户名重复,请重新输入一个。");
                    }
                    else
                    {
                        // 保存数据
                        var x = await _boVMService.SaveBo(boVM);

                        if (x)
                        {
                            return(RedirectToAction("CommonList"));
                        }
                    }
                }
                else
                {
                    // 保存数据
                    var x = await _boVMService.SaveBo(boVM);

                    if (x)
                    {
                        return(RedirectToAction("CommonList"));
                    }
                }
            }


            if (!boVM.IsNew)
            {
                functionName = "编辑系统用户数据:" + boVM.UserName + "(" + boVM.Name + ")";
            }

            await _boVMService.SetApplicationRoleItemCollection(boVM);

            ViewData["ModuleName"]   = "系统用户管理";
            ViewData["FunctionName"] = functionName;
            if (boVM.IsNew)
            {
                return(PartialView("_Create", boVM));
            }
            else
            {
                return(PartialView("_Edit", boVM));
            }
        }
Пример #2
0
        public async Task <IActionResult> Register(ApplicationUserVM userVM)
        {
            if (ModelState.IsValid)
            {
                var isUniquelyUserName = await _boVMService.IsUniquelyForUserName(userVM.UserName);

                if (!isUniquelyUserName)
                {
                    // 处理名称重复校验
                    ModelState.AddModelError("UserName", "你提交的用户名经被系统使用,用户名。");
                    return(View(userVM));
                }

                await _boVMService.SaveBo(userVM);

                #region 直接登录系统
                // 提取用户对象
                var user = await _userManager.FindByEmailAsync(userVM.Email);

                if (user != null)
                {
                    var result = await _signInManager.PasswordSignInAsync(user, userVM.Password, false, lockoutOnFailure : false);

                    return(RedirectToAction("Index"));
                }
                else
                {
                }

                #endregion

                return(RedirectToAction("Index"));
            }

            return(View(userVM));
        }