Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

76 строки
2.0KB

  1. namespace CartWise.Domain.Entities;
  2. public class PurchaseItem
  3. {
  4. public Guid PurchaseItemId { get; private set; }
  5. public Guid PurchaseId { get; private set; }
  6. public Guid? ProductId { get; private set; }
  7. public Guid? GroceryConceptId { get; private set; }
  8. public Guid? ShoppingListItemId { get; private set; }
  9. public string Description { get; private set; } = null!;
  10. public decimal Quantity { get; private set; }
  11. public string? Unit { get; private set; }
  12. public decimal LinePrice { get; private set; }
  13. public decimal? UnitPrice { get; private set; }
  14. public DateTime CreatedUtc { get; private set; }
  15. private PurchaseItem()
  16. {
  17. }
  18. public PurchaseItem(
  19. Guid purchaseId,
  20. string description,
  21. decimal linePrice,
  22. DateTime createdUtc,
  23. decimal quantity = 1m,
  24. string? unit = null,
  25. Guid? productId = null,
  26. Guid? groceryConceptId = null,
  27. Guid? shoppingListItemId = null,
  28. decimal? unitPrice = null)
  29. {
  30. if (purchaseId == Guid.Empty)
  31. {
  32. throw new ArgumentException("PurchaseId is required.", nameof(purchaseId));
  33. }
  34. if (string.IsNullOrWhiteSpace(description))
  35. {
  36. throw new ArgumentException("Description is required.", nameof(description));
  37. }
  38. if (quantity <= 0)
  39. {
  40. throw new ArgumentOutOfRangeException(nameof(quantity), "Quantity must be greater than zero.");
  41. }
  42. if (linePrice < 0)
  43. {
  44. throw new ArgumentOutOfRangeException(nameof(linePrice), "LinePrice cannot be negative.");
  45. }
  46. PurchaseItemId = Guid.NewGuid();
  47. PurchaseId = purchaseId;
  48. Description = description.Trim();
  49. Quantity = quantity;
  50. Unit = unit;
  51. LinePrice = linePrice;
  52. UnitPrice = unitPrice;
  53. ProductId = productId;
  54. GroceryConceptId = groceryConceptId;
  55. ShoppingListItemId = shoppingListItemId;
  56. CreatedUtc = createdUtc;
  57. }
  58. }

Powered by TurnKey Linux.