Example #1
0
        public void UpdateProduct(Product product)
        {
            if (product.Id == null)
            {
                throw new InvalidOperationException("cannot update a new product");
            }
            var productId = product.Id.GetValueOrDefault();

            product.CreateCheckPoint();
            var keyToRemove = product.CheckPointHistory.Last().Key;

            // cloning the object to separate it from the original - thereby simulating a real-life data insertion
            var clone = (Product)product.CurrentCheckPoint;

            if (!ProductData.ContainsKey(productId))
            {
                throw new InvalidOperationException("product not found");
            }
            ProductData[productId] = clone;

            //get rid of checkpoint
            product.CheckPointHistory.Remove(keyToRemove);
        }