Notification.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System.ComponentModel.DataAnnotations;
  2. using System.ComponentModel.DataAnnotations.Schema;
  3. using Domain.Entities.Members;
  4. using Domain.Entities.Notifications.ValueObject;
  5. namespace Domain.Entities.Notifications;
  6. public class Notification
  7. {
  8. [ForeignKey(nameof(MemberID))]
  9. public virtual Member? Member { get; private set; }
  10. [Key]
  11. public int ID { get; private set; }
  12. public int MemberID { get; private set; }
  13. public NotificationType Type { get; private set; }
  14. public string Title { get; private set; } = default!;
  15. public string Message { get; private set; } = default!;
  16. public bool IsRead { get; private set; }
  17. public string? ActionUrl { get; private set; }
  18. public string? RelatedType { get; private set; }
  19. public int? RelatedID { get; private set; }
  20. public string? ImageUrl { get; private set; }
  21. public DateTime? ReadAt { get; private set; }
  22. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  23. private Notification() { }
  24. public static Notification Create(
  25. int memberID,
  26. NotificationType type,
  27. string title,
  28. string message,
  29. string? actionUrl = null,
  30. string? relatedType = null,
  31. int? relatedID = null,
  32. string? imageUrl = null
  33. )
  34. {
  35. return new Notification
  36. {
  37. MemberID = memberID,
  38. Type = type,
  39. Title = title,
  40. Message = message,
  41. ActionUrl = actionUrl,
  42. RelatedType = relatedType,
  43. RelatedID = relatedID,
  44. ImageUrl = imageUrl
  45. };
  46. }
  47. public void MarkRead()
  48. {
  49. if (!IsRead)
  50. {
  51. IsRead = true;
  52. ReadAt = DateTime.UtcNow;
  53. }
  54. }
  55. }