Esempio n. 1
0
        private static void MoveProducts()
        {
            var client = new SupermarketModel();

            using (client)
            {
                var products = client.Products;

                using (SupermarketContext context = new SupermarketContext())
                {
                    foreach (var item in products)
                    {
                        var product = new SupermarketSQL.Models.Product
                        {
                            ProductName = item.ProductName,
                            BasePrice   = item.BasePrice,
                            MeasureId   = item.MeasureId,
                            VendorId    = item.VendorId
                        };
                        context.Products.Add(product);
                    }

                    context.SaveChanges();
                }
            }
        }
Esempio n. 2
0
        protected override void Seed(SupermarketSQLDbContext context)
        {
            using (var dbSuperMarketMysql = new SupermarketModel())
            {
                dbSuperMarketMysql.Vendors.ToList().ForEach(v =>
                {
                    var vendor        = new Vendor();
                    vendor.VendorName = v.VendorName;
                    SessionState.db.Vendors.Add(vendor);
                });
                SessionState.db.SaveChanges();
                dbSuperMarketMysql.Measures.ToList().ForEach(m =>
                {
                    Measure measure     = new Measure();
                    measure.MeasureName = m.MeasureName;
                    SessionState.db.Measures.Add(measure);
                });
                SessionState.db.SaveChanges();
                dbSuperMarketMysql.Products.ToList().ForEach(p =>
                {
                    string vendorID  = p.VendorID.Value.ToString();
                    string measureID = p.MeasureID.Value.ToString();

                    Product product     = new Product();
                    product.VendorID    = int.Parse(vendorID.Remove(vendorID.Length - 1, 1));
                    product.ProductName = p.ProductName;
                    product.MeasureID   = int.Parse(measureID.Remove(measureID.Length - 2, 2));
                    product.BasePrice   = p.BasePrice;
                    SessionState.db.Products.Add(product);
                });
                SessionState.db.SaveChanges();
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            SetTempDirectory();

            UnZipFiles();

            InitializeRootDirectory();

            // Console.WriteLine(ROOT.ChildFolders[0].Files[0].Path);

            //string pathToFile = ROOT.ChildFolders[0].Files[0].Path;

            // PrintFileData(pathToFile);

            // PrintFolderFilesInfo(ROOT);

            using (var superMarketDb = new SupermarketModel())
            {
                var measure = superMarketDb.Measures.FirstOrDefault(m => m.ID == 1);

                var b = 5;
            }

            // PrintFileData("..\\..\\Temp-20130722021046\\22-Jul-2013\\Plovdiv-Stolipinovo-Sales-Report-22-Jul-2013.xls");
            var a = 5;
        }
Esempio n. 4
0
        protected override void Seed(Supermarket.Data.SuperMarketContext context)
        {
            var openAccesContext = new SupermarketModel();

            using (openAccesContext)
            {
                foreach (var product in openAccesContext.Products)
                {
                    context.Products.AddOrUpdate(new Product {
                        ID = product.ID, VendorID = product.VendorID, ProductName = product.ProductName, MeasureID = product.MeasureID, BasePrice = product.BasePrice
                    });
                }

                foreach (var measure in openAccesContext.Measures)
                {
                    context.Measures.AddOrUpdate(new Measure {
                        ID = measure.ID, MeasureName = measure.MeasureName
                    });
                }

                foreach (var vendor in openAccesContext.Vendors)
                {
                    context.Vendors.AddOrUpdate(new Vendor {
                        ID = vendor.ID, VendorName = vendor.VendorName
                    });
                }
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> EditPost(int?id)
        {
            if (id is null)
            {
                return(NotFound());
            }

            SupermarketModel supermarketToUpdate = await context.Supermarkets
                                                   .FirstOrDefaultAsync(sm => sm.ID.Equals(id));

            if (await TryUpdateModelAsync <SupermarketModel>(
                    supermarketToUpdate,
                    "",
                    sm => sm.Name, sm => sm.Address))
            {
                try
                {
                    await context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                catch (DbUpdateException /* ex */)
                {
                    ModelState.AddModelError("", "Unable to save changes. " +
                                             "Try again, and if the problem persists, " +
                                             "see your system administrator.");
                }
            }
            return(View(supermarketToUpdate));
        }
Esempio n. 6
0
        public void MigrateDataFromMySqlToSqlServer()
        {
            using (var supermarketContextSqlServer = new SupermarketContext())
            {
                using (var supermarketContextMySql = new SupermarketModel())
                {
                    foreach (var measureMySql in supermarketContextMySql.Measures)
                    {
                        if (!supermarketContextSqlServer.Measures
                            .Any(m => m.MeasureName == measureMySql.MeasureName))
                        {
                            supermarketContextSqlServer.Measures.Add(new Models.Measure()
                            {
                                MeasureName = measureMySql.MeasureName
                            });
                        }
                    }

                    foreach (var vendorMySql in supermarketContextMySql.Vendors)
                    {
                        if (!supermarketContextSqlServer.Vendors
                            .Any(v => v.VendorName == vendorMySql.VendorName))
                        {
                            supermarketContextSqlServer.Vendors.Add(new Models.Vendor()
                            {
                                VendorName = vendorMySql.VendorName
                            });
                        }
                    }

                    supermarketContextSqlServer.SaveChanges();

                    foreach (var productMySql in supermarketContextMySql.Products)
                    {
                        if (!supermarketContextSqlServer.Products
                            .Any(p => p.Name == productMySql.ProductName))
                        {
                            var vendorSqlServer = supermarketContextSqlServer.Vendors
                                                  .First(v => v.VendorName == productMySql.Vendor.VendorName);
                            var measureSqlServer = supermarketContextSqlServer.Measures
                                                   .First(m => m.MeasureName == productMySql.Measure.MeasureName);

                            supermarketContextSqlServer.Products.Add(new Models.Product()
                            {
                                BasePrice = productMySql.BasePrice,
                                Name      = productMySql.ProductName,
                                Measure   = measureSqlServer,
                                Vendor    = vendorSqlServer,
                            });
                        }
                    }
                }

                supermarketContextSqlServer.SaveChanges();
            }
        }
        public void MigrateDataFromMySqlToSqlServer()
        {
            using (var supermarketContextSqlServer = new SupermarketContext())
            {
                using (var supermarketContextMySql = new SupermarketModel())
                {
                    foreach (var measureMySql in supermarketContextMySql.Measures)
                    {
                        if (!supermarketContextSqlServer.Measures
                            .Any(m => m.MeasureName == measureMySql.MeasureName))
                        {
                            supermarketContextSqlServer.Measures.Add(new Models.Measure()
                            {
                                MeasureName = measureMySql.MeasureName
                            });
                        }
                    }

                    foreach (var vendorMySql in supermarketContextMySql.Vendors)
                    {
                        if (!supermarketContextSqlServer.Vendors
                            .Any(v => v.VendorName == vendorMySql.VendorName))
                        {
                            supermarketContextSqlServer.Vendors.Add(new Models.Vendor()
                            {
                                VendorName = vendorMySql.VendorName
                            });
                        }
                    }

                    supermarketContextSqlServer.SaveChanges();

                    foreach (var productMySql in supermarketContextMySql.Products)
                    {
                        if (!supermarketContextSqlServer.Products
                            .Any(p => p.Name == productMySql.ProductName))
                        {
                            var vendorSqlServer = supermarketContextSqlServer.Vendors
                                .First(v => v.VendorName == productMySql.Vendor.VendorName);
                            var measureSqlServer = supermarketContextSqlServer.Measures
                                .First(m => m.MeasureName == productMySql.Measure.MeasureName);

                            supermarketContextSqlServer.Products.Add(new Models.Product()
                            {
                                BasePrice = productMySql.BasePrice,
                                Name = productMySql.ProductName,
                                Measure = measureSqlServer,
                                Vendor = vendorSqlServer,
                            });
                        }
                    }
                }

                supermarketContextSqlServer.SaveChanges();
            }
        }
Esempio n. 8
0
        private static void FromMySqlNeverAgain()
        {
            var dbcontext = new SupermarketContext();

            var mySqlContx = new SupermarketModel();

            using (mySqlContx)
            {
                var products = mySqlContx.Products.OrderBy(e => e.ID).ToList();
                var vendors  = mySqlContx.Vendors.ToList();
                var mesuares = mySqlContx.Measures.ToList();
                using (dbcontext)
                {
                    foreach (var mesuare in mesuares)
                    {
                        var newMeasure = new Measure()
                        {
                            ID   = mesuare.ID,
                            Name = mesuare.Name
                        };
                        dbcontext.Measures.Add(newMeasure);
                    }

                    foreach (var vendor in vendors)
                    {
                        var newVendor = new Vendor()
                        {
                            ID   = vendor.ID,
                            Name = vendor.Name
                        };
                        dbcontext.Vendors.Add(newVendor);
                    }


                    foreach (var product in products)
                    {
                        var some = new Product
                        {
                            BasePrice  = product.BasePrice,
                            Measure_ID = product.Measure_ID,
                            Name       = product.Name,
                            Vendor_ID  = product.Vendor_ID,
                        };
                        dbcontext.Products.Add(some);
                    }

                    dbcontext.SaveChanges();
                }
            }
        }
Esempio n. 9
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id is null)
            {
                return(NotFound());
            }

            SupermarketModel supermarket = await GetSupermarketByIdAsync(id);

            if (supermarket is null)
            {
                return(NotFound());
            }

            return(View(supermarket));
        }
Esempio n. 10
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            SupermarketModel supermarket = await context.Supermarkets.FindAsync(id);

            if (!(supermarket is null))
            {
                try
                {
                    context.Supermarkets.Remove(supermarket);
                    await context.SaveChangesAsync();
                }
                catch (DbUpdateException /* ex */)
                {
                    ModelState.AddModelError("",
                                             "Delete failed. Try again, and if the problem persists " +
                                             "see your system administrator.");
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 11
0
        public async Task <IActionResult> Create(SupermarketModel supermarket)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    context.Supermarkets.Add(supermarket);
                    await context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(supermarket));
        }
Esempio n. 12
0
        private static void InitializeDataFromMySQL()
        {
            var db = new SupermarketContext();
            SupermarketModel model = new SupermarketModel();

            using (db)
            {
                foreach (var measure in model.Measures)
                {
                    db.Measurments.Add(new Measure()
                    {
                        Id          = measure.Id,
                        MeasureName = measure.MeasureName
                    });
                }

                foreach (var vendor in model.Vendors)
                {
                    db.Vendors.Add(new Vendor()
                    {
                        Id         = vendor.Id,
                        VendorName = vendor.VendorName
                    });
                }
                foreach (var product in model.Products)
                {
                    db.Products.Add(new Product()
                    {
                        Id          = product.Id,
                        BasePrice   = product.BasePrice,
                        MeasureId   = product.MeasureId,
                        ProductName = product.ProductName,
                        VendorId    = product.VendorId
                    });
                }

                db.SaveChanges();
                Console.WriteLine("1. Data from MySQL saved in SQL Server!");
            }
        }
Esempio n. 13
0
        private static void MoveMeasures()
        {
            var client = new SupermarketModel();

            using (client)
            {
                var measures = client.Measures;

                using (SupermarketContext context = new SupermarketContext())
                {
                    foreach (var item in measures)
                    {
                        var measure = new SupermarketSQL.Models.Measure {
                            MeasureName = item.MeasureName
                        };
                        context.Measures.Add(measure);
                    }

                    context.SaveChanges();
                }
            }
        }
Esempio n. 14
0
        private static void MoveVendors()
        {
            var client = new SupermarketModel();

            using (client)
            {
                var vendors = client.Vendors;

                using (SupermarketContext context = new SupermarketContext())
                {
                    foreach (var item in vendors)
                    {
                        var vendor = new SupermarketSQL.Models.Vendor
                        {
                            VendorName = item.VendorName
                        };
                        context.Vendors.Add(vendor);
                    }

                    context.SaveChanges();
                }
            }
        }
        public static async Task InitializeAsync(ShoppingContext context)
        {
            if (await context.Database.EnsureCreatedAsync())
            {
                return;
            }

            if (context.Customers.Any())
            {
                return;
            }

            CustomerModel[] customers = new CustomerModel[]
            {
                new CustomerModel {
                    FirstName = "Carson", LastName = "Alexander", Address = "Lviv", Discount = "5"
                },
                new CustomerModel {
                    FirstName = "Meredith", LastName = "Alonso", Address = "Kyiv", Discount = "65"
                },
                new CustomerModel {
                    FirstName = "Arturo", LastName = "Anand", Address = "Mykolaiv", Discount = "3"
                },
                new CustomerModel {
                    FirstName = "Gytis", LastName = "Barzdukas", Address = "Odessa", Discount = "56"
                },
                new CustomerModel {
                    FirstName = "Yan", LastName = "Li", Address = "Lviv", Discount = "22"
                },
                new CustomerModel {
                    FirstName = "Peggy", LastName = "Justice", Address = "Lviv", Discount = "15"
                },
                new CustomerModel {
                    FirstName = "Laura", LastName = "Norman", Address = "Kyiv", Discount = "15"
                },
                new CustomerModel {
                    FirstName = "Nino", LastName = "Olivetto", Address = "London", Discount = "10"
                }
            };

            await context.Customers.AddRangeAsync(customers);

            await context.SaveChangesAsync();

            ProductModel[] products = new ProductModel[]
            {
                new ProductModel {
                    Name = "iPhone X", Price = 1250
                },
                new ProductModel {
                    Name = "iPhone Xr", Price = 1350
                },
                new ProductModel {
                    Name = "iPhone XS", Price = 1450
                },
                new ProductModel {
                    Name = "iPhone 5", Price = 350
                },
                new ProductModel {
                    Name = "iPhone 6", Price = 400
                },
                new ProductModel {
                    Name = "iPhone 7", Price = 500
                },
                new ProductModel {
                    Name = "iPhone 8", Price = 600
                },
                new ProductModel {
                    Name = "iPhone 4", Price = 250
                }
            };

            await context.Products.AddRangeAsync(products);

            await context.SaveChangesAsync();

            SupermarketModel[] supermarkets = new SupermarketModel[]
            {
                new SupermarketModel {
                    Address = "Lviv", Name = "Silpo"
                },
                new SupermarketModel {
                    Address = "Kyiv", Name = "Silpo"
                },
                new SupermarketModel {
                    Address = "Lviv", Name = "Metro"
                },
                new SupermarketModel {
                    Address = "Mykolaiv", Name = "Nash Kray"
                },
                new SupermarketModel {
                    Address = "Lviv", Name = "Rukavychka"
                },
                new SupermarketModel {
                    Address = "Mykolaiv", Name = "Rukavychka"
                },
                new SupermarketModel {
                    Address = "Kyiv", Name = "Rukavychka"
                }
            };

            await context.Supermarkets.AddRangeAsync(supermarkets);

            await context.SaveChangesAsync();

            List <Object>[] orders = new List <Object>[]
            {
                new List <Object>
                {
                    new OrderModel {
                        CustomerModelId = 2, SupermarketModelId = 3, OrderDate = new DateTime(2012, 6, 3)
                    },
                    new OrderDetailsModel {
                        ProductModel = products[0], Quantity = 2
                    },
                    new OrderDetailsModel {
                        ProductModel = products[1], Quantity = 2
                    }
                },
                new List <Object>
                {
                    new OrderModel {
                        CustomerModelId = 1, SupermarketModelId = 6, OrderDate = new DateTime(2015, 7, 3)
                    },
                    new OrderDetailsModel {
                        ProductModel = products[1], Quantity = 1
                    },
                    new OrderDetailsModel {
                        ProductModel = products[3], Quantity = 13
                    }
                },
                new List <Object>
                {
                    new OrderModel {
                        CustomerModelId = 5, SupermarketModelId = 2, OrderDate = new DateTime(2011, 4, 3)
                    },
                    new OrderDetailsModel {
                        ProductModel = products[3], Quantity = 9
                    },
                    new OrderDetailsModel {
                        ProductModel = products[4], Quantity = 4
                    }
                },
                new List <Object>
                {
                    new OrderModel {
                        CustomerModelId = 4, SupermarketModelId = 3, OrderDate = new DateTime(2016, 2, 3)
                    },
                    new OrderDetailsModel {
                        ProductModel = products[4], Quantity = 15
                    },
                    new OrderDetailsModel {
                        ProductModel = products[5], Quantity = 3
                    },
                },
                new List <Object>
                {
                    new OrderModel {
                        CustomerModelId = 4, SupermarketModelId = 5, OrderDate = new DateTime(2018, 8, 3)
                    },
                    new OrderDetailsModel {
                        ProductModel = products[6], Quantity = 7
                    },
                    new OrderDetailsModel {
                        ProductModel = products[1], Quantity = 17
                    }
                }
            };

            foreach (List <Object> item in orders)
            {
                OrderModel order = (OrderModel)item[0];
                context.Orders.Add(order);
                await context.SaveChangesAsync();

                OrderDetailsModel details1 = ((OrderDetailsModel)item[1]);
                details1.OrderId = order.Id;
                details1.Order   = order;
                context.OrderDetails.Add(details1);
                await context.SaveChangesAsync();

                OrderDetailsModel details2 = ((OrderDetailsModel)item[2]);
                details2.OrderId = order.Id;
                details2.Order   = order;
                context.OrderDetails.Add(details2);
                await context.SaveChangesAsync();
            }
        }