Esempio n. 1
0
        //When user wants to remove product from the cart:
        // - calling reservationmanager to remove product from the reservationDb and update inventory
        // - removing product from the cartDB;
        public void RemoveProduct(Product product, string sessionId)
        {
            var listOdReservations = _reservationsProvider.GetReservations().Where(sId => sId.SessionId == sessionId).ToList();

            foreach (var reservation in listOdReservations)
            {
                if (reservation.ProductId == product.Id)
                {
                    _reservationsManager.CancelReservation(reservation.Id);
                    break;
                }
            }

            var cart = _cartsProvider.GetCartForSession(sessionId);

            cart.Products.RemoveAll(item => item == product.Id);
            _cartsProvider.SaveCart(cart);
        }
Esempio n. 2
0
        public void CancelReservation(Guid reservationId)
        {
            // - remove reservation from the reservedInventory
            // - update inventory
            var reservation = _reservationsProvider.GetReservations().FirstOrDefault(r => r.Id == reservationId);

            if (reservation != null)
            {
                _reservationsProvider.TryRemoveReservation(reservationId); // get the product id in order to update inventory.
                _stocksProvider.TryIncreaseStock(reservation.ProductId, 1);
            }
        }
        private void GetExpiredReservations(object sender, ElapsedEventArgs e)
        {
            var listOfReservations = _reservationsProvider.GetReservations().Where(ext => ext.ExpirationTime <= DateTime.Now).ToList();

            _expirationReservationsHandler(listOfReservations);
        }