DonationMeta.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.ComponentModel.DataAnnotations;
  2. using System.ComponentModel.DataAnnotations.Schema;
  3. using Domain.Entities.Donations.ValueObject;
  4. using Domain.Entities.Members;
  5. namespace Domain.Entities.Donations;
  6. public class DonationMeta
  7. {
  8. [ForeignKey(nameof(ChannelID))]
  9. public virtual Channel? Channel { get; private set; }
  10. [ForeignKey(nameof(MemberID))]
  11. public virtual Member? Member { get; private set; }
  12. [Key]
  13. public int ID { get; private set; }
  14. public int ChannelID { get; private set; }
  15. public int MemberID { get; private set; }
  16. public int MinAmount { get; private set; } = DonationConstants.MinAmount;
  17. public bool IsPaused { get; private set; }
  18. public bool IsAccepting { get; private set; } = true;
  19. public bool IsAudioOnly { get; private set; }
  20. public bool IsVideoOnly { get; private set; }
  21. public DateTime? UpdatedAt { get; private set; }
  22. public DateTime CreatedAt { get; private set; } = DateTime.UtcNow;
  23. private DonationMeta() { }
  24. public static DonationMeta Create(int channelID, int memberID)
  25. {
  26. return new DonationMeta
  27. {
  28. ChannelID = channelID,
  29. MemberID = memberID
  30. };
  31. }
  32. public void UpdateSettings(int minAmount, bool isAccepting)
  33. {
  34. MinAmount = minAmount;
  35. IsAccepting = isAccepting;
  36. UpdatedAt = DateTime.UtcNow;
  37. }
  38. public void UpdateRemoteState(bool isPaused, bool isAudioOnly, bool isVideoOnly)
  39. {
  40. IsPaused = isPaused;
  41. IsAudioOnly = isAudioOnly;
  42. IsVideoOnly = isVideoOnly;
  43. UpdatedAt = DateTime.UtcNow;
  44. }
  45. public void Pause() { IsPaused = true; UpdatedAt = DateTime.UtcNow; }
  46. public void Resume() { IsPaused = false; UpdatedAt = DateTime.UtcNow; }
  47. public void StopAccepting() { IsAccepting = false; UpdatedAt = DateTime.UtcNow; }
  48. public void StartAccepting() { IsAccepting = true; UpdatedAt = DateTime.UtcNow; }
  49. }