private void ProductRemovedFromCartHandler(InBookBlockPvmByTransaction bookBlock) { // -- Remove the from-cart-removed book from the correspondent Cart UserOrderPlvmWp cartRemovedFrom = null; var wasAroundEnd = false; foreach (var userOrderPlvmWp in Carts) { var indexOfRemoved = userOrderPlvmWp.Products.IndexOf(bookBlock); if (indexOfRemoved >= 0) { cartRemovedFrom = userOrderPlvmWp; wasAroundEnd = (userOrderPlvmWp.Products.Count - indexOfRemoved) <= 3; // index is zero based userOrderPlvmWp.Products.RemoveAt(indexOfRemoved); break; } } // If we could not remove the item, something went wrong if (cartRemovedFrom == null) { throw new Exception(); } // If the removed item was one of the last 2 books in the last cart, because of a Framework bug, // the screen will be empty. The reason is only, we got out from the visible area, // so we have to scroll up a bit var isBigEnough = cartRemovedFrom.Products.Count >= 3; // the item is already removed var isLastCart = Carts[Carts.Count - 1] == cartRemovedFrom; if (wasAroundEnd && isLastCart && isBigEnough) { LongListSelectorCarts.ScrollTo(cartRemovedFrom); } // If the cart became empty if (cartRemovedFrom.Products.Count == 0) { Carts.Remove(cartRemovedFrom); } }
private void ExchangeProductRemovedHandler(InBookBlockPvmByTransaction bookBlock) { InProgressSells.First(userOrderPlvmWp => userOrderPlvmWp.ExchangeProducts.Remove(bookBlock)); }