private static void SeedCategories()
        {
            var context = new ShopEntities();
            using (StreamReader file = File.OpenText("../../../categories.json"))
            {
                Category[] categories = JsonConvert.DeserializeObject<Category[]>(file.ReadToEnd());

                foreach (var category in categories)
                {
                    context.Categories.AddOrUpdate(category);
                }

                context.SaveChanges();
            }
        }
 private static void SeedProductCategories()
 {
     var context = new ShopEntities();
     for (int i = 3; i < 47; i++)
     {
         Random rnd = new Random();
         using (var dbContextTransaction4 = context.Database.BeginTransaction())
         {
             try
             {
                 context.Database.ExecuteSqlCommand(
                     "INSERT INTO ProductCategories(Product_Id, Category_Id) VALUES (" + i + "," +
                     rnd.Next(1, 11) + ")");
                 context.SaveChanges();
                 dbContextTransaction4.Commit();
             }
             catch (Exception)
             {
                 dbContextTransaction4.Rollback();
             }
         }
     }
 }
        private static void SeedUsers()
        {
            var context = new ShopEntities();
            var path = "..\\..\\..\\users.xml";
            var doc = XDocument.Load(path);
            string json = JsonConvert.SerializeXNode(doc, Newtonsoft.Json.Formatting.Indented);
            var jsonObj = JObject.Parse(json);
            foreach (var u in jsonObj["users"]["user"])
            {
                string lname = u["@last-name"].ToString();
                string fname = null;
                if (u["@first-name"] != null)
                {
                    fname = u["@first-name"].ToString();
                }

                if (!Object.ReferenceEquals(null, u["@age"]))
                {
                    int age = int.Parse((u["@age"].ToString()));

                    using (var dbContextTransaction = context.Database.BeginTransaction())
                    {
                        try
                        {
                            context.Database.ExecuteSqlCommand(
                                "INSERT INTO Users(FirstName, LastName, Age) VALUES ('" + fname + "','" + lname + "'," +
                                age + ")");
                            context.SaveChanges();
                            dbContextTransaction.Commit();
                        }
                        catch (Exception)
                        {
                            dbContextTransaction.Rollback();
                        }
                    }
                }
                else
                {
                    using (var dbContextTransaction2 = context.Database.BeginTransaction())
                    {
                        try
                        {
                            context.Database.ExecuteSqlCommand(
                                "INSERT INTO Users(FirstName, LastName) VALUES (" + fname + "," + lname + ")");
                            context.SaveChanges();
                            dbContextTransaction2.Commit();
                        }
                        catch (Exception)
                        {
                            dbContextTransaction2.Rollback();
                        }
                    }
                }
            }
        }
 private static void SeedProducts()
 {
     var context = new ShopEntities();
     using (StreamReader file = File.OpenText("../../../products.json"))
     {
         Product[] products = JsonConvert.DeserializeObject<Product[]>(file.ReadToEnd());
         Random rnd = new Random();
         int buyer = rnd.Next(0, 50);
         int seller = 46;
         foreach (var product in products)
         {
             double price = Double.Parse((product.Price).ToString());
             string name = product.Name.ToString();
             if (buyer >= 3 && buyer <= 46)
             {
                 using (var dbContextTransaction3 = context.Database.BeginTransaction())
                 {
                     try
                     {
                         context.Database.ExecuteSqlCommand(
                             "INSERT INTO Products(Name, Price, BuyerId, SellerId) VALUES ('" + name + "'," +
                             price + "," + buyer + "," + seller + ")");
                         context.SaveChanges();
                         dbContextTransaction3.Commit();
                     }
                     catch (Exception)
                     {
                         dbContextTransaction3.Rollback();
                     }
                 }
             }
             else
             {
                 using (var dbContextTransaction5 = context.Database.BeginTransaction())
                 {
                     try
                     {
                         context.Database.ExecuteSqlCommand(
                             "INSERT INTO Products(Name, Price, SellerId) VALUES ('" + name + "'," +
                             price + "," + seller + ")");
                         context.SaveChanges();
                         dbContextTransaction5.Commit();
                     }
                     catch (Exception)
                     {
                         dbContextTransaction5.Rollback();
                     }
                 }
             }
             buyer = rnd.Next(0, 50);
             seller--;
         }
     }
 }