fixed update function
This commit is contained in:
1 parent
ec91488f9a
commit
5fa35536cc
2 files changed
+17
-4
No files matched your search
+13
-1
@@ -31,10 +31,22 @@ public sealed class Person
|
||||
return new Person(username, realName, birthday);
|
||||
}
|
||||
|
||||
public void Update(string realName, DateOnly birthday)
|
||||
{
|
||||
realName = realName.Trim();
|
||||
|
||||
if (realName.Length == 0) throw new ArgumentException("Name cannot be empty");
|
||||
if (!IsAtLeast16(birthday) || birthday >= DateOnly.FromDateTime(DateTime.Today))
|
||||
throw new ArgumentException("Person must be at least 16 years old.");
|
||||
|
||||
RealName = realName;
|
||||
Birthday = 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();
|
||||
|
||||
|
||||
@@ -45,11 +45,12 @@ namespace api.Services
|
||||
|
||||
public async Task UpdatePersonAsync(string username, PersonDto personDto)
|
||||
{
|
||||
Person person = await PersonExists(username);
|
||||
|
||||
await PersonExists(username);
|
||||
string updatedName = string.IsNullOrWhiteSpace(personDto.RealName) ? person.RealName : personDto.RealName;
|
||||
|
||||
Person updatedPerson = Person.Create(username: username, realName: personDto.RealName, birthday: personDto.Birthday);
|
||||
await _personRepository.UpdateAsync(updatedPerson);
|
||||
person.Update(realName: updatedName, birthday: personDto.Birthday);
|
||||
await _personRepository.UpdateAsync(person);
|
||||
}
|
||||
|
||||
public async Task DeletePersonAsync(string username)
|
||||
|
||||
Reference in new issue
Block a user