Keep legal first and last names for formal lists; show DisplayFirstName on teams, calendars, and import matching so two Josiahs can be told apart. Co-authored-by: Cursor <cursoragent@cursor.com>
108 lines
3.0 KiB
C#
108 lines
3.0 KiB
C#
using System.ComponentModel.DataAnnotations;
|
|
using static System.Text.RegularExpressions.Regex;
|
|
|
|
namespace Core.Entities;
|
|
|
|
public class Student : IEquatable<Student>
|
|
{
|
|
public int Id { get; set; }
|
|
|
|
[Required]
|
|
[StringLength(50,MinimumLength = 2)]
|
|
[Display(Name = "First Name")]
|
|
public string FirstName { get; set; } = null!;
|
|
|
|
[Required]
|
|
[StringLength(50, MinimumLength = 2)]
|
|
[Display(Name = "Last Name")]
|
|
public string LastName { get; set; } = null!;
|
|
|
|
[StringLength(50)]
|
|
[Display(Name = "Nickname")]
|
|
public string? Nickname { get; set; }
|
|
|
|
[Range(5,12)]
|
|
[Display(Name = "Grade")]
|
|
public int Grade { get; set; }
|
|
|
|
[EmailAddress]
|
|
[Display(Name = "Email Address")]
|
|
public string? Email { get; set; }
|
|
|
|
[Phone]
|
|
[Display(Name = "Phone Number")]
|
|
public string? PhoneNumber { get; set; }
|
|
|
|
[Display(Name = "TSA Year")]
|
|
public int TsaYear { get; set; }
|
|
|
|
[Display(Name = "State Id")]
|
|
public string? StateId { get; set; }
|
|
|
|
[Display(Name = "Regional Id")]
|
|
public string? RegionalId { get; set; }
|
|
|
|
[Display(Name = "National Id")]
|
|
public string? NationalId { get; set; }
|
|
|
|
[Display(Name = "Officer Role")]
|
|
public OfficerRole? OfficerRole { get; set; }
|
|
|
|
public List<Team> Teams { get; set; } = null!;
|
|
public List<EventDefinition> RankedEvents { get; } = [];
|
|
public List<StudentEventRanking> EventRankings { get; } = [];
|
|
|
|
|
|
public string Name => FirstNameLastName;
|
|
|
|
public string LastNameFirstName => $"{LastName}, {FirstName}";
|
|
|
|
public string FirstNameLastName => $"{FirstName} {LastName}";
|
|
|
|
/// <summary>
|
|
/// Nickname when set, otherwise <see cref="FirstName"/>.
|
|
/// </summary>
|
|
public string DisplayFirstName =>
|
|
string.IsNullOrWhiteSpace(Nickname) ? FirstName : Nickname.Trim();
|
|
|
|
public void NormalizeNickname()
|
|
{
|
|
Nickname = string.IsNullOrWhiteSpace(Nickname) ? null : Nickname.Trim();
|
|
}
|
|
|
|
public static Tuple<string, string> ParseNameParts(string fullName)
|
|
{
|
|
var match = Match(fullName, @"(.*),\s*(.*)");
|
|
if (match.Success)
|
|
return Tuple.Create(match.Groups[2].Value, match.Groups[1].Value);
|
|
match = Match(fullName, @"(.*)\s*(.*)");
|
|
return
|
|
match.Success
|
|
? Tuple.Create(match.Groups[1].Value, match.Groups[2].Value)
|
|
: new Tuple<string, string>(fullName, string.Empty);
|
|
}
|
|
|
|
public override string ToString() => DisplayFirstName;
|
|
|
|
public bool VotingDelegate => OfficerRole is Entities.OfficerRole.President or Entities.OfficerRole.VicePresident;
|
|
|
|
public bool Equals(Student? other)
|
|
{
|
|
if (other is null) return false;
|
|
if (ReferenceEquals(this, other)) return true;
|
|
return Id == other.Id;
|
|
}
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
if (obj is null) return false;
|
|
if (ReferenceEquals(this, obj)) return true;
|
|
if (obj.GetType() != GetType()) return false;
|
|
return Equals((Student)obj);
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
return Id;
|
|
}
|
|
} |