public void ImportClients(ICollection<MongoDb.Data.Models.Client> mongoClients) { var clients = mongoClients.Select(c => new Model.Client() { Address = c.Address, Contact = c.Contact, Email = c.Email, Mobile = c.Mobile, Name = c.Name }); var counter = 0; foreach (var client in clients) { this.dbContext.Clients.Add(client); counter++; if (counter % 50 == 0) { this.dbContext.SaveChanges(); this.dbContext.Dispose(); this.dbContext = new FurnitureFactoryDbContext(); } } this.dbContext.SaveChanges(); }
public static void Main() { var db = new FurnitureFactoryDbContext(); ConsoleUserInterfaceIO io = new ConsoleUserInterfaceIO(); //db.Database.Delete(); //db.Database.Create(); //var mongodata = new MongoDbData(DatabaseName, io); //mongodata.Import(db); //PdfExporter pdfExporter = new PdfExporter(db); //pdfExporter.GeneratePdf(); var furnituresForBedroom = db.Products .Where(x => x.RoomId == 1) .Select(x => x.Series.Name) .ToList(); // Output must be: ALVIS \n 396 Tests, huh? :D io.SetOutput(furnituresForBedroom.FirstOrDefault()); io.SetOutput(db.Products.Count()); // task 4.1 //var jsonReporter = new JsonProductsReporter(db); //jsonReporter.GetJsonReport().Load(); // task 4.2 //var mySqlImporter = new SalesReportsMySqlImporter(io); //mySqlImporter.Save(); //// Generate Xml Report in Xml-Exports folder var productXmlReport = new ProductsXmlFileExporter(db); productXmlReport.GetXmlReport(); var ordersXmlReport = new OrdersXmlFileExporter(db); ordersXmlReport.GetXmlReport(); //// import XML file //var importProducts = new ProductsXmlFileImporter(); //importProducts.ImportXmlData("../../../Xml-Data.xml"); // Load excel from zip - Task1 LoadSalesReports(SourceSalesReportsArchiveFilePath); }
public static void Main() { var db = new FurnitureFactoryDbContext(); Utils.IUserInterfaceHandlerIO io = new ConsoleUserInterfaceIO(); var mongodata = new MongoDbData(DatabaseName, io); mongodata.Import(db); // Task 1. Load excel from zip LoadSalesReports(SourceSalesReportsArchiveFilePath); new MaterialsXmlImporter().Import(); new ProductionDetailsXmlImporter().Import(); new RoomsXmlMongoImporter().Import(io); PdfExporter pdfExporter = new PdfExporter(db); pdfExporter.GeneratePdf(); // Task 4.1 var jsonReporter = new JsonProductsReporter(db); jsonReporter.GetJsonReport().Load(); // Task 4.2 //var mySqlImporter = new SalesReportsMySqlImporter(io); //mySqlImporter.Save(); //// Task 3. Generate Xml Report in Xml-Exports folder var productXmlReport = new ProductsXmlFileExporter(db); productXmlReport.GetXmlReport(); var ordersXmlReport = new OrdersXmlFileExporter(db); ordersXmlReport.GetXmlReport(); }
public void ImportMaterials(ICollection<MongoDb.Data.Models.Material> mongoMaterials) { var materials = mongoMaterials.Select(c => new Model.Material() { Name = c.Name, Unit = (Units)c.Unit }); var counter = 0; foreach (var material in materials) { this.dbContext.Materials.Add(material); counter++; if (counter % 50 == 0) { this.dbContext.SaveChanges(); this.dbContext.Dispose(); this.dbContext = new FurnitureFactoryDbContext(); } } this.dbContext.SaveChanges(); }
/// <summary> /// The method imports data to the sql server database. It checks whether such customer exists /// and adds it to customers DbSet if necessary and gets its id to use for orders. /// So you can`t add the same customer twice to Customers DbSet, say if you load two different xls reports from the same customer. /// But it does not check for duplication of orders. /// So the same orders can be added to Orders DbSet twice if we load the same xls report file twice from a particular Customer. /// </summary> /// <param name="data"></param> public void ImportData(IList<object> data) { if (data.Count == 0) { throw new ArgumentOutOfRangeException(); } // means we start a new file (assuming first row is always empty if (data[0] == null) { // we reset the products client for the new file this.clientId = -1; return; } if (this.clientId == -1) { var client = new Client() { Name = data[0].ToString(), }; if (!this.db.Clients.Any(x => x.Name == client.Name)) { this.db.Clients.Add(client); this.db.SaveChanges(); } // we set the current client Id for the current sales reports file`s products this.clientId = this.db.Clients.First(x => x.Name == client.Name).Id; return; } if (data.Count < 4) { throw new ArgumentOutOfRangeException("Data record should have at least 4 fields"); } if (data[0].ToString().Contains("ProductID")) { return; } var order = new Order() { ProductId = int.Parse(data[0].ToString()), ClientId = this.clientId, Quantity = int.Parse(data[1].ToString()), Price = decimal.Parse(data[3].ToString()), DeliveryDate = (DateTime)data[data.Count-1] }; this.db.Orders.Add(order); this.databaseMonitoredOrders++; // optimize dbContext for large data import if (this.databaseMonitoredOrders >= 10) { this.db.SaveChanges(); this.db = new FurnitureFactoryDbContext(); this.databaseMonitoredOrders = 0; } }
public FurnitureFactoryMsSqlImporter() { this.dbContext = new FurnitureFactoryDbContext(); }
public ClientsExporter(FurnitureFactoryDbContext db) { this.db = db; }
public OrdersXmlFileExporter(FurnitureFactoryDbContext db) : base(db) { }
public void ImportProducts(ICollection<MongoDb.Data.Models.Product> mongoProducts) { var products = mongoProducts.Select(c => new Model.Product() { Name = c.Name, Price = Convert.ToDecimal(c.Price) }); var counter = 0; foreach (var product in products) { this.dbContext.Products.Add(product); counter++; if (counter % 50 == 0) { this.dbContext.SaveChanges(); this.dbContext.Dispose(); this.dbContext = new FurnitureFactoryDbContext(); } } this.dbContext.SaveChanges(); }
public XmlFileExporter(FurnitureFactoryDbContext db) { this.db = db; }
public SQLCustomerRepository(FurnitureFactoryDbContext context) { this._context = context; }
public OrdersController(FurnitureFactoryDbContext context) { _context = context; }
public ArticlesController(FurnitureFactoryDbContext context, IArticleRepository articleRepository) { _context = context; this._articleRepository = articleRepository; }
public void FinalizeImporting() { this.db.SaveChanges(); this.db = new FurnitureFactoryDbContext(); }
public JsonProductsReporter(FurnitureFactoryDbContext db) { this.db = db; }
/// <summary> /// The method imports data to the sql server database. It checks whether such customer exists /// and adds it to customers DbSet if necessary and gets its id to use for orders. /// So you can`t add the same customer twice to Customers DbSet, say if you load two different xls reports from the same customer. /// But it does not check for duplication of orders. /// So the same orders can be added to Orders DbSet twice if we load the same xls report file twice from a particular Customer. /// </summary> /// <param name="data"></param> public void ImportData(IList <object> data) { if (data.Count == 0) { throw new ArgumentOutOfRangeException(); } // means we start a new file (assuming first row is always empty if (data[0] == null) { // we reset the products client for the new file this.clientId = -1; return; } if (this.clientId == -1) { var client = new Client() { Name = data[0].ToString(), }; if (!this.db.Clients.Any(x => x.Name == client.Name)) { this.db.Clients.Add(client); this.db.SaveChanges(); } // we set the current client Id for the current sales reports file`s products this.clientId = this.db.Clients.First(x => x.Name == client.Name).Id; return; } if (data.Count < 4) { throw new ArgumentOutOfRangeException("Data record should have at least 4 fields"); } if (data[0].ToString().Contains("ProductID")) { return; } var order = new Order() { ProductId = int.Parse(data[0].ToString()), ClientId = this.clientId, Quantity = int.Parse(data[1].ToString()), Price = decimal.Parse(data[3].ToString()), DeliveryDate = (DateTime)data[data.Count - 1] }; this.db.Orders.Add(order); this.databaseMonitoredOrders++; // optimize dbContext for large data import if (this.databaseMonitoredOrders >= 10) { this.db.SaveChanges(); this.db = new FurnitureFactoryDbContext(); this.databaseMonitoredOrders = 0; } }
public ProductsExporter(FurnitureFactoryDbContext db) { this.db = db; }
public SQLArticleRepository(FurnitureFactoryDbContext context) { this._context = context; }
public Repository(FurnitureFactoryDbContext context) { _entities = context.Set <TEntity>(); _context = context; }
public ProductsXmlFileExporter(FurnitureFactoryDbContext db) : base(db) { }
public RepresentativesController(FurnitureFactoryDbContext context) { _context = context; }
public HomeController(ILogger <HomeController> logger, FurnitureFactoryDbContext dbContext) { _logger = logger; _dbContext = dbContext; }