public async Task GetByIdAsync() { var role = await _identityRoleManager.FindByIdAsync(_testData.RoleModeratorId.ToString()); role.ShouldNotBeNull(); role.Name.ShouldBe("moderator"); }
public override async Task <IActionResult> Delete(int id) { Role role = await roleManager.FindByIdAsync(id.ToString()); if (role != null) { IdentityResult result = await roleManager.DeleteAsync(role); if (result.Succeeded) { return(NoContent()); } } ModelState.AddModelError("Errors", "Role doesn't exists."); return(NotFound()); }
public async Task <SearchResponseData> GetMembersAsync(int roleId, SearchParams parameters, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); var role = await roleManager.FindByIdAsync(roleId.ToString()); if (role != null) { var members = from userRoles in DbContext.Set <UserRole>() join users in DbContext.Set <User>() on userRoles.UserId equals users.Id where userRoles.RoleId == roleId && userRoles.UserId == users.Id select users; return(await members .Search <User, int>(parameters) .ToListAsync <User>(parameters, cancellationToken)); } return(null); }
/// <summary> /// Finds role by name asynchronously /// </summary> /// <param name="roleId"></param> /// <returns></returns> public Task <IdentityRole> FindByIdAsync(string roleId) { return(_roleManager.FindByIdAsync(roleId)); }