Пример #1
0
        public bool TryToReserveProduct(Product product, string sessionId, out Reservation reservation)
        {
            if (_stocksProvider.TryDecreaseStock(product.Id, 1))
            {
                reservation = new Reservation(product, sessionId);
                if (!_reservationsProvider.TryAddReservation(reservation))
                {
                    // in case attempt to add reservation to the reservedInventory failed -> increase stock
                    _stocksProvider.TryIncreaseStock(product.Id, 1);
                    return(false);
                }

                return(true);
            }

            reservation = null;
            return(false);
        }
Пример #2
0
 /// <summary>
 /// Increase the stock for existing product
 /// </summary>
 public bool TryIncreaseStock(Guid productId, int count)
 {
     return(_stocksProvider.TryIncreaseStock(productId, count));
 }