public static List<ProductReport> CreateReportForEveryProductFromSQLServer() { SQLServerContext db = new SQLServerContextFactory().Create(); var reports = new List<ProductReport>(); using (db) { var productsCount = GetProductsCount(db); var productSalesData = GetProductsDataFromDb(db); reports = new List<ProductReport>(productsCount); for (int i = 1; i <= productsCount; i++) { var currentProduct = new ProductReport(i); foreach (var product in productSalesData) { if (product.Id == currentProduct.Id) { currentProduct.ProductCode = product.ProductCode; currentProduct.Name = product.Name; currentProduct.ShopNames.Add(product.ShopName); currentProduct.TotalQuantitySold += product.TotalQuantitySold; currentProduct.TotalIncomes += product.TotalIncomes; } } reports.Add(currentProduct); } } return reports; }
public static List<ProductReport> CreateReportForEveryProductFromMySQL() { MySQLContext db = new MySQLContext("MySQLConnStrDKostovLaptop"); var reports = new List<ProductReport>(); using (db) { var productsCount = GetProductsCount(db); var productSalesData = GetProductsDataFromDb(db); var firstProductId = GetFirstProductId(db); reports = new List<ProductReport>(productsCount); var length = firstProductId + productsCount; for (int i = firstProductId; i < length; i++) { var currentProduct = new ProductReport(i); foreach (var product in productSalesData) { if (product.Id == currentProduct.Id) { currentProduct.ProductCode = product.ProductCode; currentProduct.Name = product.Name; currentProduct.ShopNames.Add(product.ShopName); currentProduct.TotalQuantitySold += product.TotalQuantitySold; currentProduct.TotalIncomes += product.TotalIncomes; } } reports.Add(currentProduct); } } return reports; }