Class NewsletterSubscriberStore
SQL Server newsletter subscriber store implementation. Manages persistence and retrieval of newsletter subscribers from the database.
Implements
Inherited Members
Namespace: DataWeb.Newsletter.SqlServer
Assembly: DataWeb.Data.SqlServer.dll
Syntax
public class NewsletterSubscriberStore : INewsletterSubscriberStore
Constructors
NewsletterSubscriberStore(ISqlHelper)
SQL Server newsletter subscriber store implementation. Manages persistence and retrieval of newsletter subscribers from the database.
Declaration
public NewsletterSubscriberStore(ISqlHelper sqlHelper)
Parameters
| Type | Name | Description |
|---|---|---|
| ISqlHelper | sqlHelper |
Properties
Name
Gets the name of the store.
Declaration
public string Name { get; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
ConvertStatusToString(SubscriberStatus)
Converts a subscriber status to its string representation.
Declaration
public static string ConvertStatusToString(SubscriberStatus status)
Parameters
| Type | Name | Description |
|---|---|---|
| SubscriberStatus | status | The subscriber status to convert. |
Returns
| Type | Description |
|---|---|
| string | String representation of the status. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | If status is not a valid value. |
ConvertStringToStatus(string)
Converts a string to the corresponding subscriber status.
Declaration
public SubscriberStatus ConvertStringToStatus(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | String representing the status. Cannot be null. |
Returns
| Type | Description |
|---|---|
| SubscriberStatus | Corresponding SubscriberStatus. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If value is null. |
| ArgumentOutOfRangeException | If value does not correspond to any valid status. |
DeleteAsync(string, CancellationToken)
Permanently deletes a newsletter subscriber from the database.
Declaration
public Task DeleteAsync(string id, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | Identifier of the subscriber to delete. Cannot be null or empty. |
| CancellationToken | cancellationToken | Token to cancel the asynchronous operation. |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If id is null or empty. |
DeserializeAdditionalValues(string)
Deserializes a JSON string into a list of additional values. Returns an empty list if the value is null or empty.
Declaration
public List<NewsletterSubscriber.AdditionalValue> DeserializeAdditionalValues(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | value | JSON string to deserialize. |
Returns
| Type | Description |
|---|---|
| List<NewsletterSubscriber.AdditionalValue> | List of deserialized additional values, or empty list if value is null or empty. |
GetSubscriberAsync(NewsletterSubscriberFilter, CancellationToken)
Retrieves a single newsletter subscriber based on the specified filter criteria.
Declaration
public Task<NewsletterSubscriber> GetSubscriberAsync(NewsletterSubscriberFilter filter, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| NewsletterSubscriberFilter | filter | Search criteria. Cannot be null. |
| CancellationToken | cancellationToken | Token to cancel the asynchronous operation. |
Returns
| Type | Description |
|---|---|
| Task<NewsletterSubscriber> | The subscriber found, or null if not found. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If filter is null. |
GetSubscriberCountAsync(NewsletterSubscriberFilter, CancellationToken)
Retrieves the total count of newsletter subscribers based on the specified filters.
Declaration
public Task<long> GetSubscriberCountAsync(NewsletterSubscriberFilter filter, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| NewsletterSubscriberFilter | filter | Search criteria. Cannot be null. |
| CancellationToken | cancellationToken | Token to cancel the asynchronous operation. |
Returns
| Type | Description |
|---|---|
| Task<long> | Number of subscribers matching the filter criteria. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If filter is null. |
GetSubscribersAsync(NewsletterSubscriberFilter, CancellationToken)
Retrieves a collection of newsletter subscribers based on the specified filters.
Declaration
public Task<IEnumerable<NewsletterSubscriber>> GetSubscribersAsync(NewsletterSubscriberFilter filter, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| NewsletterSubscriberFilter | filter | Search criteria. Cannot be null. |
| CancellationToken | cancellationToken | Token to cancel the asynchronous operation. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<NewsletterSubscriber>> | Collection of subscribers matching the filter criteria. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | If filter is null. |
RemoveGroupAsync(string, string, DateTimeOffset, CancellationToken)
Removes a specific group from the subscriber's group list.
Declaration
public Task RemoveGroupAsync(string id, string group, DateTimeOffset modificationDate, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | Identifier of the subscriber. Cannot be null or empty. |
| string | group | Group name to remove. Cannot be null or empty. |
| DateTimeOffset | modificationDate | Date and time of the modification. |
| CancellationToken | cancellationToken | Token to cancel the asynchronous operation. |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If id or group is null or empty. |
SetAsync(NewsletterSubscriber, CancellationToken)
Saves a subscriber (inserts if new, updates if existing).
Declaration
public Task SetAsync(NewsletterSubscriber subscriber, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| NewsletterSubscriber | subscriber | Subscriber to save. Cannot be null and must have a valid Id. |
| CancellationToken | cancellationToken | Token to cancel the asynchronous operation. |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If subscriber or its Id is null or empty. |
SetStatusAsync(string, SubscriberStatus, DateTimeOffset, CancellationToken)
Updates the status of a newsletter subscriber.
Declaration
public Task SetStatusAsync(string id, SubscriberStatus status, DateTimeOffset modificationDate, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | Identifier of the subscriber. Cannot be null or empty. |
| SubscriberStatus | status | New status to set. |
| DateTimeOffset | modificationDate | Date and time of the modification. |
| CancellationToken | cancellationToken | Token to cancel the asynchronous operation. |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If id is null or empty. |