EmailVerifyNumber.cs 1.6 KB

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