1 parent
84ad43af76
commit
3f54e6eb2f
48 files changed
+21367
-33
No files matched your search
@@ -8,34 +8,4 @@ public sealed class Person
|
||||
|
||||
public DateOnly Birthday { get; }
|
||||
|
||||
private Person(String username, String realName, DateOnly birthday)
|
||||
{
|
||||
Username = username;
|
||||
RealName = realName;
|
||||
Birthday = birthday;
|
||||
}
|
||||
|
||||
public static Person Create(String username, String realName, DateOnly birthday)
|
||||
{
|
||||
username = NormalizeUsername(username);
|
||||
realName = realName.Trim();
|
||||
|
||||
// TODO: Error Handling
|
||||
if (username.Length is < 3 or > 32) throw new Exception();
|
||||
if (realName.Length == 0) throw new Exception();
|
||||
if (birthday >= DateOnly.FromDateTime(DateTime.Today)) throw new Exception();
|
||||
if (!IsAtLeast16(birthday)) throw new Exception();
|
||||
|
||||
return new Person(username, realName, birthday);
|
||||
}
|
||||
|
||||
// Konstruktor zum Erzeugen von Nutzerobjekten aus der Datenbank
|
||||
internal static Person FromStorage(String username, String realName, DateOnly birthday)
|
||||
=> new(username, realName, birthday);
|
||||
|
||||
public static String NormalizeUsername(String username)
|
||||
=> username.Trim().ToLowerInvariant();
|
||||
|
||||
public static bool IsAtLeast16(DateOnly birthday)
|
||||
=> birthday.AddYears(16) <= DateOnly.FromDateTime(DateTime.Today);
|
||||
}
|
||||
Reference in new issue
Block a user