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); }
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)); }
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)); }