EmailVerifyNumber.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Domain.Entities.EmailVerification.ValueObject;
  2. namespace Domain.Entities.EmailVerification
  3. {
  4. public class EmailVerifyNumber
  5. {
  6. public int ID { get; private set; }
  7. public VerificationType Type { get; private set; }
  8. public string Email { get; private set; } = default!;
  9. public string Code { get; private set; } = default!;
  10. public bool IsVerified { get; private set; } = false;
  11. public DateTime Expiration { get; private set; }
  12. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  13. private EmailVerifyNumber() { }
  14. private EmailVerifyNumber(VerificationType type, string email, string code, DateTime expiration)
  15. {
  16. if (string.IsNullOrWhiteSpace(email))
  17. {
  18. throw new ArgumentException("Email is required.", nameof(email));
  19. }
  20. if (email.Length > 60)
  21. {
  22. throw new ArgumentOutOfRangeException(nameof(email));
  23. }
  24. if (string.IsNullOrWhiteSpace(code))
  25. {
  26. throw new ArgumentException("Code is required.", nameof(code));
  27. }
  28. if (code.Length > 10)
  29. {
  30. throw new ArgumentOutOfRangeException(nameof(code));
  31. }
  32. Type = type;
  33. Email = email;
  34. Code = code;
  35. Expiration = expiration;
  36. CreatedAt = DateTime.UtcNow;
  37. }
  38. public static EmailVerifyNumber Create(VerificationType type, string email, string code, DateTime expiration)
  39. {
  40. return new(type, email, code, expiration);
  41. }
  42. public void MarkVerified()
  43. {
  44. IsVerified = true;
  45. }
  46. }
  47. }