public bool setProductAmount(Product product, int amount) { ProductAmount wannaBeCart; if (amount == 0 && containProduct(product)) { wannaBeCart = getCartValue(product.id); products.Remove(wannaBeCart); return(true); } else if (amount > 0) { if (containProduct(product)) { ProductAmount p = getCartValue(product.id); p.amount = amount; } else { wannaBeCart = new ProductAmount(product, amount); products.Add(wannaBeCart); } return(true); } return(false); }
public override void Copy(IEntity other) { base.Copy(other); if (other is ProductAmount) { ProductAmount _other = ((ProductAmount)other); product = _other.product; } }
public int getProductAmount(Product product) { Predicate <ProductAmount> productPredicat = s => ((ProductAmount)s).product.Equals(product); ProductAmount cartValue = products.Find(productPredicat); if (cartValue == null) { return(0); } return(cartValue.amount); }