ApplicationUser.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 SetDeleted(bool isDeleted)
  32. {
  33. IsDeleted = isDeleted;
  34. }
  35. }
  36. }