feat: add Configuration gRPC service and queries for club settings and features
This commit is contained in:
+24
-17
@@ -26,30 +26,37 @@ public class GetVATRateQueryHandler : IRequestHandler<GetVATRateQuery, GetVATRat
|
||||
|
||||
try
|
||||
{
|
||||
// دریافت نرخ مالیات از تنظیمات سیستم
|
||||
// دریافت تنظیمات VAT از CMS
|
||||
// Scope: VAT = 4
|
||||
var rateConfig = await _context.Configuration.GetConfigurationByKeyAsync(
|
||||
new GetConfigurationByKeyRequest { Key = "VAT.Rate" },
|
||||
var allConfigs = await _context.Configuration.GetAllConfigurationsAsync(
|
||||
new GetAllConfigurationsRequest
|
||||
{
|
||||
Filter = new GetAllConfigurationsFilter
|
||||
{
|
||||
Scope = 4, // VAT scope
|
||||
IsActive = true
|
||||
}
|
||||
},
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
if (rateConfig != null && !string.IsNullOrEmpty(rateConfig.Value))
|
||||
if (allConfigs?.Models != null)
|
||||
{
|
||||
if (double.TryParse(rateConfig.Value, out var rate))
|
||||
foreach (var config in allConfigs.Models)
|
||||
{
|
||||
response.VatRate = rate;
|
||||
response.VatPercentage = (int)(rate * 100);
|
||||
if (config.Key == "Shop.VAT" && !string.IsNullOrEmpty(config.Value))
|
||||
{
|
||||
if (double.TryParse(config.Value, out var rate))
|
||||
{
|
||||
response.VatRate = rate;
|
||||
response.VatPercentage = (int)(rate * 100);
|
||||
}
|
||||
}
|
||||
else if (config.Key == "IsEnabled" && !string.IsNullOrEmpty(config.Value))
|
||||
{
|
||||
response.IsEnabled = bool.TryParse(config.Value, out var enabled) && enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// دریافت وضعیت فعال بودن مالیات
|
||||
var enabledConfig = await _context.Configuration.GetConfigurationByKeyAsync(
|
||||
new GetConfigurationByKeyRequest { Key = "VAT.IsEnabled" },
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
if (enabledConfig != null && !string.IsNullOrEmpty(enabledConfig.Value))
|
||||
{
|
||||
response.IsEnabled = bool.TryParse(enabledConfig.Value, out var enabled) && enabled;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user