using CandyHouseBase.Exceptions; using CandyHouseBase.Extensions; using CandyHouseBase.Infrastructure; namespace CandyHouseBase.DataModels { public class OrderItemDataModel : IValidation { public string OrderId { get; private set; } public string ProductId { get; private set; } public int Quantity { get; private set; } public decimal Price { get; private set; } // Цена на момент заказа public OrderItemDataModel(string orderId, string productId, int quantity, decimal price) { OrderId = orderId; ProductId = productId; Quantity = quantity; Price = price; } public void Validate() { if (!OrderId.IsGuid()) throw new ValidationException("OrderId must be a GUID"); if (!ProductId.IsGuid()) throw new ValidationException("ProductId must be a GUID"); if (Quantity <= 0) throw new ValidationException("Quantity must be positive"); if (Price < 0) throw new ValidationException("Price cannot be negative"); } } }