public void AddToCart() { CartItemDisplayModel existingItem = Cart.FirstOrDefault(x => x.Product == SelectedProduct); if (existingItem != null) { existingItem.QuantityInCart += ItemQuantity; } else { CartItemDisplayModel item = new CartItemDisplayModel { Product = SelectedProduct, QuantityInCart = ItemQuantity }; Cart.Add(item); } SelectedProduct.QuantityInStock -= ItemQuantity; ItemQuantity = 1; NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); NotifyOfPropertyChange(() => CanCheckOut); NotifyOfPropertyChange(() => CanAddToCart); }
public void AddToCart() { CartItemDisplayModel existingItem = Cart.FirstOrDefault(x => x.Product == SelectedProduct); if (existingItem != null) { existingItem.QuantityInCart += ItemQuantity; // Hack - there should be a better way of refreshing the cart display Cart.Remove(existingItem); Cart.Add(existingItem); } else { CartItemDisplayModel item = new CartItemDisplayModel { Product = SelectedProduct, QuantityInCart = ItemQuantity }; Cart.Add(item); } SelectedProduct.QuantityInStock -= ItemQuantity; ItemQuantity = 1; NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); NotifyOfPropertyChange(() => CanCheckout); }
public void AddToCart() { // If the same item already exists in the cart update qty CartItemDisplayModel existingItem = Cart.FirstOrDefault(i => i.Product.Id == SelectedProduct.Id); if (existingItem != null) { existingItem.Quantity += ItemQuantity; } else { // Add selection to cart Cart.Add(new CartItemDisplayModel { Product = SelectedProduct, Quantity = ItemQuantity }); } // Prep in-stock qty SelectedProduct.InStock -= ItemQuantity; // Reset ItemQuantity back to 1 ItemQuantity = 1; NotifyOfPropertyChange(() => Cart); NotifyOfPropertyChange(() => CanCheckout); NotifyOfPropertyChange(() => Subtotal); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); }
public void AddToCart() { // Compares the two objects (not the values). CartItemDisplayModel existingItem = Cart.FirstOrDefault(x => x.Product == SelectedProduct); // We already have this utem in the cart if (existingItem != null) { // This is executed on the Cart. (existingItem points to an address of an item on the cart) existingItem.QuantityInCart += ItemQuantity; } // New item to the cart else { CartItemDisplayModel item = new CartItemDisplayModel { Product = SelectedProduct, QuantityInCart = ItemQuantity }; Cart.Add(item); } SelectedProduct.QuantityInStock -= ItemQuantity; ItemQuantity = 1; NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); NotifyOfPropertyChange(() => CanCheckout); }
public void AddToCart() { CartItemDisplayModel existingItem = Cart.FirstOrDefault(x => x.Product == SelectedProduct); if (existingItem != null) { // Update an existing item quantity so we dont have duplicate products in cart existingItem.QuantityInCart += ItemQuantity; //// Triggers quantity refresh - could be done better //Cart.Remove(existingItem); //Cart.Add(existingItem); } else { CartItemDisplayModel item = new CartItemDisplayModel { Product = SelectedProduct, QuantityInCart = ItemQuantity }; Cart.Add(item); } SelectedProduct.QuantityInStock -= ItemQuantity; // Subtrack from item quantity ItemQuantity = 1; // Reset item quantity back to 1 NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); NotifyOfPropertyChange(() => CanCheckOut); }
public void AddToCart() { CartItemDisplayModel existingItems = Cart.FirstOrDefault(x => x.Product == SelectedProduct); //If there's an existing item in the cart, add to the quantity if (existingItems != null) { existingItems.QuantityInCart += ItemQuantity; ////Cheaty hack to refresh the Cart //Cart.Remove(existingItems); //Cart.Add(existingItems); } //If there's not an existing item, add new item into cart else { CartItemDisplayModel item = new CartItemDisplayModel { Product = SelectedProduct, QuantityInCart = ItemQuantity }; Cart.Add(item); } SelectedProduct.QuantityInStock -= ItemQuantity; ItemQuantity = 1; NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); NotifyOfPropertyChange(() => CanCheckOut); //Cart.ResetBindings(); }
public void AddToCart() { CartItemDisplayModel existingItem = Cart.FirstOrDefault(x => x.Product == SelectedProduct); // comparing same type of object having different value. if (existingItem != null) { existingItem.QuantityInCart += ItemQuantity; //SOLVED: Its a Hack . should be replaced in a better way. //Cart.Remove(existingItem); //Cart.Add(existingItem); } else { CartItemDisplayModel item = new CartItemDisplayModel { Product = SelectedProduct, QuantityInCart = ItemQuantity }; Cart.Add(item); } SelectedProduct.QuantityinStock -= ItemQuantity; ItemQuantity = 1; NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Cart); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); NotifyOfPropertyChange(() => CanCheckOut); }
public void AddToCart() { var existingItem = Cart.SingleOrDefault(x => x.Product == SelectedProduct); if (existingItem != null) { existingItem.QuantityInCart += ProductQuantity; } else { var cartItem = new CartItemDisplayModel { Product = SelectedProduct, QuantityInCart = ProductQuantity }; Cart.Add(cartItem); } SelectedProduct.QuantityInStock -= ProductQuantity; ProductQuantity = 1; NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Total); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => CanCheckout); }
public void AddToCart() { CartItemDisplayModel existingItem = Cart.FirstOrDefault(x => x.Product == SelectedProduct); if (existingItem != null) { // Modify the quantity, since we have the same memory address existingItem.QuantityInCart += ItemQuantity; // HACK - There should e a better way of refreshing the cart display //Cart.Remove(existingItem); //Cart.Add(existingItem); } else { CartItemDisplayModel item = new CartItemDisplayModel { Product = SelectedProduct, QuantityInCart = ItemQuantity }; Cart.Add(item); } SelectedProduct.QuantityInStock -= ItemQuantity; ItemQuantity = 1; NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); NotifyOfPropertyChange(() => CanCheckOut); }
public void AddToCart() { // Si el producto existe en el carrito, actualizar cantidad, si no, crear uno nuevo. CartItemDisplayModel existingItem = Cart.FirstOrDefault(i => i.Product == SelectedProduct); if (existingItem != null) { existingItem.QuantityInCart += ItemQuantity; } else { CartItemDisplayModel item = new CartItemDisplayModel { Product = SelectedProduct, QuantityInCart = ItemQuantity }; Cart.Add(item); } SelectedProduct.QuantityInStock -= ItemQuantity; ItemQuantity = 1; NotifyChangesInCart(); }
public void RemoveFromCart() { CartItemDisplayModel existingItem = Cart.FirstOrDefault(x => x.Product == SelectedProductToRemove.Product); existingItem.QuantityInCart -= ItemQuantity; //HACK - There should be a better way of refreshing the cart display Cart.Remove(existingItem); if (existingItem.QuantityInCart > 0) { Cart.Add(existingItem); } ProductDisplayModel ProductInStock = Products.FirstOrDefault(x => x.Id == existingItem.Product.Id); ProductInStock.QuantityInStock += ItemQuantity; ItemQuantity = 1; NotifyOfPropertyChange(() => SubTotal); NotifyOfPropertyChange(() => Tax); NotifyOfPropertyChange(() => Total); NotifyOfPropertyChange(() => CanCheckOut); }