Class UserSettingStore
SQL Server implementation of the user settings store, managing user-specific configuration and preferences.
Implements
Inherited Members
Namespace: DataWeb.Identity.SqlServer
Assembly: DataWeb.Data.SqlServer.dll
Syntax
public class UserSettingStore : IUserSettingStore
Remarks
Provides methods to retrieve, create, update, and delete user settings with support for:
- Hierarchical navigation paths for organizing settings
- Named settings with associated values
- Upsert operations (insert if not exists, otherwise update)
- Optional filtering by navigation path All queries are parametrized to prevent SQL injection.
Constructors
UserSettingStore(ISqlHelper)
SQL Server implementation of the user settings store, managing user-specific configuration and preferences.
Declaration
public UserSettingStore(ISqlHelper sqlHelper)
Parameters
| Type | Name | Description |
|---|---|---|
| ISqlHelper | sqlHelper |
Remarks
Provides methods to retrieve, create, update, and delete user settings with support for:
- Hierarchical navigation paths for organizing settings
- Named settings with associated values
- Upsert operations (insert if not exists, otherwise update)
- Optional filtering by navigation path 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
ExistsAsync(string, string, string, CancellationToken)
Determines whether a user setting exists.
Declaration
public Task<bool> ExistsAsync(string userIdMaster, string name, string navigationPath = null, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userIdMaster | The user ID. Must not be null or empty. |
| string | name | The setting name. Must not be null or empty. |
| string | navigationPath | The optional navigation path for organizing settings. |
| CancellationToken | cancellationToken | Cancellation token for the async operation. |
Returns
| Type | Description |
|---|---|
| Task<bool> | True if the setting exists; otherwise, false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when userIdMaster or name is null or empty. |
GetSettingAsync(UserSettingFilter, CancellationToken)
Retrieves a single user setting based on the provided filter criteria.
Declaration
public Task<UserSetting> GetSettingAsync(UserSettingFilter filter, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| UserSettingFilter | filter | Filter criteria for the setting. Must not be null. |
| CancellationToken | cancellationToken | Cancellation token for the async operation. |
Returns
| Type | Description |
|---|---|
| Task<UserSetting> | The first UserSetting object matching the filter criteria, or null if none found. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when filter is null. |
GetSettingValueAsync(string, string, string, CancellationToken)
Retrieves the value of a specific user setting.
Declaration
public Task<string> GetSettingValueAsync(string userIdMaster, string name, string navigationPath = null, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userIdMaster | The user ID. Must not be null or empty. |
| string | name | The setting name. Must not be null or empty. |
| string | navigationPath | The optional navigation path for organizing settings. |
| CancellationToken | cancellationToken | Cancellation token for the async operation. |
Returns
| Type | Description |
|---|---|
| Task<string> | The setting value as a string, or null if not found. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when userIdMaster or name is null or empty. |
GetSettingsAsync(UserSettingFilter, CancellationToken)
Retrieves a collection of user settings based on the provided filter criteria.
Declaration
public Task<IEnumerable<UserSetting>> GetSettingsAsync(UserSettingFilter filter, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| UserSettingFilter | filter | Filter criteria including ID, UserIdMaster, NavigationPath, and Name. Must not be null. |
| CancellationToken | cancellationToken | Cancellation token for the async operation. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<UserSetting>> | An enumerable collection of UserSetting objects matching the filter criteria. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when filter is null. |
RemoveAllAsync(string, CancellationToken)
Removes all settings for a user.
Declaration
public Task RemoveAllAsync(string userIdMaster, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userIdMaster | The user ID. Must not be null or empty. |
| CancellationToken | cancellationToken | Cancellation token for the async operation. |
Returns
| Type | Description |
|---|---|
| Task |
Remarks
This operation cannot be undone. All settings for the user will be permanently deleted.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when userIdMaster is null or empty. |
RemoveAsync(string, string, string, CancellationToken)
Removes a specific user setting.
Declaration
public Task RemoveAsync(string userIdMaster, string name, string navigationPath = null, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userIdMaster | The user ID. Must not be null or empty. |
| string | name | The setting name. Must not be null or empty. |
| string | navigationPath | The optional navigation path for organizing settings. |
| CancellationToken | cancellationToken | Cancellation token for the async operation. |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when userIdMaster or name is null or empty. |
SetAsync(string, string, string, string, CancellationToken)
Creates or updates a user setting (upsert operation).
Declaration
public Task SetAsync(string userIdMaster, string name, string value, string navigationPath = null, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userIdMaster | The user ID. Must not be null or empty. |
| string | name | The setting name. Must not be null or empty. |
| string | value | The setting value. Must not be null or empty. |
| string | navigationPath | The optional navigation path for organizing settings. |
| CancellationToken | cancellationToken | Cancellation token for the async operation. |
Returns
| Type | Description |
|---|---|
| Task |
Remarks
If the setting exists, it updates the value; otherwise, it creates a new setting.
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when userIdMaster, name, or value is null or empty. |