public void UpdateCustomer(Customer customer) { if (customer.Id == null) { throw new InvalidOperationException("cannot update a new customer"); } var customerId = customer.Id.GetValueOrDefault(); customer.CreateCheckPoint(); var keyToRemove = customer.CheckPointHistory.Last().Key; // cloning the object to separate it from the original - thereby simulating a real-life data insertion var clone = (Customer)customer.CurrentCheckPoint; if (!CustomerData.ContainsKey(customerId)) { throw new InvalidOperationException("customer not found"); } CustomerData[customerId] = clone; //get rid of checkpoint customer.CheckPointHistory.Remove(keyToRemove); }