Exemplo n.º 1
0
        public void AddToStorehouse(Storehouse storehouse, int quantity)
        {
            var storehouseItem         = StorehouseItem.Create(this.Quantity, storehouse.Id, this.Id, this.Price);
            var storehouseItemToUpdate = this.StorehouseItems.FirstOrDefault(x => x.Equals(storehouseItem));

            if (storehouseItemToUpdate == null)
            {
                this.StorehouseItems.Add(storehouseItem);
            }
            else
            {
                storehouseItemToUpdate.AddQiantity(this.Quantity);
            }
        }
Exemplo n.º 2
0
        public void AddItem(int quantity, InvoiceItem item)
        {
            if (quantity > item.Quantity)
            {
                throw new ArgumentOutOfRangeException("quantity", "Not enough quantity available of the selected item.");
            }

            var storehouseItem = StorehouseItem.Create(quantity, this.Id, item.Id, item.Price);
            var itemToUpdate   = this.StorehouseItems.FirstOrDefault(x => x.Equals(storehouseItem));

            if (itemToUpdate == null)
            {
                this.StorehouseItems.Add(storehouseItem);
            }
            else
            {
                itemToUpdate.AddQiantity(quantity);
            }
        }
Exemplo n.º 3
0
        public static InvoiceItem Create(
            Dictionary <Storehouse, int> quantities, decimal price, Item item, Invoice invoice)
        {
            var invoiceItemQuantity = quantities.Sum(x => x.Value);
            var invoiceItem         = new InvoiceItem()
            {
                Quantity        = invoiceItemQuantity,
                Price           = price,
                ItemId          = item.Id,
                InvoiceId       = invoice.Id,
                StorehouseItems = new HashSet <StorehouseItem>()
            };

            foreach (var storehouse in quantities.Keys)
            {
                var storehouseItem = StorehouseItem.Create(quantities[storehouse], storehouse.Id, invoiceItem.Id, invoiceItem.Price);
                invoiceItem.AddToStorehouse(storehouse, quantities[storehouse]);
            }

            return(invoiceItem);
        }