/// <summary> /// 用户管理界面创建用户 /// </summary> /// <param name="param"></param> /// <param name="currentUser"></param> /// <returns></returns> public async Task <BaseResponseModel> CreateManagerUserAsync(CreateUserParam param, UserCacheBo currentUser) { var result = new ResponseModel <bool>(); // 考虑是否验证上传的角色是当前租户下的 var checkResult = await CheckRoleIds(param.RoleIds, currentUser); if (!checkResult.IsNullOrEmpty()) { return(result.Fail(checkResult)); } if (await ExistUserAsync(param.Email)) { result.Fail(ResponseCode.Fail, "该邮箱已存在", false); return(result); } var sysUser = new SysUser() { NickName = param.NickName, PassWord = param.Pwd.Md5Encrypt(), Email = param.Email, Sex = 1, State = 1, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now, TenantId = currentUser.TenantId, UpdatedBy = 0, CreatedBy = currentUser.UserId, SysUserRoleRelations = new List <SysUserRoleRelation>() }; param.RoleIds.ForEach(roleId => { sysUser.SysUserRoleRelations.Add(new SysUserRoleRelation() { TenantId = currentUser.TenantId, RoleId = roleId, State = 1, CreatedTime = DateTime.Now, CreatedBy = currentUser.UserId, Deleted = false, }); }); SysUserDao.Add(sysUser); var count = await SysUserDao.SaveChangesAsync(); return(count > 0 ? result.Succeed(true) : result.Fail("保存失败", false)); }
/// <summary> /// 保存注册用户 /// </summary> /// <param name="registerUserParam"></param> /// <returns></returns> private async Task <int> SaveRegisterUserAsync(RegisterUserParam registerUserParam) { var tenantUser = new SysTenant() { //TenantId = IdWorker.NextId(), CreatedTime = DateTime.Now, TenantName = registerUserParam.TenantName, Remark = "注册", State = 1, }; SysUserDao.Add(tenantUser); await SysUserDao.SaveChangesAsync(); var currentRoleMenu = new List <SysRoleMenuRelation>(); SeedData.InitNormalRoleMenuRelations.ForEach(roleMenu => { currentRoleMenu.Add(new SysRoleMenuRelation() { TenantId = tenantUser.TenantId, CreatedTime = DateTime.Now, MenuId = roleMenu.MenuId, State = 1, }); }); var sysUser = new SysUser() { NickName = registerUserParam.NickName, PassWord = registerUserParam.PassWord.Md5Encrypt(), Email = registerUserParam.Email, Sex = 1, State = 1, CreatedTime = DateTime.Now, UpdatedTime = DateTime.Now, UpdatedBy = 0, CreatedBy = 0, TenantId = tenantUser.TenantId, SysUserRoleRelations = new List <SysUserRoleRelation>() { new SysUserRoleRelation() { State = 1, TenantId = tenantUser.TenantId, CreatedTime = DateTime.Now, SysRole = new SysRole() { CreatedTime = DateTime.Now, RoleName = "超级管理员", RoleDesc = string.Empty, TenantId = tenantUser.TenantId, SysRoleMenuRelations = currentRoleMenu } } } }; SysUserDao.Add(sysUser); //var role = new SysRole() //{ // CreatedTime = DateTime.Now, // RoleName = "超级管理员", // RoleDesc = String.Empty, // TenantId = tenantUser.TenantId, //}; var count = await SysUserDao.SaveChangesAsync(); return(count); }