37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
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; }
|
|
[CustomValidation(typeof(Tournament), nameof(ValidateDates))]
|
|
public DateTime Start { get; set; }
|
|
[CustomValidation(typeof(Tournament), nameof(ValidateDates))]
|
|
public DateTime End { get; set; }
|
|
|
|
public RuleSet S1RuleSet { get; set; }
|
|
public int? S1Groups { get; set; }
|
|
public int? S1GroupAdvances { get; set; }
|
|
public RuleSet? S2RuleSet { get; set; }
|
|
|
|
public Game Game { get; set; } = null!;
|
|
public Event Event { get; set; } = null!;
|
|
public List<TournamentTeam> TournamentTeams { get; set; } = [];
|
|
|
|
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.");
|
|
}
|
|
|
|
} |