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 string RemoveStore(MongoStore store)
        {
            var    mongoDbStoreRepository = new MongoDbStoreRepository();
            string Result = mongoDbStoreRepository.RemoveStore(store);

            Console.WriteLine(Result);
            Console.WriteLine();
            return(Result);
        }
        public string UpdateStore(MongoStore store)
        {
            var    mongoDbStoreRepository = new MongoDbStoreRepository();
            string result = mongoDbStoreRepository.UpdateStore(store);

            Console.WriteLine(result);
            Console.WriteLine();
            return(result);
        }
        public void MongodbStoreManagement()
        {
            try
            {
                Console.WriteLine("\n\t*****Store MongoDb Implementation*****\n");
                InsertStore();
                RemoveStore(new MongoStore()
                {
                    StoreName = "HemKop"
                });
                var productList = new List <MongoProduct>()
                {
                    new MongoProduct()
                    {
                        Name = "Salt", Price = 34.57m, ProductInStock = 8, ManufacturerDetails = new Manufacturer()
                        {
                            ManufacturerName = "SSS", PhoneNumber = 762892347, Place = "Chalmers"
                        }
                    },
                    new MongoProduct()
                    {
                        Name = "Muffins", Price = 50.37m, ProductInStock = 16, ManufacturerDetails = new Manufacturer()
                        {
                            ManufacturerName = "AWE", PhoneNumber = 762892856, Place = "Hjlmar"
                        }
                    }
                };
                UpdateStore(new MongoStore()
                {
                    Id = "5ef5c31458ed8642580d7cc3", StoreName = "Pressbyran", StoreAddress = "777 Chalmers", PinCode = 2222, ProductDetails = productList
                });

                GetAllStores();
                GetByStoreId("5ef5c31458ed8642580d7cbf");

                //StoreFilter
                IMongoDbProductRepository productRepository = new MongoDbProductRepository();
                IMongoStore   storeRepository = new MongoDbStoreRepository();
                ProductFilter storeFilter     = new ProductFilter(productRepository, storeRepository);

                //searchBy Store
                storeFilter.GetStoresBySearch("Lidl");
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public void GetAllStores()
        {
            var mongoDbStoreRepository         = new MongoDbStoreRepository();
            IEnumerable <MongoStore> StoreList = mongoDbStoreRepository.GetAllStores();

            Console.WriteLine("\n\t********Stores details************\n");
            foreach (var store in StoreList)
            {
                Console.WriteLine($"---Store : {store.StoreName} Details ---");
                foreach (var productDetails in store.ProductDetails)
                {
                    Console.WriteLine($"StoreId :{store.Id} StoreName: {store.StoreName} StoreAddress:{store.StoreAddress} ProductName: {productDetails.Name} Price:{productDetails.Price} ProductInStock:{productDetails.ProductInStock} ManufacturerName:{productDetails.ManufacturerDetails.ManufacturerName} PhoneNumber:{productDetails.ManufacturerDetails.PhoneNumber} Place:{productDetails.ManufacturerDetails.Place}");
                }
            }
        }
Exemplo n.º 6
0
 public void MongoDbProdManagment()
 {
     try
     {
         InsertProduct();
         Console.WriteLine("********Product MongoDB implementation********");
         RemoveProduct(new MongoProduct {
             Name = "Pepsodent Tootpaste", Price = 50.37m, ProductInStock = 10, ManufacturerDetails = new Manufacturer()
             {
                 ManufacturerName = "ERE", PhoneNumber = 762892333, Place = "Redbergplasten"
             }
         });
         UpdateProduct(new MongoProduct {
             Name = "Toothbrush", Price = 50.78m, Id = "5ef5c2a3ac609330f4f799bf", ProductInStock = 10, ManufacturerDetails = new Manufacturer()
             {
                 ManufacturerName = "TTT", PhoneNumber = 762892530, Place = "Hjalmar"
             }
         });
         GetAllProducts();
         GetByProductId("5ef5c2a2ac609330f4f799b1");
         //ProductFilter-Search by ProductName
         IMongoDbProductRepository productRep = new MongoDbProductRepository();
         IMongoStore   storeRep      = new MongoDbStoreRepository();
         ProductFilter productFilter = new ProductFilter(productRep, storeRep);
         var           searchProduct = productFilter.SearchProductByName("Vaseline").FirstOrDefault();
         Console.WriteLine();
         Console.WriteLine("********Matched record by ProductName************");
         Console.WriteLine($"Name : {searchProduct.Name} , ProductId:{searchProduct.Id} ,Price: {searchProduct.Price},ProductInStock:{searchProduct.ProductInStock}, ManufacturerDetails : {searchProduct.ManufacturerDetails.ManufacturerName} ,ManufacturerDetails : {searchProduct.ManufacturerDetails.Place}, ManufacturerDetails : {searchProduct.ManufacturerDetails.PhoneNumber}");
         //ProductFilter-ProductsCostingLessThan
         Console.WriteLine("********Matched 10 records by ProductPrice ************");
         var matchedProduct = productFilter.ProductsCostingLessThan(130.12m);
         foreach (var records in matchedProduct)
         {
             Console.WriteLine($"Name : {records.Name} , ProductId:{records.Id} ,Price: {records.Price},ProductInStock:{records.ProductInStock}, ManufacturerDetails : {records.ManufacturerDetails.ManufacturerName} ,ManufacturerDetails : {records.ManufacturerDetails.Place}, ManufacturerDetails : {records.ManufacturerDetails.PhoneNumber}");
         }
         //ProductFilter-Manufacturerdetails
         productFilter.ListOfManufacturersWithProductCount();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
        public void GetByStoreId(string storeId)
        {
            var        mongoDbStoreRepository = new MongoDbStoreRepository();
            MongoStore store = mongoDbStoreRepository.GetByStoreId(storeId);

            if (store != null)
            {
                Console.WriteLine();
                Console.WriteLine("******Matched record by StoreId*****");

                foreach (var productDetails in store.ProductDetails)
                {
                    Console.WriteLine($"StoreId :{store.Id} StoreName: {store.StoreName} ProductName: {productDetails.Name} Price:{productDetails.Price} ProductInStock:{productDetails.ProductInStock} ManufacturerName:{productDetails.ManufacturerDetails.ManufacturerName} PhoneNumber:{productDetails.ManufacturerDetails.PhoneNumber} Place:{productDetails.ManufacturerDetails.Place}");
                }
            }
            else
            {
                Console.WriteLine("No matched records found for the productID:{0}:" + storeId);
            }
        }
        public void GetStoresBySearch(string searchString)
        {
            IMongoStore storeRepository           = new MongoDbStoreRepository();
            IEnumerable <MongoStore> storeList    = storeRepository.GetAllStores();
            IEnumerable <MongoStore> storeDetails = from rec in storeList
                                                    where rec.StoreName.Contains(searchString)
                                                    select rec;

            Console.WriteLine();
            Console.WriteLine("********Matched record by Store Name************");
            foreach (var storeData in storeDetails)
            {
                Console.WriteLine($"---Store : {storeData.StoreName} Details ---");
                foreach (var storeProduct in storeData.ProductDetails)
                {
                    Console.WriteLine($"StoreId : {storeData.Id} StoreName: {storeData.StoreName} ProductName:{storeProduct.Name} Price:{storeProduct.Price}  ProductInStock:{storeProduct.ProductInStock} ManufacturerName:{storeProduct.ManufacturerDetails.ManufacturerName} PhoneNumber:{storeProduct.ManufacturerDetails.PhoneNumber} Place:{storeProduct.ManufacturerDetails.Place}");
                }
            }
            Console.WriteLine();
        }