Exemple #1
0
        public void ToGetInLineToCashbox(Guid cashboxId, Guid buyerId, IQueuedObjectSubscriber subscriber)
        {
            if (subscriber == null)
            {
                throw new ArgumentNullException(nameof(subscriber));
            }

            if (!_buyers.TryGetValue(buyerId, out var buyer))
            {
                throw new BuyerIsNotInSupermarketException();
            }

            var queuedCashbox = _queuedCashboxes.FirstOrDefault(s => s.Object.Id == cashboxId);

            if (queuedCashbox == null)
            {
                throw new WorkerObjectNotFoundException();
            }

            queuedCashbox.Availabled += subscriber.OnQueuedObjectAvailabled;
            queuedCashbox.ToGetInLine(buyer);
        }
Exemple #2
0
        public Receipt BuyProducts(Guid cashboxId, Guid buyerId, IQueuedObjectSubscriber subscriber)
        {
            if (subscriber == null)
            {
                throw new ArgumentNullException(nameof(subscriber));
            }

            if (!_buyers.TryGetValue(buyerId, out var buyer))
            {
                throw new BuyerIsNotInSupermarketException();
            }

            var queuedCashbox = _queuedCashboxes.FirstOrDefault(c => c.Object.Id == cashboxId);

            if (queuedCashbox == null)
            {
                throw new WorkerObjectNotFoundException();
            }

            queuedCashbox.Availabled -= subscriber.OnQueuedObjectAvailabled;

            return(queuedCashbox.MakePurchases(buyerId));
        }
Exemple #3
0
        public IReadOnlyCollection <Product> TakeProductsFromShelf(Guid shelfId, Guid buyerId, int count, IQueuedObjectSubscriber subscriber)
        {
            if (subscriber == null)
            {
                throw new ArgumentNullException(nameof(subscriber));
            }

            if (!_buyers.TryGetValue(buyerId, out _))
            {
                throw new BuyerIsNotInSupermarketException();
            }

            var queuedShelf = _queuedShelves.FirstOrDefault(s => s.Object.Id == shelfId);

            if (queuedShelf == null)
            {
                throw new WorkerObjectNotFoundException();
            }

            queuedShelf.Availabled -= subscriber.OnQueuedObjectAvailabled;

            return(queuedShelf.TakeAnyProducts(buyerId, count));
        }