f8c22690d4
This commit introduces two new utility classes: StudentNameFormatter and TeamStudentNameFormatter, which provide methods for formatting student names with options for indicating absence and overlaps. The Team class has been updated to remove the StudentsFirstNames property, and various components across the WebApp have been refactored to utilize the new formatting utilities. This enhances the maintainability and readability of the code while improving the presentation of student names in the UI.
66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using Core.Models;
|
|
|
|
namespace Core.Entities;
|
|
public class Team
|
|
{
|
|
public int Id { get; set; }
|
|
|
|
[Required]
|
|
public EventDefinition Event { get; set; } = null!;
|
|
|
|
public List<Student> Students { get; set; } = [];
|
|
|
|
public Student? Captain { get; set; }
|
|
|
|
[Display(Name = "Team Identifier")]
|
|
[StringLength(32)]
|
|
public string? Identifier { get; set; }
|
|
|
|
|
|
// public Tuple<DateTime,DateTime?>? RegionalTimeSlotObj
|
|
//{
|
|
// get
|
|
// {
|
|
|
|
// if (string.IsNullOrEmpty(RegionalTimeSlot))
|
|
// return null;
|
|
// var times = Regex.Matches(RegionalTimeSlot, @"(.*)\s*-\s*(.*)");
|
|
// if (times.Count == 0)
|
|
// return Tuple.Create(P(RegionalTimeSlot), (DateTime?)null);
|
|
// var match = times[0];
|
|
// if (!match.Success)
|
|
// return Tuple.Create(P(RegionalTimeSlot), (DateTime?)null);
|
|
|
|
// return Tuple.Create(P(match.Groups[1].Value), (DateTime?)P(match.Groups[2].Value));
|
|
// return null;
|
|
// }
|
|
//}
|
|
|
|
private DateTime P(string s)
|
|
{
|
|
var dt = DateTime.Parse(s);
|
|
if (dt.TimeOfDay < TimeSpan.FromHours(7))
|
|
return dt + TimeSpan.FromHours(12);
|
|
return dt;
|
|
}
|
|
|
|
public virtual Team CloneWithOmittedStudents(IEnumerable<Student> studentsToOmit)
|
|
{
|
|
var studentsToOmitList = studentsToOmit.ToList();
|
|
var omittedStudents = Students.Where(studentsToOmitList.Contains).ToList();
|
|
if (omittedStudents.Count == 0)
|
|
return new Team{Captain = Captain, Event = Event, Students = Students.ToList(), Identifier = Identifier, Id = Id};
|
|
|
|
var remainingStudents = Students.Where(s => !studentsToOmitList.Contains(s)).ToList();
|
|
return new PartialTeam { Event = Event, Students = remainingStudents, OmittedStudents = omittedStudents, Identifier = Identifier, Id = Id};
|
|
}
|
|
|
|
public Team Clone() => CloneWithOmittedStudents([]);
|
|
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"{Event.Name} {(Identifier != null ? $"({Identifier})" : "")}";
|
|
}
|
|
} |