Exemple #1
0
        public void GetAllProducts()
        {
            MongoProduct product = new MongoProduct();
            //productRepository = new ProductRepository();
            IMongoDbProductRepository  mongoRep    = new MongoDbProductRepository();
            IEnumerable <MongoProduct> productList = mongoRep.GetAllProducts();

            Console.WriteLine("********Products details************");
            foreach (var products in productList)
            {
                Console.WriteLine($"Name : {products.Name} , ProductId:{products.Id} ,Price: {products.Price}, ManufacturerDetails : {products.ManufacturerDetails.ManufacturerName} ,ManufacturerDetails : {products.ManufacturerDetails.Place}, ManufacturerDetails : {products.ManufacturerDetails.PhoneNumber}");
            }
        }
        public void ListOfManufacturersWithProductCount()
        {
            var manufacturerList           = MongoDbProductRepository.GetAllProducts();
            var groupedManufacturerRecords =
                manufacturerList.GroupBy(c => c.ManufacturerDetails.ManufacturerName);

            Console.WriteLine("****List of Manufacturer details*****");

            foreach (var groups in groupedManufacturerRecords)
            {
                Console.WriteLine("ManufacturerName:" + groups.Key + "\n" + "Total no of products:" + groups.Count());
                foreach (var c in groups)
                {
                    Console.WriteLine("\t" + "ProductName:" + c.Name + "," + "Price:" + c.Price);
                }
                Console.WriteLine();
            }
        }
        public void InsertStore()
        {
            IMongoStore mongoStore = new MongoDbStoreRepository();
            IMongoDbProductRepository mongoProduct = new MongoDbProductRepository();

            //mongoStore.DropCollection();
            mongoStore.InsertStore(new MongoStore()
            {
                StoreName = "Lidl", StoreAddress = "111 Backebol Norra", PinCode = 1234, ProductDetails = mongoProduct.GetAllProducts().Take(5).ToList <MongoProduct>()
            });
            mongoStore.InsertStore(new MongoStore()
            {
                StoreName = "COOP", StoreAddress = "223 Elisedal", PinCode = 4567, ProductDetails = mongoProduct.GetAllProducts().TakeLast(8).ToList <MongoProduct>()
            });
            mongoStore.InsertStore(new MongoStore()
            {
                StoreName = "ICA", StoreAddress = "345 Korsvagen", PinCode = 8907, ProductDetails = mongoProduct.GetAllProducts().Take(10).ToList <MongoProduct>()
            });
            mongoStore.InsertStore(new MongoStore()
            {
                StoreName = "Willys", StoreAddress = "234 Wavrinskyplats", PinCode = 9356, ProductDetails = mongoProduct.GetAllProducts().Take(13).ToList <MongoProduct>()
            });
            mongoStore.InsertStore(new MongoStore()
            {
                StoreName = "HemKop", StoreAddress = "435 Kapelplatsen", PinCode = 8976, ProductDetails = mongoProduct.GetAllProducts().Take(8).ToList <MongoProduct>()
            });
            mongoStore.InsertStore(new MongoStore()
            {
                StoreName = "Pressbyran", StoreAddress = "444 Hjalmar ", PinCode = 2345, ProductDetails = mongoProduct.GetAllProducts().TakeLast(2).ToList <MongoProduct>()
            });
        }
 public IEnumerable <MongoProduct> ProductsCostingLessThan(decimal price)
 {
     return(MongoDbProductRepository.GetAllProducts().Where(p => p.Price < price).Take(10));
 }
 public IEnumerable <MongoProduct> SearchProductByName(string name)
 {
     return(MongoDbProductRepository.GetAllProducts().Where(p => p.Name.Contains(name)));
 }