Add comprehensive validation system with runtime configuration
Implements a flexible validation framework for student rankings, team assignments, and team composition with administrator-configurable rules and thresholds. Validation System: - Reflection-based rule discovery eliminates manual registration - Base classes (RequiredEventTypeRuleBase, EventCountThresholdRuleBase) reduce code duplication by ~250 lines - 12 validation rules covering event requirements, counts, and team constraints - Configurable severity levels (Warning/Error) per rule type - ValidationService with caching for optimal performance - Rules apply contextually (StudentRanking, StudentAssignment, TeamComposition) Configuration & Admin UI: - ValidationSettings admin page for editing thresholds and severity levels - ChapterSettings admin page for editing chapter information - Settings stored in Data/appsettings.json for runtime configuration - JSON config works in both development and production environments - Auto-creates Data directory and config template on first run User Experience: - ValidationWarnings component displays inline warnings/errors - Integrated in Event Ranking, Registration, and Team Assignment pages - Color-coded severity indicators (warning yellow, error red) - Includes "Too Many Regional Events" rule (max 3 recommended) Technical Improvements: - Template Method pattern for rule base classes - Singleton rule instances with lazy initialization - Configuration loaded via IConfiguration with fallback to defaults - Safe JSON updates preserve other appsettings sections
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
namespace Core.Validation;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interface for all validation rules
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TEntity">Type of entity being validated (Student, Team, StudentEventStatistics, etc.)</typeparam>
|
||||||
|
public interface IValidationRule<TEntity>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Execute the validation rule against an entity
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">Entity to validate</param>
|
||||||
|
/// <param name="config">Validation configuration</param>
|
||||||
|
/// <returns>Validation warning if rule is violated, null otherwise</returns>
|
||||||
|
ValidationWarning? Validate(TEntity entity, ValidationConfiguration config);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines if this rule applies to the given context
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context">Validation context</param>
|
||||||
|
/// <returns>True if the rule should be executed in this context</returns>
|
||||||
|
bool AppliesTo(ValidationContext context);
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.BaseRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base class for validation rules that check event counts against thresholds for student rankings
|
||||||
|
/// Similar to EventCountThresholdRuleBase but works with Student entities instead of StudentEventStatistics
|
||||||
|
/// </summary>
|
||||||
|
public abstract class EventCountThresholdRankingRuleBase : IValidationRule<Student>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Get the actual count to validate
|
||||||
|
/// </summary>
|
||||||
|
protected abstract int GetCount(Student student);
|
||||||
|
|
||||||
|
/// <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 severity from configuration
|
||||||
|
/// </summary>
|
||||||
|
protected abstract ValidationSeverity GetSeverity(ValidationConfiguration config);
|
||||||
|
|
||||||
|
/// <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(Student student, ValidationConfiguration config)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, object>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ValidationWarning? Validate(Student entity, ValidationConfiguration config)
|
||||||
|
{
|
||||||
|
var count = GetCount(entity);
|
||||||
|
var threshold = GetThreshold(config);
|
||||||
|
|
||||||
|
if (!ViolatesThreshold(count, threshold))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var metadata = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "StudentId", entity.Id },
|
||||||
|
{ "StudentName", entity.FirstNameLastName }
|
||||||
|
};
|
||||||
|
|
||||||
|
// 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 = GetSeverity(config),
|
||||||
|
Context = ValidationContext.StudentRanking,
|
||||||
|
IconIdentifier = IconIdentifier,
|
||||||
|
Metadata = metadata
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AppliesTo(ValidationContext context) =>
|
||||||
|
context == ValidationContext.StudentRanking ||
|
||||||
|
context == ValidationContext.StudentRegistration;
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.BaseRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base class for validation rules that check if a student has been assigned a required event type
|
||||||
|
/// Eliminates duplication across assignment validation rules
|
||||||
|
/// </summary>
|
||||||
|
public abstract class RequiredEventTypeAssignmentRuleBase : IValidationRule<StudentEventStatistics>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Check if this event type is required based on configuration
|
||||||
|
/// </summary>
|
||||||
|
protected abstract bool IsRequired(ValidationConfiguration config);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the student has been assigned this event type
|
||||||
|
/// </summary>
|
||||||
|
protected abstract bool HasEventType(StudentEventStatistics statistics);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the severity level for this rule from configuration
|
||||||
|
/// </summary>
|
||||||
|
protected abstract ValidationSeverity GetSeverity(ValidationConfiguration config);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The validation warning code (e.g., "NO_REGIONAL_EVENT_ASSIGNED")
|
||||||
|
/// </summary>
|
||||||
|
protected abstract string Code { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The display message for the warning
|
||||||
|
/// </summary>
|
||||||
|
protected abstract string Message { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Icon identifier for the warning (e.g., "RegionalEvent")
|
||||||
|
/// </summary>
|
||||||
|
protected abstract string IconIdentifier { get; }
|
||||||
|
|
||||||
|
public ValidationWarning? Validate(StudentEventStatistics entity, ValidationConfiguration config)
|
||||||
|
{
|
||||||
|
if (!IsRequired(config))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (HasEventType(entity))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new ValidationWarning
|
||||||
|
{
|
||||||
|
Code = Code,
|
||||||
|
Message = Message,
|
||||||
|
Severity = GetSeverity(config),
|
||||||
|
Context = ValidationContext.StudentAssignment,
|
||||||
|
IconIdentifier = IconIdentifier,
|
||||||
|
Metadata = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "StudentId", entity.Student.Id },
|
||||||
|
{ "StudentName", entity.Student.FirstNameLastName },
|
||||||
|
{ "EventCount", entity.EventCount }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AppliesTo(ValidationContext context) =>
|
||||||
|
context == ValidationContext.StudentAssignment ||
|
||||||
|
context == ValidationContext.StudentRegistration;
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.BaseRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Base class for validation rules that check if a student has ranked a required event type
|
||||||
|
/// Eliminates duplication across NoRegionalEvent, NoOnSiteActivity, and NoIndividualEvent rules
|
||||||
|
/// </summary>
|
||||||
|
public abstract class RequiredEventTypeRuleBase : IValidationRule<Student>
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Check if this event type is required based on configuration
|
||||||
|
/// </summary>
|
||||||
|
protected abstract bool IsRequired(ValidationConfiguration config);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Check if the student has ranked this event type
|
||||||
|
/// </summary>
|
||||||
|
protected abstract bool HasEventType(Student student);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get the severity level for this rule from configuration
|
||||||
|
/// </summary>
|
||||||
|
protected abstract ValidationSeverity GetSeverity(ValidationConfiguration config);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The validation warning code (e.g., "NO_REGIONAL_EVENT")
|
||||||
|
/// </summary>
|
||||||
|
protected abstract string Code { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The display message for the warning
|
||||||
|
/// </summary>
|
||||||
|
protected abstract string Message { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Icon identifier for the warning (e.g., "RegionalEvent")
|
||||||
|
/// </summary>
|
||||||
|
protected abstract string IconIdentifier { get; }
|
||||||
|
|
||||||
|
public ValidationWarning? Validate(Student entity, ValidationConfiguration config)
|
||||||
|
{
|
||||||
|
if (!IsRequired(config))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (HasEventType(entity))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new ValidationWarning
|
||||||
|
{
|
||||||
|
Code = Code,
|
||||||
|
Message = Message,
|
||||||
|
Severity = GetSeverity(config),
|
||||||
|
Context = ValidationContext.StudentRanking,
|
||||||
|
IconIdentifier = IconIdentifier,
|
||||||
|
Metadata = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "StudentId", entity.Id },
|
||||||
|
{ "StudentName", entity.FirstNameLastName }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AppliesTo(ValidationContext context) =>
|
||||||
|
context == ValidationContext.StudentRanking ||
|
||||||
|
context == ValidationContext.StudentRegistration;
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
using Core.Validation.Rules.BaseRules;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.StudentAssignmentRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation rule that checks if a student has been assigned at least one on-site activity
|
||||||
|
/// </summary>
|
||||||
|
public class NoOnSiteActivityAssignmentRule : RequiredEventTypeAssignmentRuleBase
|
||||||
|
{
|
||||||
|
protected override bool IsRequired(ValidationConfiguration config) => config.RequireOnSiteActivity;
|
||||||
|
|
||||||
|
protected override bool HasEventType(StudentEventStatistics statistics) => statistics.HasOnSiteActivity;
|
||||||
|
|
||||||
|
protected override ValidationSeverity GetSeverity(ValidationConfiguration config) => config.NoOnSiteActivitySeverity;
|
||||||
|
|
||||||
|
protected override string Code => "NO_ONSITE_ACTIVITY_ASSIGNED";
|
||||||
|
|
||||||
|
protected override string Message => "No On-Site Activity";
|
||||||
|
|
||||||
|
protected override string IconIdentifier => "OnSiteActivity";
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
using Core.Validation.Rules.BaseRules;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.StudentAssignmentRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation rule that checks if a student has been assigned at least one regional event
|
||||||
|
/// </summary>
|
||||||
|
public class NoRegionalEventAssignmentRule : RequiredEventTypeAssignmentRuleBase
|
||||||
|
{
|
||||||
|
protected override bool IsRequired(ValidationConfiguration config) => config.RequireRegionalEvent;
|
||||||
|
|
||||||
|
protected override bool HasEventType(StudentEventStatistics statistics) => statistics.HasRegionalEvent;
|
||||||
|
|
||||||
|
protected override ValidationSeverity GetSeverity(ValidationConfiguration config) => config.NoRegionalEventSeverity;
|
||||||
|
|
||||||
|
protected override string Code => "NO_REGIONAL_EVENT_ASSIGNED";
|
||||||
|
|
||||||
|
protected override string Message => "No Regional Event";
|
||||||
|
|
||||||
|
protected override string IconIdentifier => "RegionalEvent";
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
using Core.Validation.Rules.BaseRules;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.StudentAssignmentRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation rule that checks if a student has too few event assignments
|
||||||
|
/// </summary>
|
||||||
|
public class TooFewEventsRule : EventCountThresholdRuleBase
|
||||||
|
{
|
||||||
|
protected override int GetCount(StudentEventStatistics statistics) => statistics.EventCount;
|
||||||
|
|
||||||
|
protected override int GetThreshold(ValidationConfiguration config) => config.MinRecommendedEvents;
|
||||||
|
|
||||||
|
protected override bool ViolatesThreshold(int count, int threshold) => count < threshold;
|
||||||
|
|
||||||
|
protected override ValidationSeverity GetBaseSeverity(ValidationConfiguration config) => config.EventCountSeverity;
|
||||||
|
|
||||||
|
protected override int? GetCriticalThreshold(ValidationConfiguration config) => config.MinCriticalEvents;
|
||||||
|
|
||||||
|
protected override bool ViolatesCriticalThreshold(int count, int criticalThreshold) => count < criticalThreshold;
|
||||||
|
|
||||||
|
protected override string Code => "TOO_FEW_EVENTS";
|
||||||
|
|
||||||
|
protected override string GetMessage(int count, int threshold) =>
|
||||||
|
$"Student has {count} events (min recommended: {threshold})";
|
||||||
|
|
||||||
|
protected override Dictionary<string, object> BuildAdditionalMetadata(StudentEventStatistics statistics, ValidationConfiguration config)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "MinRecommended", config.MinRecommendedEvents },
|
||||||
|
{ "MinCritical", config.MinCriticalEvents }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
using Core.Validation.Rules.BaseRules;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.StudentAssignmentRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation rule that checks if a student has too many event assignments
|
||||||
|
/// </summary>
|
||||||
|
public class TooManyEventsRule : EventCountThresholdRuleBase
|
||||||
|
{
|
||||||
|
protected override int GetCount(StudentEventStatistics statistics) => statistics.EventCount;
|
||||||
|
|
||||||
|
protected override int GetThreshold(ValidationConfiguration config) => config.MaxRecommendedEvents;
|
||||||
|
|
||||||
|
protected override bool ViolatesThreshold(int count, int threshold) => count > threshold;
|
||||||
|
|
||||||
|
protected override ValidationSeverity GetBaseSeverity(ValidationConfiguration config) => config.EventCountSeverity;
|
||||||
|
|
||||||
|
protected override int? GetCriticalThreshold(ValidationConfiguration config) => config.MaxCriticalEvents;
|
||||||
|
|
||||||
|
protected override bool ViolatesCriticalThreshold(int count, int criticalThreshold) => count > criticalThreshold;
|
||||||
|
|
||||||
|
protected override string Code => "TOO_MANY_EVENTS";
|
||||||
|
|
||||||
|
protected override string GetMessage(int count, int threshold) =>
|
||||||
|
$"Student has {count} events (max recommended: {threshold})";
|
||||||
|
|
||||||
|
protected override Dictionary<string, object> BuildAdditionalMetadata(StudentEventStatistics statistics, ValidationConfiguration config)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "MaxRecommended", config.MaxRecommendedEvents },
|
||||||
|
{ "MaxCritical", config.MaxCriticalEvents }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
using Core.Validation.Rules.BaseRules;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.StudentAssignmentRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation rule that checks if a student has too many regional events in their assignments
|
||||||
|
/// </summary>
|
||||||
|
public class TooManyRegionalEventsAssignmentRule : EventCountThresholdRuleBase
|
||||||
|
{
|
||||||
|
protected override int GetCount(StudentEventStatistics statistics) =>
|
||||||
|
statistics.Events.Count(e => e.RegionalEvent);
|
||||||
|
|
||||||
|
protected override int GetThreshold(ValidationConfiguration config) => config.MaxRegionalEvents;
|
||||||
|
|
||||||
|
protected override bool ViolatesThreshold(int count, int threshold) => count > threshold;
|
||||||
|
|
||||||
|
protected override ValidationSeverity GetBaseSeverity(ValidationConfiguration config) =>
|
||||||
|
config.TooManyRegionalEventsSeverity;
|
||||||
|
|
||||||
|
protected override string Code => "TOO_MANY_REGIONAL_EVENTS";
|
||||||
|
|
||||||
|
protected override string GetMessage(int count, int threshold) =>
|
||||||
|
$"Student has {count} regional events (max recommended: {threshold})";
|
||||||
|
|
||||||
|
protected override string? IconIdentifier => "RegionalEvent";
|
||||||
|
|
||||||
|
protected override Dictionary<string, object> BuildAdditionalMetadata(StudentEventStatistics statistics, ValidationConfiguration config)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "RegionalEventCount", GetCount(statistics) },
|
||||||
|
{ "MaxRegionalEvents", config.MaxRegionalEvents }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
using Core.Validation.Rules.BaseRules;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.StudentRankingRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation rule that checks if a student has ranked at least one individual event
|
||||||
|
/// </summary>
|
||||||
|
public class NoIndividualEventRule : RequiredEventTypeRuleBase
|
||||||
|
{
|
||||||
|
protected override bool IsRequired(ValidationConfiguration config) => config.RequireIndividualEvent;
|
||||||
|
|
||||||
|
protected override bool HasEventType(Student student) => student.RankedEvents.Any(e => e.EventFormat == EventFormat.Individual);
|
||||||
|
|
||||||
|
protected override ValidationSeverity GetSeverity(ValidationConfiguration config) => config.NoIndividualEventSeverity;
|
||||||
|
|
||||||
|
protected override string Code => "NO_INDIVIDUAL_EVENT";
|
||||||
|
|
||||||
|
protected override string Message => "No Individual Event";
|
||||||
|
|
||||||
|
protected override string IconIdentifier => "IndividualEvent";
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
using Core.Validation.Rules.BaseRules;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.StudentRankingRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation rule that checks if a student has ranked at least one on-site activity
|
||||||
|
/// </summary>
|
||||||
|
public class NoOnSiteActivityRule : RequiredEventTypeRuleBase
|
||||||
|
{
|
||||||
|
protected override bool IsRequired(ValidationConfiguration config) => config.RequireOnSiteActivity;
|
||||||
|
|
||||||
|
protected override bool HasEventType(Student student) => student.RankedEvents.Any(e => e.OnSiteActivity);
|
||||||
|
|
||||||
|
protected override ValidationSeverity GetSeverity(ValidationConfiguration config) => config.NoOnSiteActivitySeverity;
|
||||||
|
|
||||||
|
protected override string Code => "NO_ONSITE_ACTIVITY";
|
||||||
|
|
||||||
|
protected override string Message => "No On-Site Activity";
|
||||||
|
|
||||||
|
protected override string IconIdentifier => "OnSiteActivity";
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
using Core.Validation.Rules.BaseRules;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.StudentRankingRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation rule that checks if a student has ranked at least one regional event
|
||||||
|
/// </summary>
|
||||||
|
public class NoRegionalEventRule : RequiredEventTypeRuleBase
|
||||||
|
{
|
||||||
|
protected override bool IsRequired(ValidationConfiguration config) => config.RequireRegionalEvent;
|
||||||
|
|
||||||
|
protected override bool HasEventType(Student student) => student.RankedEvents.Any(e => e.RegionalEvent);
|
||||||
|
|
||||||
|
protected override ValidationSeverity GetSeverity(ValidationConfiguration config) => config.NoRegionalEventSeverity;
|
||||||
|
|
||||||
|
protected override string Code => "NO_REGIONAL_EVENT";
|
||||||
|
|
||||||
|
protected override string Message => "No Regional Event";
|
||||||
|
|
||||||
|
protected override string IconIdentifier => "RegionalEvent";
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
using Core.Validation.Rules.BaseRules;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.StudentRankingRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation rule that checks if a student has too many regional events in their rankings
|
||||||
|
/// </summary>
|
||||||
|
public class TooManyRegionalEventsRule : EventCountThresholdRankingRuleBase
|
||||||
|
{
|
||||||
|
protected override int GetCount(Student student) =>
|
||||||
|
student.RankedEvents.Count(e => e.RegionalEvent);
|
||||||
|
|
||||||
|
protected override int GetThreshold(ValidationConfiguration config) => config.MaxRegionalEvents;
|
||||||
|
|
||||||
|
protected override bool ViolatesThreshold(int count, int threshold) => count > threshold;
|
||||||
|
|
||||||
|
protected override ValidationSeverity GetSeverity(ValidationConfiguration config) =>
|
||||||
|
config.TooManyRegionalEventsSeverity;
|
||||||
|
|
||||||
|
protected override string Code => "TOO_MANY_REGIONAL_EVENTS";
|
||||||
|
|
||||||
|
protected override string GetMessage(int count, int threshold) =>
|
||||||
|
$"Student has {count} regional events (max recommended: {threshold})";
|
||||||
|
|
||||||
|
protected override string? IconIdentifier => "RegionalEvent";
|
||||||
|
|
||||||
|
protected override Dictionary<string, object> BuildAdditionalMetadata(Student student, ValidationConfiguration config)
|
||||||
|
{
|
||||||
|
return new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "RegionalEventCount", GetCount(student) },
|
||||||
|
{ "MaxRegionalEvents", config.MaxRegionalEvents }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.TeamRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation rule that checks if a team-based event has an assigned captain
|
||||||
|
/// </summary>
|
||||||
|
public class MissingCaptainRule : IValidationRule<Team>
|
||||||
|
{
|
||||||
|
public ValidationWarning? Validate(Team entity, ValidationConfiguration config)
|
||||||
|
{
|
||||||
|
if (!config.RequireTeamCaptain)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
// Individual events don't need captains
|
||||||
|
if (entity.Event.EventFormat == EventFormat.Individual)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (entity.Captain != null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new ValidationWarning
|
||||||
|
{
|
||||||
|
Code = "MISSING_CAPTAIN",
|
||||||
|
Message = "Team has no captain assigned",
|
||||||
|
Severity = config.MissingCaptainSeverity,
|
||||||
|
Context = ValidationContext.Team,
|
||||||
|
IconIdentifier = "Captain",
|
||||||
|
Metadata = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "TeamId", entity.Id },
|
||||||
|
{ "EventName", entity.Event.Name },
|
||||||
|
{ "TeamSize", entity.Students.Count }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AppliesTo(ValidationContext context) =>
|
||||||
|
context == ValidationContext.Team;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.TeamRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation rule that checks if a team has more members than the maximum allowed
|
||||||
|
/// </summary>
|
||||||
|
public class TeamSizeTooLargeRule : IValidationRule<Team>
|
||||||
|
{
|
||||||
|
public ValidationWarning? Validate(Team entity, ValidationConfiguration config)
|
||||||
|
{
|
||||||
|
// Individual events don't have team size requirements
|
||||||
|
if (entity.Event.EventFormat == EventFormat.Individual)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var actualSize = entity.Students.Count;
|
||||||
|
var maxSize = entity.Event.MaxTeamSize;
|
||||||
|
|
||||||
|
if (actualSize <= maxSize)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new ValidationWarning
|
||||||
|
{
|
||||||
|
Code = "TEAM_SIZE_TOO_LARGE",
|
||||||
|
Message = $"Team has {actualSize} members (max: {maxSize})",
|
||||||
|
Severity = ValidationSeverity.Error, // Always error - hard constraint
|
||||||
|
Context = ValidationContext.Team,
|
||||||
|
IconIdentifier = null,
|
||||||
|
Metadata = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "TeamId", entity.Id },
|
||||||
|
{ "EventName", entity.Event.Name },
|
||||||
|
{ "ActualSize", actualSize },
|
||||||
|
{ "MinSize", entity.Event.MinTeamSize },
|
||||||
|
{ "MaxSize", maxSize }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AppliesTo(ValidationContext context) =>
|
||||||
|
context == ValidationContext.Team;
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
|
||||||
|
namespace Core.Validation.Rules.TeamRules;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validation rule that checks if a team has fewer members than the minimum required
|
||||||
|
/// </summary>
|
||||||
|
public class TeamSizeTooSmallRule : IValidationRule<Team>
|
||||||
|
{
|
||||||
|
public ValidationWarning? Validate(Team entity, ValidationConfiguration config)
|
||||||
|
{
|
||||||
|
// Individual events don't have team size requirements
|
||||||
|
if (entity.Event.EventFormat == EventFormat.Individual)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var actualSize = entity.Students.Count;
|
||||||
|
var minSize = entity.Event.MinTeamSize;
|
||||||
|
|
||||||
|
if (actualSize >= minSize)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new ValidationWarning
|
||||||
|
{
|
||||||
|
Code = "TEAM_SIZE_TOO_SMALL",
|
||||||
|
Message = $"Team has {actualSize} members (min: {minSize})",
|
||||||
|
Severity = config.TeamSizeSeverity,
|
||||||
|
Context = ValidationContext.Team,
|
||||||
|
IconIdentifier = null,
|
||||||
|
Metadata = new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "TeamId", entity.Id },
|
||||||
|
{ "EventName", entity.Event.Name },
|
||||||
|
{ "ActualSize", actualSize },
|
||||||
|
{ "MinSize", minSize },
|
||||||
|
{ "MaxSize", entity.Event.MaxTeamSize }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AppliesTo(ValidationContext context) =>
|
||||||
|
context == ValidationContext.Team;
|
||||||
|
}
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
|
namespace Core.Validation;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configuration for validation thresholds and rules
|
||||||
|
/// </summary>
|
||||||
|
public class ValidationConfiguration
|
||||||
|
{
|
||||||
|
// Event count thresholds
|
||||||
|
/// <summary>
|
||||||
|
/// Minimum recommended number of events per student (Warning if below)
|
||||||
|
/// </summary>
|
||||||
|
public int MinRecommendedEvents { get; set; } = 2;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Maximum recommended number of events per student (Warning if above)
|
||||||
|
/// </summary>
|
||||||
|
public int MaxRecommendedEvents { get; set; } = 4;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Minimum critical number of events per student (Error if below)
|
||||||
|
/// </summary>
|
||||||
|
public int MinCriticalEvents { get; set; } = 1;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Maximum critical number of events per student (Error if above)
|
||||||
|
/// </summary>
|
||||||
|
public int MaxCriticalEvents { get; set; } = 6;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Maximum recommended number of regional events per student (Warning if above)
|
||||||
|
/// </summary>
|
||||||
|
public int MaxRegionalEvents { get; set; } = 3;
|
||||||
|
|
||||||
|
// Required event types
|
||||||
|
/// <summary>
|
||||||
|
/// Whether to require students to have at least one regional event
|
||||||
|
/// </summary>
|
||||||
|
public bool RequireRegionalEvent { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether to require students to have at least one on-site activity
|
||||||
|
/// </summary>
|
||||||
|
public bool RequireOnSiteActivity { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether to require students to have at least one individual event
|
||||||
|
/// </summary>
|
||||||
|
public bool RequireIndividualEvent { get; set; } = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether to require team-based events to have an assigned captain
|
||||||
|
/// </summary>
|
||||||
|
public bool RequireTeamCaptain { get; set; } = true;
|
||||||
|
|
||||||
|
// Severity levels for each rule type
|
||||||
|
/// <summary>
|
||||||
|
/// Severity level for "No Regional Event" warnings
|
||||||
|
/// </summary>
|
||||||
|
public ValidationSeverity NoRegionalEventSeverity { get; set; } = ValidationSeverity.Warning;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Severity level for "No On-Site Activity" warnings
|
||||||
|
/// </summary>
|
||||||
|
public ValidationSeverity NoOnSiteActivitySeverity { get; set; } = ValidationSeverity.Warning;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Severity level for "No Individual Event" warnings
|
||||||
|
/// </summary>
|
||||||
|
public ValidationSeverity NoIndividualEventSeverity { get; set; } = ValidationSeverity.Warning;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Severity level for team size warnings
|
||||||
|
/// </summary>
|
||||||
|
public ValidationSeverity TeamSizeSeverity { get; set; } = ValidationSeverity.Warning;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Severity level for event count warnings
|
||||||
|
/// </summary>
|
||||||
|
public ValidationSeverity EventCountSeverity { get; set; } = ValidationSeverity.Warning;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Severity level for missing captain warnings
|
||||||
|
/// </summary>
|
||||||
|
public ValidationSeverity MissingCaptainSeverity { get; set; } = ValidationSeverity.Warning;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Severity level for too many regional events warnings
|
||||||
|
/// </summary>
|
||||||
|
public ValidationSeverity TooManyRegionalEventsSeverity { get; set; } = ValidationSeverity.Warning;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default configuration matching current app behavior
|
||||||
|
/// </summary>
|
||||||
|
public static ValidationConfiguration Default => new()
|
||||||
|
{
|
||||||
|
RequireRegionalEvent = true,
|
||||||
|
RequireOnSiteActivity = true,
|
||||||
|
RequireIndividualEvent = false,
|
||||||
|
MinRecommendedEvents = 2,
|
||||||
|
MaxRecommendedEvents = 4,
|
||||||
|
MinCriticalEvents = 1,
|
||||||
|
MaxCriticalEvents = 6,
|
||||||
|
MaxRegionalEvents = 3,
|
||||||
|
RequireTeamCaptain = true,
|
||||||
|
NoRegionalEventSeverity = ValidationSeverity.Warning,
|
||||||
|
NoOnSiteActivitySeverity = ValidationSeverity.Warning,
|
||||||
|
NoIndividualEventSeverity = ValidationSeverity.Warning,
|
||||||
|
TeamSizeSeverity = ValidationSeverity.Warning,
|
||||||
|
EventCountSeverity = ValidationSeverity.Warning,
|
||||||
|
MissingCaptainSeverity = ValidationSeverity.Warning,
|
||||||
|
TooManyRegionalEventsSeverity = ValidationSeverity.Warning
|
||||||
|
};
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create validation configuration from assignment parameters
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="parameters">Assignment parameters to convert</param>
|
||||||
|
/// <returns>Validation configuration matching the assignment parameters</returns>
|
||||||
|
public static ValidationConfiguration FromAssignmentParameters(AssignmentParameters parameters)
|
||||||
|
{
|
||||||
|
return new ValidationConfiguration
|
||||||
|
{
|
||||||
|
RequireRegionalEvent = parameters.RequireRegional,
|
||||||
|
RequireOnSiteActivity = parameters.RequireOnSite,
|
||||||
|
MinRecommendedEvents = parameters.EventsLowerBound,
|
||||||
|
MaxRecommendedEvents = parameters.EventsUpperBound,
|
||||||
|
MinCriticalEvents = 1,
|
||||||
|
MaxCriticalEvents = 6,
|
||||||
|
RequireTeamCaptain = true,
|
||||||
|
NoRegionalEventSeverity = ValidationSeverity.Warning,
|
||||||
|
NoOnSiteActivitySeverity = ValidationSeverity.Warning,
|
||||||
|
NoIndividualEventSeverity = ValidationSeverity.Warning,
|
||||||
|
TeamSizeSeverity = ValidationSeverity.Warning,
|
||||||
|
EventCountSeverity = ValidationSeverity.Warning,
|
||||||
|
MissingCaptainSeverity = ValidationSeverity.Warning
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deserialize validation configuration from JSON string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="json">JSON string containing configuration</param>
|
||||||
|
/// <returns>ValidationConfiguration instance or Default if deserialization fails</returns>
|
||||||
|
public static ValidationConfiguration FromJson(string json)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return JsonSerializer.Deserialize<ValidationConfiguration>(json) ?? Default;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return Default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Load validation configuration from a JSON file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">Path to the JSON configuration file</param>
|
||||||
|
/// <returns>ValidationConfiguration instance or Default if file doesn't exist or loading fails</returns>
|
||||||
|
public static async Task<ValidationConfiguration> LoadFromFileAsync(string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!File.Exists(path))
|
||||||
|
return Default;
|
||||||
|
|
||||||
|
var json = await File.ReadAllTextAsync(path);
|
||||||
|
return FromJson(json);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return Default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Save this validation configuration to a JSON file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="path">Path where the JSON file should be saved</param>
|
||||||
|
public async Task SaveToFileAsync(string path)
|
||||||
|
{
|
||||||
|
var json = JsonSerializer.Serialize(this, new JsonSerializerOptions
|
||||||
|
{
|
||||||
|
WriteIndented = true
|
||||||
|
});
|
||||||
|
await File.WriteAllTextAsync(path, json);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
namespace Core.Validation;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Context in which validation is being performed
|
||||||
|
/// </summary>
|
||||||
|
public enum ValidationContext
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Validating a single student's event rankings
|
||||||
|
/// </summary>
|
||||||
|
StudentRanking = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validating a single team configuration
|
||||||
|
/// </summary>
|
||||||
|
Team = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validating a student's assigned events
|
||||||
|
/// </summary>
|
||||||
|
StudentAssignment = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validating student registration data
|
||||||
|
/// </summary>
|
||||||
|
StudentRegistration = 3
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
using Core.Entities;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace Core.Validation;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Main service for executing validation rules and generating warnings
|
||||||
|
/// </summary>
|
||||||
|
public class ValidationService
|
||||||
|
{
|
||||||
|
private readonly ValidationConfiguration _config;
|
||||||
|
private readonly List<IValidationRule<Student>> _studentRules;
|
||||||
|
private readonly List<IValidationRule<Team>> _teamRules;
|
||||||
|
private readonly List<IValidationRule<StudentEventStatistics>> _statisticsRules;
|
||||||
|
|
||||||
|
// Lazy static singletons for rule definitions (instantiated once per application lifetime)
|
||||||
|
private static readonly Lazy<List<IValidationRule<Student>>> _studentRuleDefinitions =
|
||||||
|
new(() => DiscoverRules<Student>());
|
||||||
|
private static readonly Lazy<List<IValidationRule<Team>>> _teamRuleDefinitions =
|
||||||
|
new(() => DiscoverRules<Team>());
|
||||||
|
private static readonly Lazy<List<IValidationRule<StudentEventStatistics>>> _statisticsRuleDefinitions =
|
||||||
|
new(() => DiscoverRules<StudentEventStatistics>());
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new validation service with the specified configuration
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="config">Validation configuration (uses Default if null)</param>
|
||||||
|
public ValidationService(ValidationConfiguration? config = null)
|
||||||
|
{
|
||||||
|
_config = config ?? ValidationConfiguration.Default;
|
||||||
|
|
||||||
|
// Use the shared rule definitions (singleton pattern)
|
||||||
|
_studentRules = _studentRuleDefinitions.Value;
|
||||||
|
_teamRules = _teamRuleDefinitions.Value;
|
||||||
|
_statisticsRules = _statisticsRuleDefinitions.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Discover all validation rules for a given entity type using reflection
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="TEntity">The entity type to find rules for</typeparam>
|
||||||
|
/// <returns>List of discovered validation rules</returns>
|
||||||
|
private static List<IValidationRule<TEntity>> DiscoverRules<TEntity>()
|
||||||
|
{
|
||||||
|
var ruleType = typeof(IValidationRule<TEntity>);
|
||||||
|
|
||||||
|
return Assembly.GetExecutingAssembly()
|
||||||
|
.GetTypes()
|
||||||
|
.Where(t => t.IsClass && !t.IsAbstract && ruleType.IsAssignableFrom(t))
|
||||||
|
.Select(t => (IValidationRule<TEntity>)Activator.CreateInstance(t)!)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate a student's event rankings
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="student">Student to validate</param>
|
||||||
|
/// <param name="context">Validation context</param>
|
||||||
|
/// <returns>List of validation warnings</returns>
|
||||||
|
public List<ValidationWarning> ValidateStudentRankings(Student student, ValidationContext context)
|
||||||
|
{
|
||||||
|
return _studentRules
|
||||||
|
.Where(rule => rule.AppliesTo(context))
|
||||||
|
.Select(rule => rule.Validate(student, _config))
|
||||||
|
.Where(warning => warning != null)
|
||||||
|
.Cast<ValidationWarning>()
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate a team configuration
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="team">Team to validate</param>
|
||||||
|
/// <param name="context">Validation context (defaults to Team)</param>
|
||||||
|
/// <returns>List of validation warnings</returns>
|
||||||
|
public List<ValidationWarning> ValidateTeam(Team team, ValidationContext context = ValidationContext.Team)
|
||||||
|
{
|
||||||
|
return _teamRules
|
||||||
|
.Where(rule => rule.AppliesTo(context))
|
||||||
|
.Select(rule => rule.Validate(team, _config))
|
||||||
|
.Where(warning => warning != null)
|
||||||
|
.Cast<ValidationWarning>()
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate student event assignment statistics
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="stats">Student statistics to validate</param>
|
||||||
|
/// <param name="context">Validation context</param>
|
||||||
|
/// <returns>List of validation warnings</returns>
|
||||||
|
public List<ValidationWarning> ValidateStudentStatistics(StudentEventStatistics stats, ValidationContext context)
|
||||||
|
{
|
||||||
|
return _statisticsRules
|
||||||
|
.Where(rule => rule.AppliesTo(context))
|
||||||
|
.Select(rule => rule.Validate(stats, _config))
|
||||||
|
.Where(warning => warning != null)
|
||||||
|
.Cast<ValidationWarning>()
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate all students in a collection
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="students">Students to validate</param>
|
||||||
|
/// <param name="context">Validation context</param>
|
||||||
|
/// <returns>Dictionary mapping each student to their warnings</returns>
|
||||||
|
public Dictionary<Student, List<ValidationWarning>> ValidateStudents(
|
||||||
|
IEnumerable<Student> students,
|
||||||
|
ValidationContext context)
|
||||||
|
{
|
||||||
|
return students.ToDictionary(
|
||||||
|
student => student,
|
||||||
|
student => ValidateStudentRankings(student, context)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Validate all teams in a collection
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="teams">Teams to validate</param>
|
||||||
|
/// <returns>Dictionary mapping each team to their warnings</returns>
|
||||||
|
public Dictionary<Team, List<ValidationWarning>> ValidateTeams(IEnumerable<Team> teams)
|
||||||
|
{
|
||||||
|
return teams.ToDictionary(
|
||||||
|
team => team,
|
||||||
|
team => ValidateTeam(team)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
namespace Core.Validation;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Severity level for validation warnings
|
||||||
|
/// </summary>
|
||||||
|
public enum ValidationSeverity
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Warning that should be addressed but doesn't prevent operation
|
||||||
|
/// </summary>
|
||||||
|
Warning = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Error that indicates a critical issue
|
||||||
|
/// </summary>
|
||||||
|
Error = 1
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
namespace Core.Validation;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a validation warning or error for a student, team, or assignment
|
||||||
|
/// </summary>
|
||||||
|
public class ValidationWarning
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Human-readable warning message
|
||||||
|
/// </summary>
|
||||||
|
public required string Message { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Unique code identifying the validation rule (e.g., "NO_REGIONAL_EVENT")
|
||||||
|
/// </summary>
|
||||||
|
public required string Code { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Severity level of the warning
|
||||||
|
/// </summary>
|
||||||
|
public required ValidationSeverity Severity { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Context in which this warning applies
|
||||||
|
/// </summary>
|
||||||
|
public required ValidationContext Context { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Icon identifier for UI display (maps to AppIcons constants in WebApp)
|
||||||
|
/// </summary>
|
||||||
|
public string? IconIdentifier { get; init; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Additional contextual information about the warning
|
||||||
|
/// </summary>
|
||||||
|
public Dictionary<string, object> Metadata { get; init; } = new();
|
||||||
|
}
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
@using WebApp.Models
|
@using WebApp.Models
|
||||||
|
|
||||||
|
<span style=""></span>
|
||||||
|
@if (EventDefinition.LevelOfEffort.HasValue)
|
||||||
|
{
|
||||||
|
<span class="numberCircle">@EventDefinition.LevelOfEffort</span>
|
||||||
|
}
|
||||||
<MudText Style="font-family: monospace; white-space: pre;">
|
<MudText Style="font-family: monospace; white-space: pre;">
|
||||||
|
|
||||||
@foreach (var charStr in _attributes.Select(c => c.ToString()))
|
@foreach (var charStr in _attributes.Select(c => c.ToString()))
|
||||||
{
|
{
|
||||||
if (AppIcons.IconTooltips.TryGetValue(charStr, out var tooltip))
|
if (AppIcons.IconTooltips.TryGetValue(charStr, out var tooltip))
|
||||||
@@ -23,9 +29,7 @@
|
|||||||
|
|
||||||
protected override void OnParametersSet()
|
protected override void OnParametersSet()
|
||||||
{
|
{
|
||||||
_attributes = AppIcons.LevelOfEffortIcon(EventDefinition.LevelOfEffort);
|
_attributes = EventDefinition.EventFormat == EventFormat.Individual ? AppIcons.IndividualEvent : " ";
|
||||||
_attributes += " ";
|
|
||||||
_attributes += EventDefinition.EventFormat == EventFormat.Individual ? AppIcons.IndividualEvent : " ";
|
|
||||||
_attributes += EventDefinition.OnSiteActivity ? AppIcons.OnSiteActivity : " ";
|
_attributes += EventDefinition.OnSiteActivity ? AppIcons.OnSiteActivity : " ";
|
||||||
_attributes += EventDefinition.RegionalEvent ? AppIcons.RegionalEvent : " ";
|
_attributes += EventDefinition.RegionalEvent ? AppIcons.RegionalEvent : " ";
|
||||||
_attributes += EventDefinition.InterviewOrPresentation ? AppIcons.PresentationEvent : " ";
|
_attributes += EventDefinition.InterviewOrPresentation ? AppIcons.PresentationEvent : " ";
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
@attribute [Authorize]
|
@attribute [Authorize]
|
||||||
@using Microsoft.EntityFrameworkCore
|
@using Microsoft.EntityFrameworkCore
|
||||||
@using WebApp.Models
|
@using WebApp.Models
|
||||||
|
@using Core.Validation
|
||||||
@inject AppDbContext Context
|
@inject AppDbContext Context
|
||||||
|
@inject ValidationService ValidationService
|
||||||
@rendermode InteractiveServer
|
@rendermode InteractiveServer
|
||||||
|
|
||||||
<PageTitle>Student Event Ranks - TSA Chapter Organizer</PageTitle>
|
<PageTitle>Student Event Ranks - TSA Chapter Organizer</PageTitle>
|
||||||
@@ -37,25 +39,7 @@ else
|
|||||||
<MudTh>@context.TsaYear</MudTh>
|
<MudTh>@context.TsaYear</MudTh>
|
||||||
<MudTd><MudButton StartIcon="@Icons.Material.Filled.TableChart" Href="@($"students/event-ranking-edit/{context.Id}")">Edit</MudButton></MudTd>
|
<MudTd><MudButton StartIcon="@Icons.Material.Filled.TableChart" Href="@($"students/event-ranking-edit/{context.Id}")">Edit</MudButton></MudTd>
|
||||||
<MudTd>
|
<MudTd>
|
||||||
@if (!context.RankedEvents.Any(re => re.OnSiteActivity))
|
<ValidationWarnings Warnings="@GetStudentWarnings(context)" />
|
||||||
{
|
|
||||||
<MudTooltip Text="No On-Site Activity">
|
|
||||||
<MudText Style="font-weight:bolder" Color="Color.Warning">@AppIcons.OnSiteActivity</MudText>
|
|
||||||
</MudTooltip>
|
|
||||||
}
|
|
||||||
@if (!context.RankedEvents.Any(re => re.RegionalEvent))
|
|
||||||
{
|
|
||||||
<MudTooltip Text="No Regional Event">
|
|
||||||
<MudText Style="font-weight:bolder" Color="Color.Warning">@AppIcons.RegionalEvent</MudText>
|
|
||||||
</MudTooltip>
|
|
||||||
}
|
|
||||||
|
|
||||||
@if (context.RankedEvents.All(re => re.EventFormat != EventFormat.Individual))
|
|
||||||
{
|
|
||||||
<MudTooltip Text="No Individual Event">
|
|
||||||
<MudText Style="font-weight:bolder" Color="Color.Warning">@AppIcons.IndividualEvent</MudText>
|
|
||||||
</MudTooltip>
|
|
||||||
}
|
|
||||||
</MudTd>
|
</MudTd>
|
||||||
@for (var i = 1; i <= 10; i++)
|
@for (var i = 1; i <= 10; i++)
|
||||||
{
|
{
|
||||||
@@ -154,4 +138,9 @@ else
|
|||||||
|
|
||||||
_maxEventStudentRankings = _eventStudentRankings.Max(esr => esr.StudentRanking.Length);
|
_maxEventStudentRankings = _eventStudentRankings.Max(esr => esr.StudentRanking.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<ValidationWarning> GetStudentWarnings(Student student)
|
||||||
|
{
|
||||||
|
return ValidationService.ValidateStudentRankings(student, ValidationContext.StudentRanking);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
@attribute [Authorize]
|
@attribute [Authorize]
|
||||||
@using Microsoft.EntityFrameworkCore
|
@using Microsoft.EntityFrameworkCore
|
||||||
@using WebApp.Models
|
@using WebApp.Models
|
||||||
|
@using Core.Validation
|
||||||
@inject AppDbContext Context
|
@inject AppDbContext Context
|
||||||
@inject WebApp.LocalStorageService LocalStorage
|
@inject WebApp.LocalStorageService LocalStorage
|
||||||
|
@inject ValidationService ValidationService
|
||||||
|
|
||||||
<PageTitle>Registration - TSA Chapter Organizer</PageTitle>
|
<PageTitle>Registration - TSA Chapter Organizer</PageTitle>
|
||||||
|
|
||||||
@@ -43,6 +45,11 @@
|
|||||||
</MudTooltip>
|
</MudTooltip>
|
||||||
</CellTemplate>
|
</CellTemplate>
|
||||||
</PropertyColumn>
|
</PropertyColumn>
|
||||||
|
<TemplateColumn Title="Warnings" Sortable="false">
|
||||||
|
<CellTemplate>
|
||||||
|
<ValidationWarnings Warnings="@GetRegistrationWarnings(context.Item.Student)" />
|
||||||
|
</CellTemplate>
|
||||||
|
</TemplateColumn>
|
||||||
@if (_showGrade)
|
@if (_showGrade)
|
||||||
{
|
{
|
||||||
<PropertyColumn Property="@(e => e.Student.Grade)" Title="Grade" Sortable="true" />
|
<PropertyColumn Property="@(e => e.Student.Grade)" Title="Grade" Sortable="true" />
|
||||||
@@ -239,6 +246,20 @@
|
|||||||
: data.OrderBy(sortExpression);
|
: data.OrderBy(sortExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<ValidationWarning> GetRegistrationWarnings(Student student)
|
||||||
|
{
|
||||||
|
// Create StudentEventStatistics from the student's teams
|
||||||
|
var stats = new StudentEventStatistics
|
||||||
|
{
|
||||||
|
Student = student,
|
||||||
|
Events = student.Teams?.Where(t => t?.Event != null)
|
||||||
|
.Select(t => t.Event)
|
||||||
|
.ToList() ?? new List<EventDefinition>()
|
||||||
|
};
|
||||||
|
|
||||||
|
return ValidationService.ValidateStudentStatistics(stats, ValidationContext.StudentRegistration);
|
||||||
|
}
|
||||||
|
|
||||||
public class StudentTeamInfo
|
public class StudentTeamInfo
|
||||||
{
|
{
|
||||||
public required Student Student { get; init; }
|
public required Student Student { get; init; }
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
@page "/teams/assignment"
|
@page "/teams/assignment"
|
||||||
@attribute [Authorize]
|
@attribute [Authorize]
|
||||||
@using Core.Calculation
|
@using Core.Calculation
|
||||||
|
@using Core.Validation
|
||||||
@using Microsoft.EntityFrameworkCore
|
@using Microsoft.EntityFrameworkCore
|
||||||
@using WebApp.Models
|
@using WebApp.Models
|
||||||
@using EventAssignment = Core.Calculation.EventAssignment
|
@using EventAssignment = Core.Calculation.EventAssignment
|
||||||
@inject AppDbContext Context
|
@inject AppDbContext Context
|
||||||
@inject IDialogService DialogService
|
@inject IDialogService DialogService
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
|
@inject ValidationService ValidationService
|
||||||
|
|
||||||
<PageTitle>Event Assignment - TSA Chapter Organizer</PageTitle>
|
<PageTitle>Event Assignment - TSA Chapter Organizer</PageTitle>
|
||||||
|
|
||||||
@@ -134,18 +136,8 @@
|
|||||||
<MudTd><b>@context.Student.FirstName</b></MudTd>
|
<MudTd><b>@context.Student.FirstName</b></MudTd>
|
||||||
<MudTd>@context.EventCount</MudTd>
|
<MudTd>@context.EventCount</MudTd>
|
||||||
<MudTd>@context.TotalLevelOfEffort</MudTd>
|
<MudTd>@context.TotalLevelOfEffort</MudTd>
|
||||||
<MudTd>@if (!context.HasOnSiteActivity)
|
<MudTd>
|
||||||
{
|
<ValidationWarnings Warnings="@GetStatisticsWarnings(context)" />
|
||||||
<MudTooltip Text="No On-Site Activity">
|
|
||||||
<MudText Style="font-weight:bolder" Color="Color.Warning">@AppIcons.OnSiteActivity</MudText>
|
|
||||||
</MudTooltip>
|
|
||||||
}
|
|
||||||
@if (!context.HasRegionalEvent)
|
|
||||||
{
|
|
||||||
<MudTooltip Text="No Regional Event">
|
|
||||||
<MudText Style="font-weight:bolder" Color="Color.Warning">@AppIcons.RegionalEvent</MudText>
|
|
||||||
</MudTooltip>
|
|
||||||
}
|
|
||||||
</MudTd>
|
</MudTd>
|
||||||
</RowTemplate>
|
</RowTemplate>
|
||||||
<ChildRowContent>
|
<ChildRowContent>
|
||||||
@@ -313,6 +305,7 @@
|
|||||||
public bool TestSwitch { get; set; } = false;
|
public bool TestSwitch { get; set; } = false;
|
||||||
|
|
||||||
private readonly AssignmentParameters _parameters = new() { RequireOnSite = false, RequireRegional = false };
|
private readonly AssignmentParameters _parameters = new() { RequireOnSite = false, RequireRegional = false };
|
||||||
|
private ValidationService _validationService = new ValidationService(ValidationConfiguration.Default);
|
||||||
|
|
||||||
private List<EventDefinition>? _events;
|
private List<EventDefinition>? _events;
|
||||||
private List<Student>? _students;
|
private List<Student>? _students;
|
||||||
@@ -367,6 +360,7 @@
|
|||||||
private async Task<TableData<Team>> SolveAssignments(TableState arg1, CancellationToken arg2)
|
private async Task<TableData<Team>> SolveAssignments(TableState arg1, CancellationToken arg2)
|
||||||
{
|
{
|
||||||
_isSolving = true;
|
_isSolving = true;
|
||||||
|
UpdateValidationConfig();
|
||||||
var eventAssignment = new EventAssignment(_events, _students, _parameters);
|
var eventAssignment = new EventAssignment(_events, _students, _parameters);
|
||||||
foreach (var requirement in _assignmentRequirements)
|
foreach (var requirement in _assignmentRequirements)
|
||||||
{
|
{
|
||||||
@@ -396,6 +390,17 @@
|
|||||||
return new TableData<StudentEventStatistics> {Items = _statistics};
|
return new TableData<StudentEventStatistics> {Items = _statistics};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateValidationConfig()
|
||||||
|
{
|
||||||
|
var config = ValidationConfiguration.FromAssignmentParameters(_parameters);
|
||||||
|
_validationService = new ValidationService(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ValidationWarning> GetStatisticsWarnings(StudentEventStatistics stats)
|
||||||
|
{
|
||||||
|
return _validationService.ValidateStudentStatistics(stats, ValidationContext.StudentAssignment);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<TableData<AssignmentRequirement>> ReloadAssignmentRequirements(TableState arg1, CancellationToken arg2)
|
private async Task<TableData<AssignmentRequirement>> ReloadAssignmentRequirements(TableState arg1, CancellationToken arg2)
|
||||||
{
|
{
|
||||||
return new TableData<AssignmentRequirement> { Items = _assignmentRequirements };
|
return new TableData<AssignmentRequirement> { Items = _assignmentRequirements };
|
||||||
|
|||||||
@@ -0,0 +1,186 @@
|
|||||||
|
@page "/settings/chapter"
|
||||||
|
@attribute [Authorize(Roles = AuthRoles.Administrator)]
|
||||||
|
@using WebApp.Authentication
|
||||||
|
@using WebApp.Models
|
||||||
|
@using System.Text.Json
|
||||||
|
@inject IWebHostEnvironment Environment
|
||||||
|
@inject IConfiguration Configuration
|
||||||
|
|
||||||
|
@rendermode InteractiveServer
|
||||||
|
|
||||||
|
<PageTitle>Chapter Settings</PageTitle>
|
||||||
|
|
||||||
|
<MudContainer MaxWidth="MaxWidth.Large" Class="mt-4">
|
||||||
|
<MudText Typo="Typo.h3" Class="mb-4">Chapter Settings</MudText>
|
||||||
|
<MudText Typo="Typo.body1" Class="mb-6">Configure chapter information. Changes take effect on next application restart.</MudText>
|
||||||
|
|
||||||
|
@if (_settings != null)
|
||||||
|
{
|
||||||
|
<MudPaper Class="pa-6 mb-4">
|
||||||
|
<MudText Typo="Typo.h5" Class="mb-4">Basic Information</MudText>
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12" md="8">
|
||||||
|
<MudTextField @bind-Value="_settings.Name"
|
||||||
|
Label="Chapter Name"
|
||||||
|
Variant="Variant.Outlined"
|
||||||
|
HelperText="Full chapter name"
|
||||||
|
Required="true" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="4">
|
||||||
|
<MudTextField @bind-Value="_settings.ShortName"
|
||||||
|
Label="Short Name"
|
||||||
|
Variant="Variant.Outlined"
|
||||||
|
HelperText="Abbreviation (e.g., YCN)"
|
||||||
|
MaxLength="10"
|
||||||
|
Required="true" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudTextField @bind-Value="_settings.CompetitionYear"
|
||||||
|
Label="Competition Year"
|
||||||
|
Variant="Variant.Outlined"
|
||||||
|
HelperText="Year of competition (e.g., 2026)"
|
||||||
|
MaxLength="4"
|
||||||
|
Required="true" />
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
<MudPaper Class="pa-6 mb-4">
|
||||||
|
<MudText Typo="Typo.h5" Class="mb-4">Chapter IDs</MudText>
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12" md="4">
|
||||||
|
<MudTextField @bind-Value="_settings.NationalId"
|
||||||
|
Label="National ID"
|
||||||
|
Variant="Variant.Outlined"
|
||||||
|
HelperText="4-digit national chapter ID"
|
||||||
|
MaxLength="4" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="4">
|
||||||
|
<MudTextField @bind-Value="_settings.StateId"
|
||||||
|
Label="State ID"
|
||||||
|
Variant="Variant.Outlined"
|
||||||
|
HelperText="5-digit state chapter ID"
|
||||||
|
MaxLength="5" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="4">
|
||||||
|
<MudTextField @bind-Value="_settings.RegionalId"
|
||||||
|
Label="Regional ID"
|
||||||
|
Variant="Variant.Outlined"
|
||||||
|
HelperText="5-digit regional chapter ID"
|
||||||
|
MaxLength="5" />
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
<MudPaper Class="pa-6">
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12">
|
||||||
|
<MudButton Variant="Variant.Filled"
|
||||||
|
Color="Color.Primary"
|
||||||
|
StartIcon="@Icons.Material.Filled.Save"
|
||||||
|
OnClick="SaveSettings"
|
||||||
|
Disabled="_isSaving">
|
||||||
|
@if (_isSaving)
|
||||||
|
{
|
||||||
|
<MudProgressCircular Class="mr-2" Size="Size.Small" Indeterminate="true" />
|
||||||
|
<span>Saving...</span>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<span>Save Settings</span>
|
||||||
|
}
|
||||||
|
</MudButton>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
@if (!string.IsNullOrEmpty(_statusMessage))
|
||||||
|
{
|
||||||
|
<MudAlert Severity="@_statusSeverity" Class="mt-4">@_statusMessage</MudAlert>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<MudProgressCircular Indeterminate="true" />
|
||||||
|
}
|
||||||
|
</MudContainer>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private Models.ChapterSettings? _settings;
|
||||||
|
private bool _isSaving;
|
||||||
|
private string? _statusMessage;
|
||||||
|
private Severity _statusSeverity = Severity.Success;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
// Load from IConfiguration
|
||||||
|
_settings = Configuration.GetSection("ChapterSettings").Get<Models.ChapterSettings>()
|
||||||
|
?? new Models.ChapterSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetAppSettingsPath()
|
||||||
|
{
|
||||||
|
return Path.Combine(
|
||||||
|
Environment.ContentRootPath,
|
||||||
|
"Data",
|
||||||
|
"appsettings.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveSettings()
|
||||||
|
{
|
||||||
|
if (_settings == null) return;
|
||||||
|
|
||||||
|
_isSaving = true;
|
||||||
|
_statusMessage = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var appSettingsPath = GetAppSettingsPath();
|
||||||
|
|
||||||
|
// Ensure Data directory exists
|
||||||
|
var dataDir = Path.GetDirectoryName(appSettingsPath);
|
||||||
|
if (dataDir != null && !Directory.Exists(dataDir))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(dataDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read existing appsettings or create new
|
||||||
|
JsonDocument? existingDoc = null;
|
||||||
|
Dictionary<string, object?> settings;
|
||||||
|
|
||||||
|
if (File.Exists(appSettingsPath))
|
||||||
|
{
|
||||||
|
var existingJson = await File.ReadAllTextAsync(appSettingsPath);
|
||||||
|
existingDoc = JsonDocument.Parse(existingJson);
|
||||||
|
settings = JsonSerializer.Deserialize<Dictionary<string, object?>>(existingJson)
|
||||||
|
?? new Dictionary<string, object?>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
settings = new Dictionary<string, object?>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update ChapterSettings section
|
||||||
|
settings["ChapterSettings"] = _settings;
|
||||||
|
|
||||||
|
// Write back to file
|
||||||
|
var options = new JsonSerializerOptions { WriteIndented = true };
|
||||||
|
var json = JsonSerializer.Serialize(settings, options);
|
||||||
|
await File.WriteAllTextAsync(appSettingsPath, json);
|
||||||
|
|
||||||
|
existingDoc?.Dispose();
|
||||||
|
|
||||||
|
_statusMessage = "Settings saved successfully! Changes will take effect on next application restart.";
|
||||||
|
_statusSeverity = Severity.Success;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_statusMessage = $"Error saving settings: {ex.Message}";
|
||||||
|
_statusSeverity = Severity.Error;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isSaving = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -26,6 +26,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</MudPaper>
|
</MudPaper>
|
||||||
|
|
||||||
|
<MudPaper Elevation="0" Class="mb-6">
|
||||||
|
<MudText Typo="Typo.h4" Class="mb-2">Data</MudText>
|
||||||
|
</MudPaper>
|
||||||
<MudGrid>
|
<MudGrid>
|
||||||
<!-- Events Card -->
|
<!-- Events Card -->
|
||||||
<DashboardCard Icon="@AppIcons.Events"
|
<DashboardCard Icon="@AppIcons.Events"
|
||||||
@@ -60,13 +63,19 @@
|
|||||||
Subtitle="Total Teams"
|
Subtitle="Total Teams"
|
||||||
Caption="@($"{_groupTeamsCount} Team | {_individualTeamsCount} Individual")"
|
Caption="@($"{_groupTeamsCount} Team | {_individualTeamsCount} Individual")"
|
||||||
NavigateUrl="/teams" />
|
NavigateUrl="/teams" />
|
||||||
|
</MudGrid>
|
||||||
|
<MudPaper Elevation="0" Class="my-6">
|
||||||
|
<MudText Typo="Typo.h4">Tools</MudText>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
<MudGrid>
|
||||||
|
|
||||||
<!-- Meeting Schedule Card -->
|
<!-- Meeting Schedule Card -->
|
||||||
<DashboardCard Icon="@AppIcons.Scheduler"
|
<DashboardCard Icon="@AppIcons.Scheduler"
|
||||||
Title="Schedule"
|
Title="Schedule"
|
||||||
Caption="Optimize meeting times"
|
Caption="Optimize meeting times"
|
||||||
NavigateUrl="/meeting-schedule" />
|
NavigateUrl="/meeting-schedule"/>
|
||||||
</MudGrid>
|
</MudGrid>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private int _eventCount;
|
private int _eventCount;
|
||||||
|
|||||||
@@ -0,0 +1,284 @@
|
|||||||
|
@page "/settings/validation"
|
||||||
|
@attribute [Authorize(Roles = AuthRoles.Administrator)]
|
||||||
|
@using Core.Validation
|
||||||
|
@using WebApp.Authentication
|
||||||
|
@using System.Text.Json
|
||||||
|
@inject IWebHostEnvironment Environment
|
||||||
|
@inject IConfiguration Configuration
|
||||||
|
|
||||||
|
@rendermode InteractiveServer
|
||||||
|
|
||||||
|
<PageTitle>Validation Settings</PageTitle>
|
||||||
|
|
||||||
|
<MudContainer MaxWidth="MaxWidth.Large" Class="mt-4">
|
||||||
|
<MudText Typo="Typo.h3" Class="mb-4">Validation Settings</MudText>
|
||||||
|
<MudText Typo="Typo.body1" Class="mb-6">Configure validation rules and thresholds. Changes take effect on next application restart.</MudText>
|
||||||
|
|
||||||
|
@if (_config != null)
|
||||||
|
{
|
||||||
|
<MudPaper Class="pa-6 mb-4">
|
||||||
|
<MudText Typo="Typo.h5" Class="mb-4">Event Count Thresholds</MudText>
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudNumericField @bind-Value="_config.MinRecommendedEvents"
|
||||||
|
Label="Minimum Recommended Events"
|
||||||
|
Variant="Variant.Outlined"
|
||||||
|
HelperText="Warning if student has fewer events"
|
||||||
|
Min="0" Max="10" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudNumericField @bind-Value="_config.MaxRecommendedEvents"
|
||||||
|
Label="Maximum Recommended Events"
|
||||||
|
Variant="Variant.Outlined"
|
||||||
|
HelperText="Warning if student has more events"
|
||||||
|
Min="0" Max="10" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudNumericField @bind-Value="_config.MinCriticalEvents"
|
||||||
|
Label="Minimum Critical Events"
|
||||||
|
Variant="Variant.Outlined"
|
||||||
|
HelperText="Error if student has fewer events"
|
||||||
|
Min="0" Max="10" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudNumericField @bind-Value="_config.MaxCriticalEvents"
|
||||||
|
Label="Maximum Critical Events"
|
||||||
|
Variant="Variant.Outlined"
|
||||||
|
HelperText="Error if student has more events"
|
||||||
|
Min="0" Max="10" />
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudNumericField @bind-Value="_config.MaxRegionalEvents"
|
||||||
|
Label="Maximum Regional Events"
|
||||||
|
Variant="Variant.Outlined"
|
||||||
|
HelperText="Warning if student has more regional events"
|
||||||
|
Min="0" Max="10" />
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
<MudPaper Class="pa-6 mb-4">
|
||||||
|
<MudText Typo="Typo.h5" Class="mb-4">Required Event Types</MudText>
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudSwitch @bind-Value="_config.RequireRegionalEvent"
|
||||||
|
Label="Require Regional Event"
|
||||||
|
Color="Color.Primary" />
|
||||||
|
<MudText Typo="Typo.body2" Class="mud-text-secondary ml-10">
|
||||||
|
Students must have at least one regional event
|
||||||
|
</MudText>
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudSwitch @bind-Value="_config.RequireOnSiteActivity"
|
||||||
|
Label="Require On-Site Activity"
|
||||||
|
Color="Color.Primary" />
|
||||||
|
<MudText Typo="Typo.body2" Class="mud-text-secondary ml-10">
|
||||||
|
Students must have at least one on-site activity
|
||||||
|
</MudText>
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudSwitch @bind-Value="_config.RequireIndividualEvent"
|
||||||
|
Label="Require Individual Event"
|
||||||
|
Color="Color.Primary" />
|
||||||
|
<MudText Typo="Typo.body2" Class="mud-text-secondary ml-10">
|
||||||
|
Students must have at least one individual event
|
||||||
|
</MudText>
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudSwitch @bind-Value="_config.RequireTeamCaptain"
|
||||||
|
Label="Require Team Captain"
|
||||||
|
Color="Color.Primary" />
|
||||||
|
<MudText Typo="Typo.body2" Class="mud-text-secondary ml-10">
|
||||||
|
Team events must have an assigned captain
|
||||||
|
</MudText>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
<MudPaper Class="pa-6 mb-4">
|
||||||
|
<MudText Typo="Typo.h5" Class="mb-4">Validation Severity Levels</MudText>
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudSelect @bind-Value="_config.NoRegionalEventSeverity"
|
||||||
|
Label="No Regional Event"
|
||||||
|
Variant="Variant.Outlined">
|
||||||
|
<MudSelectItem Value="ValidationSeverity.Warning">Warning</MudSelectItem>
|
||||||
|
<MudSelectItem Value="ValidationSeverity.Error">Error</MudSelectItem>
|
||||||
|
</MudSelect>
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudSelect @bind-Value="_config.NoOnSiteActivitySeverity"
|
||||||
|
Label="No On-Site Activity"
|
||||||
|
Variant="Variant.Outlined">
|
||||||
|
<MudSelectItem Value="ValidationSeverity.Warning">Warning</MudSelectItem>
|
||||||
|
<MudSelectItem Value="ValidationSeverity.Error">Error</MudSelectItem>
|
||||||
|
</MudSelect>
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudSelect @bind-Value="_config.NoIndividualEventSeverity"
|
||||||
|
Label="No Individual Event"
|
||||||
|
Variant="Variant.Outlined">
|
||||||
|
<MudSelectItem Value="ValidationSeverity.Warning">Warning</MudSelectItem>
|
||||||
|
<MudSelectItem Value="ValidationSeverity.Error">Error</MudSelectItem>
|
||||||
|
</MudSelect>
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudSelect @bind-Value="_config.TeamSizeSeverity"
|
||||||
|
Label="Team Size Issues"
|
||||||
|
Variant="Variant.Outlined">
|
||||||
|
<MudSelectItem Value="ValidationSeverity.Warning">Warning</MudSelectItem>
|
||||||
|
<MudSelectItem Value="ValidationSeverity.Error">Error</MudSelectItem>
|
||||||
|
</MudSelect>
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudSelect @bind-Value="_config.EventCountSeverity"
|
||||||
|
Label="Event Count Issues"
|
||||||
|
Variant="Variant.Outlined">
|
||||||
|
<MudSelectItem Value="ValidationSeverity.Warning">Warning</MudSelectItem>
|
||||||
|
<MudSelectItem Value="ValidationSeverity.Error">Error</MudSelectItem>
|
||||||
|
</MudSelect>
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudSelect @bind-Value="_config.MissingCaptainSeverity"
|
||||||
|
Label="Missing Team Captain"
|
||||||
|
Variant="Variant.Outlined">
|
||||||
|
<MudSelectItem Value="ValidationSeverity.Warning">Warning</MudSelectItem>
|
||||||
|
<MudSelectItem Value="ValidationSeverity.Error">Error</MudSelectItem>
|
||||||
|
</MudSelect>
|
||||||
|
</MudItem>
|
||||||
|
<MudItem xs="12" md="6">
|
||||||
|
<MudSelect @bind-Value="_config.TooManyRegionalEventsSeverity"
|
||||||
|
Label="Too Many Regional Events"
|
||||||
|
Variant="Variant.Outlined">
|
||||||
|
<MudSelectItem Value="ValidationSeverity.Warning">Warning</MudSelectItem>
|
||||||
|
<MudSelectItem Value="ValidationSeverity.Error">Error</MudSelectItem>
|
||||||
|
</MudSelect>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
<MudPaper Class="pa-6">
|
||||||
|
<MudGrid>
|
||||||
|
<MudItem xs="12">
|
||||||
|
<MudButton Variant="Variant.Filled"
|
||||||
|
Color="Color.Primary"
|
||||||
|
StartIcon="@Icons.Material.Filled.Save"
|
||||||
|
OnClick="SaveConfiguration"
|
||||||
|
Disabled="_isSaving">
|
||||||
|
@if (_isSaving)
|
||||||
|
{
|
||||||
|
<MudProgressCircular Class="mr-2" Size="Size.Small" Indeterminate="true" />
|
||||||
|
<span>Saving...</span>
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<span>Save Configuration</span>
|
||||||
|
}
|
||||||
|
</MudButton>
|
||||||
|
<MudButton Variant="Variant.Outlined"
|
||||||
|
Class="ml-2"
|
||||||
|
OnClick="ResetToDefaults"
|
||||||
|
Disabled="_isSaving">
|
||||||
|
Reset to Defaults
|
||||||
|
</MudButton>
|
||||||
|
</MudItem>
|
||||||
|
</MudGrid>
|
||||||
|
</MudPaper>
|
||||||
|
|
||||||
|
@if (!string.IsNullOrEmpty(_statusMessage))
|
||||||
|
{
|
||||||
|
<MudAlert Severity="@_statusSeverity" Class="mt-4">@_statusMessage</MudAlert>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<MudProgressCircular Indeterminate="true" />
|
||||||
|
}
|
||||||
|
</MudContainer>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
private ValidationConfiguration? _config;
|
||||||
|
private bool _isSaving;
|
||||||
|
private string? _statusMessage;
|
||||||
|
private Severity _statusSeverity = Severity.Success;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
|
{
|
||||||
|
// Load from IConfiguration
|
||||||
|
_config = Configuration.GetSection("ValidationSettings").Get<ValidationConfiguration>()
|
||||||
|
?? ValidationConfiguration.Default;
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetAppSettingsPath()
|
||||||
|
{
|
||||||
|
return Path.Combine(
|
||||||
|
Environment.ContentRootPath,
|
||||||
|
"Data",
|
||||||
|
"appsettings.json");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SaveConfiguration()
|
||||||
|
{
|
||||||
|
if (_config == null) return;
|
||||||
|
|
||||||
|
_isSaving = true;
|
||||||
|
_statusMessage = null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var appSettingsPath = GetAppSettingsPath();
|
||||||
|
|
||||||
|
// Ensure Data directory exists
|
||||||
|
var dataDir = Path.GetDirectoryName(appSettingsPath);
|
||||||
|
if (dataDir != null && !Directory.Exists(dataDir))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(dataDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read existing appsettings or create new
|
||||||
|
JsonDocument? existingDoc = null;
|
||||||
|
Dictionary<string, object?> settings;
|
||||||
|
|
||||||
|
if (File.Exists(appSettingsPath))
|
||||||
|
{
|
||||||
|
var existingJson = await File.ReadAllTextAsync(appSettingsPath);
|
||||||
|
existingDoc = JsonDocument.Parse(existingJson);
|
||||||
|
settings = JsonSerializer.Deserialize<Dictionary<string, object?>>(existingJson)
|
||||||
|
?? new Dictionary<string, object?>();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
settings = new Dictionary<string, object?>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update ValidationSettings section
|
||||||
|
settings["ValidationSettings"] = _config;
|
||||||
|
|
||||||
|
// Write back to file
|
||||||
|
var options = new JsonSerializerOptions { WriteIndented = true };
|
||||||
|
var json = JsonSerializer.Serialize(settings, options);
|
||||||
|
await File.WriteAllTextAsync(appSettingsPath, json);
|
||||||
|
|
||||||
|
existingDoc?.Dispose();
|
||||||
|
|
||||||
|
_statusMessage = "Configuration saved successfully! Changes will take effect on next application restart.";
|
||||||
|
_statusSeverity = Severity.Success;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_statusMessage = $"Error saving configuration: {ex.Message}";
|
||||||
|
_statusSeverity = Severity.Error;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_isSaving = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ResetToDefaults()
|
||||||
|
{
|
||||||
|
_config = ValidationConfiguration.Default;
|
||||||
|
_statusMessage = "Configuration reset to defaults. Click Save to apply.";
|
||||||
|
_statusSeverity = Severity.Info;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
@using WebApp.Models
|
@using WebApp.Models
|
||||||
|
@using WebApp.Authentication
|
||||||
@inject IConfiguration Configuration
|
@inject IConfiguration Configuration
|
||||||
|
|
||||||
<MudPaper Width="250px" Class="d-inline-flex py-3" Elevation="0">
|
<MudPaper Width="250px" Class="d-inline-flex py-3" Elevation="0">
|
||||||
@@ -20,5 +21,10 @@
|
|||||||
<MudNavLink Href="/students/event-ranking" Icon="@AppIcons.EventRank">Event Ranking</MudNavLink>
|
<MudNavLink Href="/students/event-ranking" Icon="@AppIcons.EventRank">Event Ranking</MudNavLink>
|
||||||
<MudNavLink Href="/teams/assignment" Icon="@AppIcons.TeamAssignment">Team Assignment</MudNavLink>
|
<MudNavLink Href="/teams/assignment" Icon="@AppIcons.TeamAssignment">Team Assignment</MudNavLink>
|
||||||
</MudNavGroup>
|
</MudNavGroup>
|
||||||
|
<AuthorizeView Roles="Administrator">
|
||||||
|
<MudDivider Class="my-2"/>
|
||||||
|
<MudNavLink Href="/settings/chapter" Icon="@Icons.Material.Filled.School">Chapter Settings</MudNavLink>
|
||||||
|
<MudNavLink Href="/settings/validation" Icon="@Icons.Material.Filled.Settings">Validation Settings</MudNavLink>
|
||||||
|
</AuthorizeView>
|
||||||
</MudNavMenu>
|
</MudNavMenu>
|
||||||
</MudPaper>
|
</MudPaper>
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
@using Core.Validation
|
||||||
|
@using WebApp.Models
|
||||||
|
|
||||||
|
@if (Warnings != null && Warnings.Any())
|
||||||
|
{
|
||||||
|
<MudText Style="display: inline-flex; gap: 4px;">
|
||||||
|
@foreach (var warning in Warnings)
|
||||||
|
{
|
||||||
|
var color = warning.Severity == ValidationSeverity.Error ? Color.Error : Color.Warning;
|
||||||
|
var icon = GetIconFromIdentifier(warning.IconIdentifier);
|
||||||
|
|
||||||
|
<MudTooltip Text="@warning.Message">
|
||||||
|
<MudText Style="font-weight:bolder" Color="@color">@icon</MudText>
|
||||||
|
</MudTooltip>
|
||||||
|
}
|
||||||
|
</MudText>
|
||||||
|
}
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter]
|
||||||
|
public List<ValidationWarning>? Warnings { get; set; }
|
||||||
|
|
||||||
|
private string GetIconFromIdentifier(string? identifier)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(identifier))
|
||||||
|
return "";
|
||||||
|
|
||||||
|
return identifier switch
|
||||||
|
{
|
||||||
|
"RegionalEvent" => AppIcons.RegionalEvent,
|
||||||
|
"OnSiteActivity" => AppIcons.OnSiteActivity,
|
||||||
|
"IndividualEvent" => AppIcons.IndividualEvent,
|
||||||
|
"Captain" => AppIcons.Captain,
|
||||||
|
_ => ""
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,9 +17,9 @@ namespace WebApp.Models
|
|||||||
|
|
||||||
return loe switch
|
return loe switch
|
||||||
{
|
{
|
||||||
1 => "‧",
|
1 => "1",
|
||||||
2 => "⁚",
|
2 => "2",
|
||||||
3 => "⁝",
|
3 => "3",
|
||||||
_ => Icons.Material.Filled.QuestionMark
|
_ => Icons.Material.Filled.QuestionMark
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
namespace WebApp.Models;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Configuration for chapter-specific information
|
||||||
|
/// </summary>
|
||||||
|
public class ChapterSettings
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Full chapter name (e.g., "Your Chapter Name")
|
||||||
|
/// </summary>
|
||||||
|
public string Name { get; set; } = "Your Chapter Name";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Short chapter name abbreviation (e.g., "YCN")
|
||||||
|
/// </summary>
|
||||||
|
public string ShortName { get; set; } = "YCN";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// National chapter ID (4 digits, e.g., "0000")
|
||||||
|
/// </summary>
|
||||||
|
public string NationalId { get; set; } = "0000";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// State chapter ID (5 digits, e.g., "00000")
|
||||||
|
/// </summary>
|
||||||
|
public string StateId { get; set; } = "00000";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Regional chapter ID (5 digits, e.g., "00000")
|
||||||
|
/// </summary>
|
||||||
|
public string RegionalId { get; set; } = "00000";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Competition year (e.g., "2026")
|
||||||
|
/// </summary>
|
||||||
|
public string CompetitionYear { get; set; } = "2026";
|
||||||
|
}
|
||||||
+31
-18
@@ -11,13 +11,11 @@ using WebApp.Logging;
|
|||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Load optional appsettings from Data directory in production (overrides defaults)
|
// Load appsettings from Data directory (works in both development and production)
|
||||||
// In development, use appsettings.Development.json instead
|
// This allows runtime configuration changes without touching the codebase
|
||||||
if (builder.Environment.IsProduction())
|
var dataAppSettingsPath = Path.Combine(builder.Environment.ContentRootPath, "Data", "appsettings.json");
|
||||||
|
if (!File.Exists(dataAppSettingsPath))
|
||||||
{
|
{
|
||||||
var dataAppSettingsPath = Path.Combine(builder.Environment.ContentRootPath, "Data", "appsettings.json");
|
|
||||||
if (!File.Exists(dataAppSettingsPath))
|
|
||||||
{
|
|
||||||
Console.WriteLine($"appsettings.json not found at {dataAppSettingsPath}. Creating from template...");
|
Console.WriteLine($"appsettings.json not found at {dataAppSettingsPath}. Creating from template...");
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -25,31 +23,38 @@ if (builder.Environment.IsProduction())
|
|||||||
// Ensure Data directory exists
|
// Ensure Data directory exists
|
||||||
Directory.CreateDirectory(Path.Combine(builder.Environment.ContentRootPath, "Data"));
|
Directory.CreateDirectory(Path.Combine(builder.Environment.ContentRootPath, "Data"));
|
||||||
|
|
||||||
// Copy ChapterSettings from the base appsettings.json
|
// Copy ChapterSettings and ValidationSettings from the base appsettings.json
|
||||||
var baseAppSettingsPath = Path.Combine(builder.Environment.ContentRootPath, "appsettings.json");
|
var baseAppSettingsPath = Path.Combine(builder.Environment.ContentRootPath, "appsettings.json");
|
||||||
if (File.Exists(baseAppSettingsPath))
|
if (File.Exists(baseAppSettingsPath))
|
||||||
{
|
{
|
||||||
var baseConfig = File.ReadAllText(baseAppSettingsPath);
|
var baseConfig = File.ReadAllText(baseAppSettingsPath);
|
||||||
var baseDoc = JsonDocument.Parse(baseConfig);
|
var baseDoc = JsonDocument.Parse(baseConfig);
|
||||||
|
|
||||||
|
var templateSettings = new Dictionary<string, object?>();
|
||||||
|
|
||||||
if (baseDoc.RootElement.TryGetProperty("ChapterSettings", out var chapterSettings))
|
if (baseDoc.RootElement.TryGetProperty("ChapterSettings", out var chapterSettings))
|
||||||
{
|
{
|
||||||
var templateSettings = new
|
templateSettings["ChapterSettings"] = JsonSerializer.Deserialize<object>(chapterSettings.GetRawText());
|
||||||
{
|
}
|
||||||
ChapterSettings = JsonSerializer.Deserialize<object>(chapterSettings.GetRawText())
|
|
||||||
};
|
|
||||||
|
|
||||||
|
if (baseDoc.RootElement.TryGetProperty("ValidationSettings", out var validationSettings))
|
||||||
|
{
|
||||||
|
templateSettings["ValidationSettings"] = JsonSerializer.Deserialize<object>(validationSettings.GetRawText());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (templateSettings.Any())
|
||||||
|
{
|
||||||
var json = JsonSerializer.Serialize(templateSettings, new JsonSerializerOptions
|
var json = JsonSerializer.Serialize(templateSettings, new JsonSerializerOptions
|
||||||
{
|
{
|
||||||
WriteIndented = true
|
WriteIndented = true
|
||||||
});
|
});
|
||||||
|
|
||||||
File.WriteAllText(dataAppSettingsPath, json);
|
File.WriteAllText(dataAppSettingsPath, json);
|
||||||
Console.WriteLine("appsettings.json created in Data directory. Please update ChapterSettings with your chapter information.");
|
Console.WriteLine("appsettings.json created in Data directory.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("WARNING: ChapterSettings not found in base appsettings.json");
|
Console.WriteLine("WARNING: No settings to copy from base appsettings.json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,14 +62,13 @@ if (builder.Environment.IsProduction())
|
|||||||
{
|
{
|
||||||
Console.WriteLine($"WARNING: Unable to create appsettings.json: {ex.Message}");
|
Console.WriteLine($"WARNING: Unable to create appsettings.json: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Data/appsettings.json as additional configuration source
|
// Add Data/appsettings.json as additional configuration source (all environments)
|
||||||
if (File.Exists(dataAppSettingsPath))
|
if (File.Exists(dataAppSettingsPath))
|
||||||
{
|
{
|
||||||
builder.Configuration.AddJsonFile(dataAppSettingsPath, optional: true, reloadOnChange: true);
|
builder.Configuration.AddJsonFile(dataAppSettingsPath, optional: true, reloadOnChange: true);
|
||||||
Console.WriteLine($"Loaded configuration from {dataAppSettingsPath}");
|
Console.WriteLine($"Loaded configuration from {dataAppSettingsPath}");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure Serilog with custom handling for antiforgery errors
|
// Configure Serilog with custom handling for antiforgery errors
|
||||||
@@ -172,6 +176,15 @@ builder.Services.AddScoped<WebApp.LocalStorageService>();
|
|||||||
// State container for maintaining state per user connection (Blazor Server)
|
// State container for maintaining state per user connection (Blazor Server)
|
||||||
builder.Services.AddScoped<StateContainer>();
|
builder.Services.AddScoped<StateContainer>();
|
||||||
|
|
||||||
|
// Load validation configuration from appsettings (or use default if not found)
|
||||||
|
var validationConfig = builder.Configuration
|
||||||
|
.GetSection("ValidationSettings")
|
||||||
|
.Get<Core.Validation.ValidationConfiguration>() ?? Core.Validation.ValidationConfiguration.Default;
|
||||||
|
|
||||||
|
// Validation service with loaded configuration
|
||||||
|
builder.Services.AddScoped<Core.Validation.ValidationService>(sp =>
|
||||||
|
new Core.Validation.ValidationService(validationConfig));
|
||||||
|
|
||||||
// Add authentication services
|
// Add authentication services
|
||||||
builder.Services.AddHttpContextAccessor();
|
builder.Services.AddHttpContextAccessor();
|
||||||
builder.Services.AddScoped<AuthenticationService>();
|
builder.Services.AddScoped<AuthenticationService>();
|
||||||
|
|||||||
@@ -17,5 +17,23 @@
|
|||||||
"StateId": "00000",
|
"StateId": "00000",
|
||||||
"RegionalId": "00000",
|
"RegionalId": "00000",
|
||||||
"CompetitionYear": "2026"
|
"CompetitionYear": "2026"
|
||||||
|
},
|
||||||
|
"ValidationSettings": {
|
||||||
|
"MinRecommendedEvents": 2,
|
||||||
|
"MaxRecommendedEvents": 4,
|
||||||
|
"MinCriticalEvents": 1,
|
||||||
|
"MaxCriticalEvents": 6,
|
||||||
|
"MaxRegionalEvents": 3,
|
||||||
|
"RequireRegionalEvent": true,
|
||||||
|
"RequireOnSiteActivity": true,
|
||||||
|
"RequireIndividualEvent": false,
|
||||||
|
"RequireTeamCaptain": true,
|
||||||
|
"NoRegionalEventSeverity": "Warning",
|
||||||
|
"NoOnSiteActivitySeverity": "Warning",
|
||||||
|
"NoIndividualEventSeverity": "Warning",
|
||||||
|
"TeamSizeSeverity": "Warning",
|
||||||
|
"EventCountSeverity": "Warning",
|
||||||
|
"MissingCaptainSeverity": "Warning",
|
||||||
|
"TooManyRegionalEventsSeverity": "Warning"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,3 +93,15 @@ h1:focus {
|
|||||||
.event-rank-4 { background-color: #ffe599; }
|
.event-rank-4 { background-color: #ffe599; }
|
||||||
.event-rank-5 { background-color: #fff2cc; }
|
.event-rank-5 { background-color: #fff2cc; }
|
||||||
.event-rank-6 { background-color: #fffaea; }
|
.event-rank-6 { background-color: #fffaea; }
|
||||||
|
|
||||||
|
.numberCircle {
|
||||||
|
display: flex;
|
||||||
|
width: fit-content;
|
||||||
|
/* min-width: .2rem; */
|
||||||
|
padding: 0;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
aspect-ratio: 10/1;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 1px solid;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user