public IEnumerable <CartLine> GetProductsInAllChains() { StoreProductMapper storeProductsMapper = new StoreProductMapper(); storeProductsMapper.FillStoreProductList(); StoreMapper storeMapper = new StoreMapper(); storeMapper.FillStoreList(); ChainMapper chainMapper = new ChainMapper(); chainMapper.FillChainList(); List <CartLine> productsFromCart = SessionManager.GetCart(Session).Lines.ToList(); foreach (var product in productsFromCart) { var list = storeProductsMapper.StoreProductList .Where(p => p.ProductId == product.Product.ProductId); var list2 = storeMapper.StoreList .Where(p => list.Any(a => a.StoreId == p.StoreId.ToString().PadLeft(3, '0'))); var list3 = chainMapper.ChainList .Where(p => list2.Any(a => a.ChainId == p.ChainId)); if (list3.Count() != chainMapper.ChainList.Count) { productsFromCart = productsFromCart .Where(x => x.Product.ProductId != product.Product.ProductId).ToList(); } } return(productsFromCart); }
public XMLParser() { productMapper = new ProductMapper(); chainMapper = new ChainMapper(); storeMapper = new StoreMapper(); storeProductMapper = new StoreProductMapper(); storeMapper.FillStoreList(); productMapper.FillProductList(); chainMapper.FillChainList(); storeProductMapper.FillStoreProductList(); }
public IEnumerable <CalculateResultBuilder> BuildResult(List <CartLine> listOfCartItems) { StoreProductMapper storeProductsMapper = new StoreProductMapper(); StoreMapper storeMapper = new StoreMapper(); ChainMapper chainMapper = new ChainMapper(); storeProductsMapper.FillStoreProductList(); storeMapper.FillStoreList(); chainMapper.FillChainList(); List <CalculateResultBuilder> CalculatedList = new List <CalculateResultBuilder>(); List <Product> products = new List <Product>(); List <Chain> chains = new List <Chain>(); List <Store> stores = new List <Store>(); List <StoreProduct> storeProducts = new List <StoreProduct>(); foreach (var item in listOfCartItems) { //TODO: fix if needed Product p = item.Product; p.Quantity = item.Quantity; products.Add(p); } foreach (var product in products) { storeProducts.AddRange(storeProductsMapper.StoreProductList .Where(p => p.ProductId == product.ProductId).ToList()); stores.AddRange(storeMapper.StoreList .Where(p => storeProducts.Any(a => a.StoreId == p.StoreId.ToString().PadLeft(3, '0'))).ToList()); chains.AddRange(chainMapper.ChainList .Where(p => stores.Any(a => a.ChainId == p.ChainId)).ToList()); } chains = chains.GroupBy(x => x.ChainId) .Select(g => g.First()).ToList(); stores = stores.GroupBy(x => x.StoreId) .Select(g => g.First()).ToList(); foreach (var chain in chains) { foreach (var store in stores) { List <Product> newProductList = new List <Product>(); if (chain.ChainId == store.ChainId) { foreach (var storeProduct in storeProducts) { foreach (var item in products) { if (storeProduct.StoreId == store.StoreId.ToString().PadLeft(3, '0')) { if (item.ProductId == storeProduct.ProductId) { Product product = item; product.ProductPrice = storeProduct.ProductPrice * product.Quantity; newProductList.Add(product); } } } } CalculatedList.Add(new CalculateResultBuilder( chain.ChainName, store.StoreName, newProductList .OrderBy(x => x.ProductPrice).ToList(), newProductList .Sum(x => x.ProductPrice))); } } } return(CalculatedList); }