f6fa070067
Implemented complete CQRS pattern for System Configuration management:
Commands:
- SetConfigurationValueCommand: Create or update configurations with history tracking
- DeactivateConfigurationCommand: Deactivate configurations with audit trail
Queries:
- GetConfigurationByKeyQuery: Retrieve configuration by Scope and Key
- GetAllConfigurationsQuery: List all configurations with filters and pagination
- GetConfigurationHistoryQuery: View complete audit history for any configuration
Features:
- All commands include FluentValidation validators
- History recording to SystemConfigurationHistory table
- Pagination support for list queries
- DTOs for clean data transfer
- Null-safe implementations
Updated:
- IApplicationDbContext: Added 11 new DbSets for network-club entities
- GlobalUsings: Added new entity namespaces
Build Status: ✅ Success (0 errors, 184 warnings in legacy code)
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
namespace CMSMicroservice.Application.ConfigurationCQ.Queries.GetConfigurationByKey;
|
|
|
|
public class GetConfigurationByKeyQueryHandler : IRequestHandler<GetConfigurationByKeyQuery, ConfigurationDto?>
|
|
{
|
|
private readonly IApplicationDbContext _context;
|
|
|
|
public GetConfigurationByKeyQueryHandler(IApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<ConfigurationDto?> Handle(GetConfigurationByKeyQuery request, CancellationToken cancellationToken)
|
|
{
|
|
var config = await _context.SystemConfigurations
|
|
.AsNoTracking()
|
|
.Where(x => x.Scope == request.Scope && x.Key == request.Key)
|
|
.FirstOrDefaultAsync(cancellationToken);
|
|
|
|
if (config == null)
|
|
return null;
|
|
|
|
return new ConfigurationDto
|
|
{
|
|
Id = config.Id,
|
|
Scope = config.Scope,
|
|
Key = config.Key,
|
|
Value = config.Value,
|
|
Description = config.Description,
|
|
IsActive = config.IsActive,
|
|
Created = config.Created,
|
|
LastModified = config.LastModified
|
|
};
|
|
}
|
|
}
|