//Does the same but for the items in the purchase history public static List <CHProduct> GetHistoryItems(string username) { List <CHProduct> products = new List <CHProduct>(); if (dbConnection != null && dbConnection.State == ConnectionState.Closed) { dbConnection.Open(); } UserAccount user = GetUser(username); PurchaseHistory history = GetPurchaseHistory(user.userID); List <HistoryItems> items = GetUserHistory(history.purchaseHistoryID); foreach (HistoryItems item in items) { CHProduct chProduct = new CHProduct(); chProduct.quantity = item.quantity; Product product = GetProduct(item.productID); chProduct.productID = product.productID; chProduct.productName = product.productName; chProduct.productManufacturer = product.productManufacturer; chProduct.productPrice = product.productPrice; chProduct.productImage = product.productImage; products.Add(chProduct); } dbConnection.Close(); return(products); }
//Returns a composite object of product and cart item, so all the details of the product and the quantity in cart //Needed to populate the shopping cart properly public static List <CHProduct> GetCartItems(string username) { List <CHProduct> products = new List <CHProduct>(); if (dbConnection != null && dbConnection.State == ConnectionState.Closed) { dbConnection.Open(); } UserAccount user = GetUser(username); ShoppingCart cart = GetCart(user.userID); List <CartItems> items = GetUserCart(cart.cartID); foreach (CartItems item in items) { CHProduct chProduct = new CHProduct(); chProduct.quantity = item.quantity; Product product = GetProduct(item.productID); chProduct.productID = product.productID; chProduct.productName = product.productName; chProduct.productManufacturer = product.productManufacturer; chProduct.productPrice = product.productPrice; chProduct.productImage = product.productImage; products.Add(chProduct); } dbConnection.Close(); return(products); }