예제 #1
0
        private static void LoadSalesReports()
        {
            List<SalesReport> salesReports = ProcessSalesReports();
            using (ProductsDBContext sqlContext = new ProductsDBContext())
            {
                foreach (var salesReport in salesReports)
                {
                    sqlContext.SalesReports.Add(salesReport);
                }

                sqlContext.SaveChanges();
            }
        }
예제 #2
0
        private static void UpdateDataBasesFromXML()
        {
            ProductsDBContext sqlContext = new ProductsDBContext();
            MongoClient client = new MongoClient("mongodb://localhost/");
            MongoServer server = client.GetServer();
            var productsDB = server.GetDatabase("ProductsDB");
            MongoCollection<Expense> expensesMongo = productsDB.GetCollection<Expense>("Expenses");

            using (XmlReader reader = XmlReader.Create(@"..\..\Data\VendorExpenses.xml"))
            {
                DateTime month = new DateTime();
                decimal amount = 0;
                string vendorName = string.Empty;
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.Name == "sale")
                        {
                            vendorName = reader.GetAttribute("vendor");
                        }
                        else if (reader.Name == "expenses")
                        {
                            month = DateTime.Parse(string.Format("{0:MMM-YYYY}", reader.GetAttribute("month")));
                        }

                    }
                    else if (reader.NodeType == XmlNodeType.Text)
                    {
                        amount = decimal.Parse(reader.Value);
                        ProductsDB.Model.Vendor vendor = sqlContext.Vendors.Where(v => v.VendorName == vendorName)
                            .FirstOrDefault();
                        Expense expenseSQL = new Expense()
                        {
                            Amount = amount,
                            Vendor = vendor,
                            Date = month
                        };

                        Expense expenseMongo = new Expense()
                        {
                            Amount = amount,
                            VendorId = vendor.VendorId,
                            Date = month
                        };

                        sqlContext.Expenses.Add(expenseSQL);
                        expensesMongo.Insert(expenseMongo);
                    }
                }
            }

            sqlContext.SaveChanges();
        }
예제 #3
0
        private static void LoadMySQLEntries()
        {
            using (ProductsDBContext sqlContext = new ProductsDBContext())
            {
                ProductsDBModel mySQLContext = new ProductsDBModel(@"Server=localhost;Database=products_db;Uid=Rami;Pwd=killer91;");
                foreach (var measure in mySQLContext.Measures)
                {
                    ProductsDB.Model.Measure newMeasure = new Model.Measure()
                    {
                        MeasureId = measure.Measure_ID,
                        MeasureName = measure.Measure_Name
                    };

                    sqlContext.Measures.Add(newMeasure);
                }

                sqlContext.SaveChanges();

                foreach (var vendor in mySQLContext.Vendors)
                {
                    ProductsDB.Model.Vendor newVendor = new Model.Vendor()
                    {
                        VendorId = vendor.Vendor_ID,
                        VendorName = vendor.Vendor_Name
                    };

                    sqlContext.Vendors.Add(newVendor);
                }

                sqlContext.SaveChanges();

                foreach (var prod in mySQLContext.Products)
                {
                    ProductsDB.Model.Vendor vendor = sqlContext.Vendors.Where
                        (v => v.VendorId == prod.Vendors_Vendor_ID).First();
                    ProductsDB.Model.Measure measure = sqlContext.Measures.Where
                        (m => m.MeasureId == prod.Measures_Measure_ID).First();
                    ProductsDB.Model.Product newProd = new Model.Product()
                    {
                        ProductId = prod.Products_ID,
                        ProductName = prod.Product_Name,
                        VendorId = prod.Vendors_Vendor_ID,
                        Vendor = vendor,
                        MeasureId = prod.Measures_Measure_ID,
                        Measure = measure,
                        BasePrice = prod.BasePrice,
                    };

                    sqlContext.Products.Add(newProd);
                }

                sqlContext.SaveChanges();
            }
        }