/// <summary> /// 修改角色 /// </summary> /// <param name="incrementRoleParam"></param> /// <param name="currentUser"></param> /// <returns></returns> public async Task <BaseResponseModel> ModifyRoleAsync(IncrementRoleParam incrementRoleParam, UserCacheBo currentUser) { var result = new ResponseModel <string>(); var db = SysRoleDao.CurrentDbContext; if (await db.SysRoles.AnyAsync(c => c.TenantId == currentUser.TenantId && !c.Deleted && c.RoleName == incrementRoleParam.RoleName && c.RoleId != incrementRoleParam.RoleId)) { return(result.Fail("角色名已存在")); } var checkResult = await RoleIdCheckAsync(incrementRoleParam.RoleId, currentUser); if (!checkResult.IsNullOrEmpty()) { return(result.Fail(checkResult)); } var role = await db.SysRoles.FirstOrDefaultAsync(c => !c.Deleted && c.RoleId == incrementRoleParam.RoleId && c.TenantId == currentUser.TenantId); role.RoleName = incrementRoleParam.RoleName; role.RoleDesc = incrementRoleParam.RoleDesc ?? ""; role.UpdatedBy = currentUser.UserId; role.UpdatedTime = DateTime.Now; var count = await db.SaveChangesAsync(); return(count > 0 ? result.Succeed("修改成功") : result.Fail("修改失败", "修改失败")); }
/// <summary> /// 新增角色 /// </summary> /// <param name="incrementRoleParam"></param> /// <param name="currentUser"></param> /// <returns></returns> public async Task <BaseResponseModel> AddRoleAsync(IncrementRoleParam incrementRoleParam, UserCacheBo currentUser) { var result = new ResponseModel <string>(); var db = SysRoleDao.CurrentDbContext; SysRoleDao.CloseTracking(); if (await db.SysRoles.CountAsync(c => c.TenantId == currentUser.TenantId && !c.Deleted) > 500) { return(result.Fail("一个租户下角色上限为500个")); } if (await db.SysRoles.AnyAsync(c => c.TenantId == currentUser.TenantId && !c.Deleted && c.RoleName == incrementRoleParam.RoleName)) { return(result.Fail("角色名已存在")); } var role = new SysRole() { TenantId = currentUser.TenantId, CreatedBy = currentUser.UserId, CreatedTime = DateTime.Now, Deleted = false, RoleDesc = incrementRoleParam.RoleDesc ?? "", RoleName = incrementRoleParam.RoleName, }; await db.SysRoles.AddAsync(role); var count = await db.SaveChangesAsync(); return(count > 0 ? result.Succeed("添加成功") : result.Fail("添加失败")); }
public async Task <ActionResult> ModifyRole(IncrementRoleParam param) { var result = await RoleBll.ModifyRoleAsync(param, CurrentUser); return(MyJson(result)); }