Пример #1
0
        public static void ReadMySQL(SalesContext SqlDatabase, SupermarketModel mySqlTest)
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<SalesContext, Configuration>());


            foreach (var vendor in mySqlTest.Vendors)
            {
                if (!SqlDatabase.Vendors.Any(x => x.Name == vendor.VendorName))
                {
                    SqlDatabase.Vendors.Add(new Models.MSSQL.Vendor
                    {
                        Name = vendor.VendorName,
                    });
                }
            }

            SqlDatabase.SaveChanges();

            foreach (var product in mySqlTest.Products.Include("Vendors").Include("Measures"))
            {
                SqlDatabase.Products.Add(new Sales.Models.MSSQL.Product
                {
                    Name = product.ProductName,
                    Vendor = SqlDatabase.Vendors.Where(x => x.Name == product.Vendor.VendorName).First(),
                    BasePrice = (decimal)product.BasePrice,
                    Measure = (Models.MSSQL.Measure)Enum.Parse(typeof(Models.MSSQL.Measure), product.Measure.MeasureName)
                });
            }

            SqlDatabase.SaveChanges();
        }
Пример #2
0
        public static void ReadExcel(SalesContext db, SupermarketModel sql)
        {
            var results =
                new ReadExcelReports("../../../Data/Sample-Sales-Reports.zip", "../../../Temp/ExcelReports/").Extract().Read();

            foreach (var result in results)
            {
                foreach (var row in result.Items)
                {
                    var productName = sql.Products.Where(x => x.ID == row.Id).First().ProductName;
                    var product = db.Products.Where(x => x.Name == productName).First();
                    var supermarket = db.Supermarkets.Where(x => x.Name == result.Name).FirstOrDefault();
                    if (supermarket == null)
                    {
                        supermarket = new Supermarket();
                        supermarket.Name = result.Name;
                    }

                    db.Records.Add(new Models.MSSQL.Record
                    {
                        Quantity = row.Quantity,
                        UnitPrice = row.UnitPrice,
                        Product = product,
                        Date = result.Date,
                        Supermarket = supermarket
                    });

                    db.SaveChanges();
                }
            }

            db.SaveChanges();
            Directory.Delete("../../../Temp/", true);
        }
Пример #3
0
        public static void PassToSql(
            IEnumerable<Sales.Models.Excel.SupermarketData> results, 
            SalesContext db, 
            SupermarketModel sql)
        {
            using (db)
            {
                foreach (var result in results)
                {
                    foreach (var row in result.Items)
                    {
                        var productName = sql.Products.Where(x => x.ID == row.Id).First().ProductName;
                        var product = db.Products.Where(x => x.Name == productName).First();
                        var supermarket = db.Supermarkets.Where(x => x.Name == result.Name).FirstOrDefault();
                        if (supermarket == null)
                        {
                            supermarket = new Supermarket();
                            supermarket.Name = result.Name;
                        }

                        db.Records.Add(new Models.MSSQL.Record
                        {
                            Quantity = row.Quantity,
                            UnitPrice = row.UnitPrice,
                            Product = product,
                            Date = result.Date,
                            Supermarket = supermarket
                        });

                        db.SaveChanges();
                    }
                }
                db.SaveChanges();
            }
        }
Пример #4
0
        public static void Save()
        {
            var expenses = ParseExpenses.Read("../../../Data/expenses.xml");

            {
                var server = new MongoClient("mongodb://localhost").GetServer();
                var db = server.GetDatabase("salesDB");
                var sales = db.GetCollection<Expenses>("vendorExpenses");

                sales.InsertBatch(expenses);
            }

            using (var db = new SalesContext())
            {
                foreach (var expense in expenses)
                {
                    var vendor = db.Vendors.FirstOrDefault(x => x.Name == expense.Vendor);

                    if (vendor == null)
                    {
                        continue;
                    }

                    foreach (var item in expense.List)
                    {
                        vendor.Expenses.Add(new Models.MSSQL.Expenses
                        {
                            DateTime = item.Key,
                            Money = item.Value
                        });
                    }
                }

                db.SaveChanges();
            }
        }