public bool Equals(ShoppingBasket obj) { bool isMatch = false; foreach (Product product1 in obj.products) { foreach (Product product2 in products) { if (product1.Equals(product2)) { isMatch = true; } } if (!isMatch) { return(false); } } return(true); }
private Receipt validPurchase(ShoppingBasket basket) { // calc the price double priceBeforeDisc = calcPriceBeforeDiscount(basket.products); double price = priceBeforeDisc - calcTotalDiscount(basket, priceBeforeDisc); Receipt receipt = new Receipt(); //List<ProductData> products = new List<ProductData>(); // request for payment // the payment was successful foreach (Product product in basket.products) { foreach (Product localProduct in this.inventory) { if (localProduct.info.Equals(product.info)) { localProduct.amount -= product.amount; // update amount in DB localProduct.update(); // add the products to receipt // products.Add(product.toDataObject(this.name)); //receipt.products.Add(localProduct.info.id, product.amount); // //receipt.actualProducts.Add(new Product(localProduct)); // leave feedback //basket.owner.canLeaveFeedback = true; product.info.leaveFeedback(basket.owner.userName, ""); // update feedback in DB //new FeedbackData(localProduct.info.toDataObject(), localProduct.info.manufacturer, ((Member)basket.owner).toDataObject(), ""); } //StoresData.getStore(this.name).removeProducts(product.toDataObject()); product.info.roomForFeedback(basket.owner.userName); } } receipt.basket = basket; // fill receipt fields receipt = fillReceipt(receipt, price); return(receipt); }
public void margeBasket(ShoppingBasket basket) { bool isMatch = false; foreach (Product product1 in basket.products) { foreach (Product product2 in products) { if (!isMatch && product1.Equals(product2)) { isMatch = true; product2.addAmount(product1.amount); products.Remove(product1); products.Add(product2); } } if (!isMatch) { products.Add(product1); } isMatch = false; } }