ApplicationUser.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Microsoft.AspNetCore.Identity;
  2. using System.ComponentModel.DataAnnotations.Schema;
  3. namespace Infrastructure.Persistence.Identity
  4. {
  5. public sealed class ApplicationUser : IdentityUser
  6. {
  7. [NotMapped]
  8. public string ID
  9. {
  10. get => Id;
  11. private set => Id = value;
  12. }
  13. public string? FullName { get; private set; }
  14. public bool IsDeleted { get; private set; } = false;
  15. // EF Core / Identity requires a public parameterless ctor
  16. public ApplicationUser() { }
  17. private ApplicationUser(string id)
  18. {
  19. if (string.IsNullOrWhiteSpace(id))
  20. {
  21. throw new ArgumentException("ID is required.", nameof(id));
  22. }
  23. ID = id;
  24. }
  25. public static ApplicationUser Create(string id, string? fullName = null)
  26. {
  27. var user = new ApplicationUser(id);
  28. user.FullName = fullName;
  29. return user;
  30. }
  31. public void SetFullName(string? fullName)
  32. {
  33. FullName = string.IsNullOrWhiteSpace(fullName) ? null : fullName.Trim();
  34. }
  35. public void SetDeleted(bool isDeleted)
  36. {
  37. IsDeleted = isDeleted;
  38. }
  39. }
  40. }