2026-04-09 10:36:09 +02:00
|
|
|
using System;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
|
|
|
|
|
namespace TournamentOrganizer.Models;
|
|
|
|
|
|
|
|
|
|
public class Tournament
|
|
|
|
|
{
|
|
|
|
|
[Key]
|
|
|
|
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
|
|
|
|
public int Id { get; set; }
|
|
|
|
|
public int GameId { get; set; }
|
|
|
|
|
public int EventId { get; set; }
|
2026-04-10 15:56:45 +02:00
|
|
|
[CustomValidation(typeof(Tournament), nameof(ValidateDates))]
|
2026-04-09 10:36:09 +02:00
|
|
|
public DateTime Start { get; set; }
|
2026-04-10 15:56:45 +02:00
|
|
|
[CustomValidation(typeof(Tournament), nameof(ValidateDates))]
|
2026-04-09 10:36:09 +02:00
|
|
|
public DateTime End { get; set; }
|
|
|
|
|
|
|
|
|
|
public RuleSet S1RuleSet { get; set; }
|
2026-04-09 12:08:52 +02:00
|
|
|
public int? S1Groups { get; set; }
|
|
|
|
|
public int? S1GroupAdvances { get; set; }
|
2026-04-09 10:36:09 +02:00
|
|
|
public RuleSet? S2RuleSet { get; set; }
|
|
|
|
|
|
|
|
|
|
public required Game Game { get; set; }
|
|
|
|
|
public required Event Event { get; set; }
|
|
|
|
|
|
2026-04-10 15:56:45 +02:00
|
|
|
public static ValidationResult ValidateDates(DateTime date, ValidationContext context)
|
|
|
|
|
{
|
|
|
|
|
Tournament instance = (Tournament)context.ObjectInstance;
|
|
|
|
|
if (date >= instance.Event.Start && date <= instance.Event.End)
|
|
|
|
|
return ValidationResult.Success;
|
|
|
|
|
return new("Tournament must take place during the event.");
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-09 10:36:09 +02:00
|
|
|
}
|