static void Main(string[] args) { var ctx = new ProductContext(); var repository = new ProductsRepository(ctx); repository.AddShops(InitialData.Shops); var shops = repository.GetShops(); var victoryInfo = shops.First(s => s.Brand == ShopBrand.Victory); var ybitanInfo = shops.First(s => s.Brand == ShopBrand.YBitan); var coobInfo = shops.First(s => s.Brand == ShopBrand.Coob); var parser = new XmlParser(); var victoryProducts = parser.ParseFile("../../../ShoppingCart.Server.XMLEngine/Xml/VictorySample.Xml", new VictoryUnitsParser(), "/Prices/Products/Product", victoryInfo); var ybitanProducts = parser.ParseFile("../../../ShoppingCart.Server.XMLEngine/Xml/YbitanSample.Xml", new YbUnitsParser(), "/Root/Items/Item", ybitanInfo); var coobProducts = parser.ParseFile("../../../ShoppingCart.Server.XMLEngine/Xml/CoobSample.Xml", new CoobUnitsParser(), "/root/Items/item", coobInfo); victoryProducts = victoryProducts.ToList(); ybitanProducts = ybitanProducts.ToList(); coobProducts = coobProducts.ToList(); repository.AddCategoies(Categorizer.Categories); repository.AddProducts(victoryProducts); repository.AddProducts(ybitanProducts); repository.AddProducts(coobProducts); repository.FindAndAddSimilarProducts(victoryInfo); repository.FindAndAddSimilarProducts(ybitanInfo); repository.FindAndAddSimilarProducts(coobInfo); }
public void Post([FromBody] Products dataProduct) { string result = string.Empty; ProductsRepository repository = new ProductsRepository(); result = repository.AddProducts(dataProduct); }
public static async Task <bool> WriteToMongo(Product[] products) { if (!products.Any()) { return(false); } // Hard-coded Connection String & Database name, as they are not the point of focus for this exercise var connectionString = "mongodb+srv://murugabms:[email protected]/AzureTest?retryWrites=true&w=majority"; var databaseName = "IOUCommrate"; var repository = new ProductsRepository( connectionString, databaseName); await repository.AddProducts(products); return(true); }
public static async Task <ActionResult <string> > Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest request) { var requestBody = await new StreamReader(request.Body).ReadToEndAsync(); var products = JsonConvert.DeserializeObject <Product[]>(requestBody).ToArray(); if (!products.Any()) { return(new OkObjectResult("No products were added")); } // Hard-coded Connection String & Database name, as they are not the point of focus for this exercise var connectionString = "mongodb+srv://muruga:[email protected]/test?retryWrites=true&w=majority"; var databaseName = "IOUCommrate"; var repository = new ProductsRepository( connectionString, databaseName); await repository.AddProducts(products); return(new OkObjectResult("Products added successfully")); }