Exemple #1
0
        public ProductQuantity GetProductQuantity(ProductCode prodCode)         // vraci imutabilni objekt, takze invarianty agregatu neni jak zmenit
        {
            if (prodCode == null)
            {
                throw new ArgumentNullException(nameof(prodCode));
            }

            var item = TryGetInvoiceItem(prodCode);

            if (item == null)
            {
                throw new InvalidOperationException($"No invoice item found for product code {prodCode}");
            }

            return(item.ProductQuantity);
        }
Exemple #2
0
        public void AddProductItem(ProductCode prodCode, ProductQuantity quantity)
        {
            if (prodCode == null)
            {
                throw new ArgumentNullException(nameof(prodCode));
            }
            if (quantity == null)
            {
                throw new ArgumentNullException(nameof(quantity));
            }

            // kontrola invariantu agregatu
            var item = TryGetInvoiceItem(prodCode);

            if (item != null)
            {
                throw new InvalidOperationException($"Invoice item already exists for product code {prodCode}");
            }

            _items[prodCode] = new InvoiceItem(prodCode, quantity);
        }
Exemple #3
0
 public InvoiceItem(ProductCode productCode, ProductQuantity productQuantity)
 {
     ProductCode     = productCode ?? throw new ArgumentNullException(nameof(productCode));
     ProductQuantity = productQuantity ?? throw new ArgumentNullException(nameof(productQuantity));
 }
Exemple #4
0
 private InvoiceItem TryGetInvoiceItem(ProductCode prodCode)
 {
     _items.TryGetValue(prodCode, out var item);
     return(item);
 }