45edcf5e5f
This commit removes the obsolete EventAssignment class from Core.Entities and introduces new models in Core.Models, including AssignmentParameters, AssignmentRequirement, PartialTeam, and StudentEventStatistics. The changes enhance the organization of assignment-related data and improve the overall structure of the codebase. Additionally, several files have been updated to include references to the new Core.Models namespace, ensuring consistency across the application.
110 lines
3.7 KiB
C#
110 lines
3.7 KiB
C#
using Core.Entities;
|
|
using Core.Models;
|
|
|
|
namespace Core.Validation.Rules.BaseRules;
|
|
|
|
/// <summary>
|
|
/// Base class for validation rules that check event counts against thresholds
|
|
/// Eliminates duplication across TooManyEvents, TooFewEvents, and TooManyRegionalEvents rules
|
|
/// </summary>
|
|
public abstract class EventCountThresholdRuleBase : IValidationRule<StudentEventStatistics>
|
|
{
|
|
/// <summary>
|
|
/// Get the actual count to validate
|
|
/// </summary>
|
|
protected abstract int GetCount(StudentEventStatistics statistics);
|
|
|
|
/// <summary>
|
|
/// Get the threshold value from configuration
|
|
/// </summary>
|
|
protected abstract int GetThreshold(ValidationConfiguration config);
|
|
|
|
/// <summary>
|
|
/// Check if the count violates the threshold
|
|
/// </summary>
|
|
protected abstract bool ViolatesThreshold(int count, int threshold);
|
|
|
|
/// <summary>
|
|
/// Get the base severity from configuration (can be overridden for critical thresholds)
|
|
/// </summary>
|
|
protected abstract ValidationSeverity GetBaseSeverity(ValidationConfiguration config);
|
|
|
|
/// <summary>
|
|
/// Optionally check for critical threshold that escalates to Error severity
|
|
/// Returns null if no critical threshold applies
|
|
/// </summary>
|
|
protected virtual int? GetCriticalThreshold(ValidationConfiguration config) => null;
|
|
|
|
/// <summary>
|
|
/// Check if count violates critical threshold (for escalation to Error)
|
|
/// </summary>
|
|
protected virtual bool ViolatesCriticalThreshold(int count, int criticalThreshold) => false;
|
|
|
|
/// <summary>
|
|
/// The validation warning code
|
|
/// </summary>
|
|
protected abstract string Code { get; }
|
|
|
|
/// <summary>
|
|
/// Build the display message
|
|
/// </summary>
|
|
protected abstract string GetMessage(int count, int threshold);
|
|
|
|
/// <summary>
|
|
/// Icon identifier for the warning (can be null)
|
|
/// </summary>
|
|
protected virtual string? IconIdentifier => null;
|
|
|
|
/// <summary>
|
|
/// Build additional metadata beyond the standard fields
|
|
/// </summary>
|
|
protected virtual Dictionary<string, object> BuildAdditionalMetadata(StudentEventStatistics statistics, ValidationConfiguration config)
|
|
{
|
|
return new Dictionary<string, object>();
|
|
}
|
|
|
|
public ValidationWarning? Validate(StudentEventStatistics entity, ValidationConfiguration config)
|
|
{
|
|
var count = GetCount(entity);
|
|
var threshold = GetThreshold(config);
|
|
|
|
if (!ViolatesThreshold(count, threshold))
|
|
return null;
|
|
|
|
// Check for critical threshold escalation
|
|
var severity = GetBaseSeverity(config);
|
|
var criticalThreshold = GetCriticalThreshold(config);
|
|
if (criticalThreshold.HasValue && ViolatesCriticalThreshold(count, criticalThreshold.Value))
|
|
{
|
|
severity = ValidationSeverity.Error;
|
|
}
|
|
|
|
var metadata = new Dictionary<string, object>
|
|
{
|
|
{ "StudentId", entity.Student.Id },
|
|
{ "StudentName", entity.Student.FirstNameLastName },
|
|
{ "EventCount", entity.EventCount }
|
|
};
|
|
|
|
// Add any additional metadata from derived class
|
|
foreach (var kvp in BuildAdditionalMetadata(entity, config))
|
|
{
|
|
metadata[kvp.Key] = kvp.Value;
|
|
}
|
|
|
|
return new ValidationWarning
|
|
{
|
|
Code = Code,
|
|
Message = GetMessage(count, threshold),
|
|
Severity = severity,
|
|
Context = ValidationContext.StudentAssignment,
|
|
IconIdentifier = IconIdentifier,
|
|
Metadata = metadata
|
|
};
|
|
}
|
|
|
|
public bool AppliesTo(ValidationContext context) =>
|
|
context == ValidationContext.StudentAssignment ||
|
|
context == ValidationContext.StudentRegistration;
|
|
}
|