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)
49 lines
2.1 KiB
C#
49 lines
2.1 KiB
C#
namespace CMSMicroservice.Application.ConfigurationCQ.Commands.SetConfigurationValue;
|
|
|
|
public class SetConfigurationValueCommandValidator : AbstractValidator<SetConfigurationValueCommand>
|
|
{
|
|
public SetConfigurationValueCommandValidator()
|
|
{
|
|
RuleFor(x => x.Scope)
|
|
.IsInEnum()
|
|
.WithMessage("محدوده تنظیمات معتبر نیست");
|
|
|
|
RuleFor(x => x.Key)
|
|
.NotEmpty()
|
|
.WithMessage("کلید تنظیمات الزامی است")
|
|
.MaximumLength(100)
|
|
.WithMessage("کلید تنظیمات نمیتواند بیشتر از 100 کاراکتر باشد")
|
|
.Matches(@"^[a-zA-Z0-9_\.]+$")
|
|
.WithMessage("کلید تنظیمات فقط میتواند شامل حروف انگلیسی، اعداد، نقطه و آندرلاین باشد");
|
|
|
|
RuleFor(x => x.Value)
|
|
.NotEmpty()
|
|
.WithMessage("مقدار تنظیمات الزامی است")
|
|
.MaximumLength(2000)
|
|
.WithMessage("مقدار تنظیمات نمیتواند بیشتر از 2000 کاراکتر باشد");
|
|
|
|
RuleFor(x => x.Description)
|
|
.MaximumLength(500)
|
|
.WithMessage("توضیحات نمیتواند بیشتر از 500 کاراکتر باشد")
|
|
.When(x => !string.IsNullOrEmpty(x.Description));
|
|
|
|
RuleFor(x => x.ChangeReason)
|
|
.MaximumLength(500)
|
|
.WithMessage("دلیل تغییر نمیتواند بیشتر از 500 کاراکتر باشد")
|
|
.When(x => !string.IsNullOrEmpty(x.ChangeReason));
|
|
}
|
|
|
|
public Func<object, string, Task<IEnumerable<string>>> ValidateValue => async (model, propertyName) =>
|
|
{
|
|
var result = await ValidateAsync(
|
|
ValidationContext<SetConfigurationValueCommand>.CreateWithOptions(
|
|
(SetConfigurationValueCommand)model,
|
|
x => x.IncludeProperties(propertyName)));
|
|
|
|
if (result.IsValid)
|
|
return Array.Empty<string>();
|
|
|
|
return result.Errors.Select(e => e.ErrorMessage);
|
|
};
|
|
}
|