Esempio n. 1
0
        public BookStock(ActiveDelivery activeDelivery, IDeliveryItem item)
        {
            if (item is not ActiveDeliveryItem)
            {
                throw new ArgumentException($"Passed Delivery Item is not of type {nameof(ActiveDeliveryItem)}");
            }
            if (item is null)
            {
                throw new ArgumentException("DeliveryItem cannot be null");
            }
            if (activeDelivery is null)
            {
                throw new ArgumentException("ActiveDelivery cannot be null");
            }
            if (!activeDelivery.Items.Any(i => i.BookEan.Code.Equals(item.BookEan.Code)))
            {
                throw new ArgumentException($"ActiveDelivery: {activeDelivery.Id} do not contain ean {item.BookEan.Code}");
            }

            BookEan13 = new BookEan13ForStock(item.BookEan.Code);
            BookId    = item.BookId;

            ModificationDate = DateTime.UtcNow;
            CreationDate     = DateTime.UtcNow;
        }
Esempio n. 2
0
        public CancelledDelivery(ActiveDelivery activeDelivery, string cancellationReason = default)
        {
            if (activeDelivery.IsAnyDeliveryItemsScanned)
            {
                throw new ArgumentException(
                          "You cannot move active delivery to cancelled if there is any scanned items");
            }

            DeliveryStatus   = DeliveryStatus.Cancelled;
            ModificationDate = DateTime.UtcNow;
            CreationDate     = DateTime.UtcNow;

            ActiveDeliveryId = activeDelivery.Id;
            _items           = activeDelivery.Items
                               .Select(i => new CancelledDeliveryItem(i.BookId, i.BookEan, i.ItemsCount)).ToList();
            CancellationReason = cancellationReason;
        }
Esempio n. 3
0
        public CompletedDelivery(ActiveDelivery activeDelivery, IEnumerable <BookStock> stocks)
        {
            if (!activeDelivery.IsAllDeliveryItemsScanned)
            {
                throw new ArgumentException(
                          "All delivery items must be scanned to be able to move Active Delivery to Completed");
            }

            Name             = activeDelivery.Name;
            DeliveryStatus   = DeliveryStatus.Completed;
            ModificationDate = DateTime.UtcNow;
            CreationDate     = DateTime.UtcNow;

            ActiveDeliveryId = activeDelivery.Id;
            _items           = activeDelivery.Items
                               .Select(i => new CompletedDeliveryItem(i.BookId, i.BookEan,
                                                                      i.ItemsCount, GetStocksByEan(i.BookEan, stocks))).ToList();
        }