/// <summary>异步更新一个角色</summary> /// <param name="role"></param> /// <returns>更新任务</returns> public Task <IdentityResult> UpdateAsync(TRole role, CancellationToken cancellationToken) { if (role == null) { throw new ArgumentNullException("role"); } return(RunTask(() => { _objectStorage.Update(role); var roleId = role.Id; var userRoles = _objectStorage.FindByQuery <UserRole, ObjectId>(p => p.RoleId == roleId, p => p.Id, true); if (userRoles != null && userRoles.Count > 0) { userRoles.ForEach(p => { p.RoleName = role.Name; _objectStorage.Update(p); }); } }, "更新角色")); }
/// <summary>Find a user by name</summary> /// <param name="userName">用户名</param> /// <returns>返回查询到的用户实体</returns> public Task <TUser> FindByNameAsync(string userName, CancellationToken cancellationToken) { if (string.IsNullOrEmpty(userName)) { throw new ArgumentException("Null or empty argument: userName"); } return(TaskHelper.RunTask(() => { var result = _objectStorage.FindByQuery <TUser, string>(p => p.UserName == userName, p => p.UserName, false); // Should I throw if > 1 user? if (result != null && result.Count == 1) { return result[0]; } return default(TUser); })); }