public async Task <ApiResult> SetRoleAsync(SetUserRoleInput input) { //分配角色 if (input.Status) { var model = await GetModelAsync(d => d.UserId == input.UserId && d.RoleId == input.RoleId && d.Status); if (model.Id > 0) { return(new ApiResult("已经存在该角色了", 500)); } R_User_Role addModel = new R_User_Role() { UserId = input.UserId, RoleId = input.RoleId, CreateTime = DateTime.Now, Status = true }; await AddAsync(addModel); } else { await UpdateAsync(d => new R_User_Role() { Status = false }, d => d.UserId == input.UserId && d.RoleId == input.RoleId); // await DeleteAsync(d => d.UserId == input.UserId && d.RoleId == input.RoleId); //删除的话 要把授权的权限都要删除掉 风险比较高。 } return(new ApiResult()); }
public async Task <ApiResult> SetRole([FromBody] SetUserRoleInput setUserRoleInput) { return(await _r_User_RoleService.SetRoleAsync(setUserRoleInput)); }
/// <summary> /// 设置 用户角色 /// </summary> /// <param name="input">用户角色Input</param> /// <returns>业务操作结果</returns> public async Task SetUserRoles(SetUserRoleInput input) { var user = await UserManager.GetUserByIdAsync(input.UserId); await UserManager.SetRoles(user, input.RoleNames); }