Exemple #1
0
        public static void SaveData()
        {
            var mongoClient      = new MongoClient(@"mongodb://localhost/");
            var mongoServer      = mongoClient.GetServer();
            var productsDb       = mongoServer.GetDatabase("ProductsDb");
            var products         = productsDb.GetCollection <FullIProductInformation>("products");
            SqlServerEntities db = new SqlServerEntities();

            using (db)
            {
                var salesReports = db.Sales
                                   .Include("Product")
                                   .Include("Supermarket")
                                   .Include("Product.Vendor")
                                   .ToList()
                                   .GroupBy(x => x.Product.ProductName);

                foreach (var item in salesReports)
                {
                    FullIProductInformation info = new FullIProductInformation();

                    info.TotalIncomes      = item.Sum(x => x.Sum);
                    info.ProductName       = item.Key;
                    info.TotalQuantitySold = item.Sum(x => x.Quantity);
                    info.VendorName        = item.First().Product.Vendor.VendorName;
                    info.ProductId         = item.First().ProductId;
                    SaveToFile(info);
                    products.Insert(info);
                }
            }
        }
        public static void SaveData()
        {
            var mongoClient = new MongoClient(@"mongodb://localhost/");
            var mongoServer = mongoClient.GetServer();
            var productsDb = mongoServer.GetDatabase("ProductsDb");
            var products = productsDb.GetCollection<FullIProductInformation>("products");
            SqlServerEntities db = new SqlServerEntities();
            using (db)
            {
                var salesReports = db.Sales
                                         .Include("Product")
                                         .Include("Supermarket")
                                         .Include("Product.Vendor")
                                         .ToList()
                                         .GroupBy(x => x.Product.ProductName);

                foreach (var item in salesReports)
                {
                    FullIProductInformation info = new FullIProductInformation();

                    info.TotalIncomes = item.Sum(x => x.Sum);
                    info.ProductName = item.Key;
                    info.TotalQuantitySold = item.Sum(x => x.Quantity);
                    info.VendorName = item.First().Product.Vendor.VendorName;
                    info.ProductId = item.First().ProductId;
                    SaveToFile(info);
                    products.Insert(info);
                }

            }
        }
Exemple #3
0
        private static void SaveToFile(FullIProductInformation product)
        {
            var          json   = new JavaScriptSerializer().Serialize(product);
            string       path   = @"..\..\Products-reports\";
            StreamWriter writer = new StreamWriter(path + product.ProductId + ".json");

            using (writer)
            {
                writer.Write(json);
            }
        }
        private static void SaveToFile(FullIProductInformation product)
        {
            var json = new JavaScriptSerializer().Serialize(product);
            string path = @"..\..\Products-reports\";
            StreamWriter writer = new StreamWriter(path + product.ProductId + ".json");

            using (writer)
            {
                writer.Write(json);
            }
        }