68 lines
2.3 KiB
C#
68 lines
2.3 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using System.Text;
|
|
using Compliance.Domain.Models;
|
|
using Compliance.DTOs;
|
|
|
|
namespace Compliance.Services.ValidationRules
|
|
{
|
|
public class BasicInformationValidationRule : IValidationRule
|
|
{
|
|
private const string RULE_NAME = "Basic Information Validation";
|
|
public int Priority => 1; // Should run first
|
|
|
|
public async Task<ValidationResult> ValidateAsync(
|
|
BillComplianceRequest request,
|
|
DistributorInformation distributorInfo,
|
|
Client clientInfo)
|
|
{
|
|
var isValid = true;
|
|
var message = new StringBuilder();
|
|
|
|
// Validate Consumer SmartCode match
|
|
if (request.SmartCode != clientInfo.SmartCode)
|
|
{
|
|
isValid = false;
|
|
message.AppendLine("SmartCode in bill doesn't match client registration.");
|
|
}
|
|
|
|
// Validate Distributor match
|
|
if (request.DistributorName != distributorInfo.Name)
|
|
{
|
|
isValid = false;
|
|
message.AppendLine("Distributor name in bill doesn't match distributor information.");
|
|
}
|
|
|
|
// Validate Consumer Classification
|
|
if (!string.IsNullOrEmpty(clientInfo.ConsumerGroup))
|
|
{
|
|
if (clientInfo.ConsumerGroup != request.ConsumerGroup)
|
|
{
|
|
isValid = false;
|
|
message.AppendLine("Consumer group in bill doesn't match client registration.");
|
|
}
|
|
|
|
if (clientInfo.Subgroup != request.Subgroup)
|
|
{
|
|
isValid = false;
|
|
message.AppendLine("Consumer subgroup in bill doesn't match client registration.");
|
|
}
|
|
}
|
|
|
|
// Validate Supply Voltage
|
|
if (!string.IsNullOrEmpty(clientInfo.SupplyVoltage) &&
|
|
clientInfo.SupplyVoltage != request.SupplyVoltage)
|
|
{
|
|
isValid = false;
|
|
message.AppendLine("Supply voltage in bill doesn't match client registration.");
|
|
}
|
|
|
|
return await Task.FromResult(new ValidationResult
|
|
{
|
|
IsValid = isValid,
|
|
RuleName = RULE_NAME,
|
|
Message = message.ToString().TrimEnd()
|
|
});
|
|
}
|
|
}
|
|
} |