Class UserStore
SQL Server implementation of the user store, managing application users and their security credentials.
Implements
Inherited Members
Namespace: DataWeb.Identity.SqlServer
Assembly: DataWeb.Data.SqlServer.dll
Syntax
public class UserStore : IUserStore
Remarks
Provides methods to retrieve, manage, and validate user accounts, including:
- User queries with filtering by username, email, or ID
- Role management for users
- Security stamp and lockout status management
- Username and email availability validation All queries are parametrized to prevent SQL injection.
Constructors
UserStore(ISqlHelper)
SQL Server implementation of the user store, managing application users and their security credentials.
Declaration
public UserStore(ISqlHelper sqlHelper)
Parameters
| Type | Name | Description |
|---|---|---|
| ISqlHelper | sqlHelper |
Remarks
Provides methods to retrieve, manage, and validate user accounts, including:
- User queries with filtering by username, email, or ID
- Role management for users
- Security stamp and lockout status management
- Username and email availability validation All queries are parametrized to prevent SQL injection.
Properties
Name
Gets the name of the store implementation.
Declaration
public string Name { get; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
GetRolesForUserAsync(string, CancellationToken)
Retrieves the roles assigned to a user.
Declaration
public Task<string[]> GetRolesForUserAsync(string userName, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userName | The username. Must not be null or empty. |
| CancellationToken | cancellationToken | Cancellation token for the async operation. |
Returns
| Type | Description |
|---|---|
| Task<string[]> | An array of role names assigned to the user. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when userName is null or empty. |
GetUserAsync(UserFilter, CancellationToken)
Retrieves a single user based on the provided filter criteria.
Declaration
public Task<UserData> GetUserAsync(UserFilter filter, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| UserFilter | filter | Filter criteria for the user. Must not be null. |
| CancellationToken | cancellationToken | Cancellation token for the async operation. |
Returns
| Type | Description |
|---|---|
| Task<UserData> | The first UserData object matching the filter criteria, or null if none found. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when filter is null. |
GetUserValueAsync(UserFilter, string, CancellationToken)
Retrieves a specific user property value.
Declaration
public Task<object> GetUserValueAsync(UserFilter filter, string name, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| UserFilter | filter | Filter criteria to identify the user. Must not be null. |
| string | name | The property name to retrieve. Must be a valid user field name. |
| CancellationToken | cancellationToken | Cancellation token for the async operation. |
Returns
| Type | Description |
|---|---|
| Task<object> | The value of the requested property, or null if not found. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when filter or name is null. |
| ArgumentException | Thrown when name contains invalid field name characters. |
GetUsersAsync(UserFilter, CancellationToken)
Retrieves a collection of users based on the provided filter criteria.
Declaration
public Task<IEnumerable<UserData>> GetUsersAsync(UserFilter filter, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| UserFilter | filter | Filter criteria including username, email, IdMaster, and publish mode. Must not be null. |
| CancellationToken | cancellationToken | Cancellation token for the async operation. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<UserData>> | An enumerable collection of UserData objects matching the filter criteria. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when filter is null. |
IsEmailAvailableAsync(string, string, CancellationToken)
Determines whether an email address is available for registration or update.
Declaration
public Task<bool> IsEmailAvailableAsync(string email, string userIdMaster, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | The email address to check. Must not be null or empty. |
|
| string | userIdMaster | The ID of the user being updated, to exclude from the availability check. Must not be null or empty. |
| CancellationToken | cancellationToken | Cancellation token for the async operation. |
Returns
| Type | Description |
|---|---|
| Task<bool> | True if the email is available; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when email or userIdMaster is null or empty. |
IsUserNameAvailableAsync(string, string, CancellationToken)
Determines whether a username is available for registration or update.
Declaration
public Task<bool> IsUserNameAvailableAsync(string userName, string userIdMaster, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userName | The username to check. Must not be null or empty. |
| string | userIdMaster | The ID of the user being updated, to exclude from the availability check. Must not be null or empty. |
| CancellationToken | cancellationToken | Cancellation token for the async operation. |
Returns
| Type | Description |
|---|---|
| Task<bool> | True if the username is available; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when userName or userIdMaster is null or empty. |