Example #1
0
 public List<Tuple<string, List<Product>>> GetMostExpensivetProductsPerProvider(ShoppingCart shoppingCart, List<Provider> providers, int numOfItemsToTake)
 {
     return (from provider in providers
             let mostExpensieveProducts = provider.Products.Intersect(shoppingCart.Products)
                                                           .OrderByDescending(p => p.Price)
                                                           .Take(3).ToList()
             select new Tuple<string, List<Product>>(provider.Name, mostExpensieveProducts)).ToList();
 }
Example #2
0
 public List<Tuple<string, List<Product>>> GetCheapestProductsPerProvider(ShoppingCart shoppingCart, List<Provider> providers, int numOfItemsToTake)
 {
     return (from provider in providers
             let cheapestProducts = provider.Products.Intersect(shoppingCart.Products)
                                                     .OrderBy(p => p.Price)
                                                     .Take(numOfItemsToTake).ToList()
             select new Tuple<string, List<Product>>(provider.Name, cheapestProducts)).ToList();
 }
Example #3
0
        public List<Tuple<string, double>> GetCartsTotalPrices(ShoppingCart shoppingCart, List<Provider> providers)
        {
            return (from provider in providers 
                    let sum = (from product in shoppingCart.Products 
                                let productPrice = provider.Products.Find(p => p.ItemCode == product.ItemCode).Price 
                                select productPrice*product.Amount).Sum()

                    select new Tuple<string, double>(provider.Name, sum)).ToList();
        }
Example #4
0
        public WiseCartManager()
        {
            ShoppingCart = new ShoppingCart();
            Providers = new List<Provider>();
            AllProvidersIntersected = new Provider("Intersected");
            ProvidersXDocuments = new Dictionary<string, XDocument>();

            XmlFilesPath = @"..\..\..\Resources\ProvidersXml";
            XmlFilesPaths = Directory.GetFiles(XmlFilesPath).ToList();
        }
Example #5
0
        public void LoadCart()
        {
            XmlSerializer deserializer = new XmlSerializer(typeof(ShoppingCart));

            if (File.Exists(CartXmlPath))
            {
                using (TextReader reader = new StreamReader(CartXmlPath))
                {
                    ShoppingCart = (ShoppingCart)deserializer.Deserialize(reader);
                }
            }
            else
            {
                Debug.WriteLine("File missing");
            }
        }
Example #6
0
 public CartSerializer(ShoppingCart shoppingCart)
 {
     CartXmlPath = Environment.CurrentDirectory + @"\..\..\..\Resources\UserCart.xml";
     ShoppingCart = shoppingCart;
 }