Exemplo n.º 1
0
 public void Delete(WebStoreContext db, Product product)
 {
     db.Products.Remove(product);
     db.SaveChanges();
 }
Exemplo n.º 2
0
 public void Post(WebStoreContext db, Product product)
 {
     db.Products.Add(product);
     db.SaveChanges();
 }
Exemplo n.º 3
0
 public void Create(Variant item)
 {
     _context.Variants.Add(item);
     _context.SaveChanges();
 }
Exemplo n.º 4
0
 public void Create(Product item)
 {
     db.Products.Add(item);
     db.SaveChanges();
 }
Exemplo n.º 5
0
 public void Create(User item)
 {
     db.Users.Add(item);
     db.SaveChanges();
 }
Exemplo n.º 6
0
        public static void Initialize(WebStoreContext context)
        {
            var rents = new Rent[]
            {
                new Rent
                {
                    CustomerId = 1,
                    TotalPrice = 50000,
                    Performed  = false
                },
                new Rent
                {
                    CustomerId = 1,
                    TotalPrice = 100000,
                    Performed  = false
                }
            };

            foreach (Rent r in rents)
            {
                context.Rents.Add(r);
            }
            context.SaveChanges();


            var rentProductConnections = new RentProductConnection[]
            {
                new RentProductConnection
                {
                    ProductModellNumber = 125,
                    CountProduct        = 1,
                    RentId = 2,
                },
                new RentProductConnection
                {
                    ProductModellNumber = 126,
                    CountProduct        = 2,
                    RentId = 1
                },
                new RentProductConnection
                {
                    ProductModellNumber = 140,
                    CountProduct        = 5,
                    RentId = 1
                }
            };

            foreach (RentProductConnection rp in rentProductConnections)
            {
                context.RentProductConnections.Add(rp);
            }
            context.SaveChanges();

            var categories = new Category[]
            {
                new Category {
                    Name = "Telefon"
                },
                new Category {
                    Name = "Mosógép"
                },
                new Category {
                    Name = "Laptop"
                },
                new Category {
                    Name = "Hangszoró"
                },
                new Category {
                    Name = "TV"
                },
                new Category {
                    Name = "Porszívó"
                },
                new Category {
                    Name = "Kábelek"
                }
            };

            foreach (Category c in categories)
            {
                context.Categories.Add(c);
            }
            context.SaveChanges();


            var products = new Product[]
            {
                new Product
                {
                    Producer     = "Apple",
                    ModellNumber = 124,
                    Description  = "Iphone8",
                    CategoryId   = 1,
                    Price        = 200000,
                    Inventory    = 10,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Apple",
                    ModellNumber = 125,
                    Description  = "IphoneX",
                    CategoryId   = 1,
                    Price        = 300000,
                    Inventory    = 5,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Apple",
                    ModellNumber = 126,
                    Description  = "Iphone6S",
                    CategoryId   = 1,
                    Price        = 140000,
                    Inventory    = 15,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Apple",
                    ModellNumber = 127,
                    Description  = "IphoneSE",
                    CategoryId   = 1,
                    Price        = 90000,
                    Inventory    = 20,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Apple",
                    ModellNumber = 128,
                    Description  = "Iphone4",
                    CategoryId   = 1,
                    Price        = 30000,
                    Inventory    = 10,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Apple",
                    ModellNumber = 129,
                    Description  = "Iphone4/S",
                    CategoryId   = 1,
                    Price        = 45000,
                    Inventory    = 7,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Apple",
                    ModellNumber = 130,
                    Description  = "Iphone5",
                    CategoryId   = 1,
                    Price        = 50000,
                    Inventory    = 15,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Apple",
                    ModellNumber = 131,
                    Description  = "Iphone5/S",
                    CategoryId   = 1,
                    Price        = 60000,
                    Inventory    = 18,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Apple",
                    ModellNumber = 132,
                    Description  = "Iphone6",
                    CategoryId   = 1,
                    Price        = 75000,
                    Inventory    = 20,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Apple",
                    ModellNumber = 133,
                    Description  = "Iphone7",
                    CategoryId   = 1,
                    Price        = 150000,
                    Inventory    = 30,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Samsung",
                    ModellNumber = 140,
                    Description  = "Samsung Galaxy S4",
                    CategoryId   = 1,
                    Price        = 30000,
                    Inventory    = 4,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Samsung",
                    ModellNumber = 141,
                    Description  = "Samsung Galaxy S5",
                    CategoryId   = 1,
                    Price        = 40000,
                    Inventory    = 15,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Samsung",
                    ModellNumber = 142,
                    Description  = "Samsung Galaxy S5 Edge",
                    CategoryId   = 1,
                    Price        = 60000,
                    Inventory    = 40,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Samsung",
                    ModellNumber = 143,
                    Description  = "Samsung Galaxy S6",
                    CategoryId   = 1,
                    Price        = 100000,
                    Inventory    = 10,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Samsung",
                    ModellNumber = 144,
                    Description  = "Samsung Galaxy S6 Edge",
                    CategoryId   = 1,
                    Price        = 120000,
                    Inventory    = 5,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Samsung",
                    ModellNumber = 145,
                    Description  = "Samsung Galaxy S7",
                    CategoryId   = 1,
                    Price        = 140000,
                    Inventory    = 6,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Samsung",
                    ModellNumber = 146,
                    Description  = "Samsung Galaxy S7 Edge",
                    CategoryId   = 1,
                    Price        = 160000,
                    Inventory    = 4,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Samsung",
                    ModellNumber = 147,
                    Description  = "Samsung Galaxy S8",
                    CategoryId   = 1,
                    Price        = 180000,
                    Inventory    = 10,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Samsung",
                    ModellNumber = 148,
                    Description  = "Samsung Galaxy S8 Edge",
                    CategoryId   = 1,
                    Price        = 200000,
                    Inventory    = 15,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Sony",
                    ModellNumber = 160,
                    Description  = "Sony XPeria Z",
                    CategoryId   = 1,
                    Price        = 60000,
                    Inventory    = 5,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Sony",
                    ModellNumber = 161,
                    Description  = "Sony XPeria Z6",
                    CategoryId   = 1,
                    Price        = 70000,
                    Inventory    = 10,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Indesit",
                    ModellNumber = 10,
                    Description  = "IWSC 51051 C ECO mosógép",
                    CategoryId   = 2,
                    Price        = 56000,
                    Inventory    = 11,
                    Available    = true,
                },
                new Product
                {
                    Producer     = "Indesit",
                    ModellNumber = 11,
                    Description  = "IWSC 10000 C ECO mosógép",
                    CategoryId   = 2,
                    Price        = 45000,
                    Inventory    = 12,
                    Available    = true,
                }
            };

            foreach (Product p in products)
            {
                context.Products.Add(p);
            }

            context.SaveChanges();
        }
Exemplo n.º 7
0
 public void Put(WebStoreContext db, User user)
 {
     db.Update(user);
     db.SaveChanges();
 }
Exemplo n.º 8
0
 public void Create(Model item)
 {
     _context.Models.Add(item);
     _context.SaveChanges();
 }
Exemplo n.º 9
0
        public static void Initialize(WebStoreContext context)
        {
            context.Database.EnsureCreated();
            // Look for any products.
            if (context.Sections.Any())
            {
                return;
            }

            var sections = new List <Section>()
            {
                new Section()
                {
                    Id       = 1,
                    Name     = "firs",
                    Order    = 0,
                    ParentId = null
                },
                new Section()
                {
                    Id       = 2,
                    Name     = "two",
                    Order    = 1,
                    ParentId = 1
                },
                new Section()
                {
                    Id       = 3,
                    Name     = "three",
                    Order    = 0,
                    ParentId = 1
                },
                new Section()
                {
                    Id       = 4,
                    Name     = "first, parent 2",
                    Order    = 0,
                    ParentId = null
                },
                new Section()
                {
                    Id       = 5,
                    Name     = "first",
                    Order    = 1,
                    ParentId = 4
                },
                new Section()
                {
                    Id       = 7,
                    Name     = "test",
                    Order    = 2,
                    ParentId = 4
                }
            };

            using (var trans = context.Database.BeginTransaction())
            {
                foreach (var section in sections)
                {
                    context.Sections.Add(section);
                }
                context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Sections] ON");
                context.SaveChanges();
                context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Sections] OFF");
                trans.Commit();
            }
            var brands = new List <Brand>();

            using (var trans = context.Database.BeginTransaction())
            {
                foreach (var brand in brands)
                {
                    context.Brand.Add(brand);
                }
                context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Brands] ON");
                context.SaveChanges();
                context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Brands] OFF");
                trans.Commit();
            }
        }
Exemplo n.º 10
0
        public void AddNew(Employee employee)
        {
            _context.Employees.Add(employee);

            _context.SaveChanges();
        }
Exemplo n.º 11
0
 public void Create(Modification item)
 {
     _context.Modifications.Add(item);
     _context.SaveChanges();
 }
Exemplo n.º 12
0
 public void Create(Position item)
 {
     db.Positions.Add(item);
     db.SaveChanges();
 }
Exemplo n.º 13
0
        private void InitializeProducts()
        {
            if (_db.Products.Any())
            {
                _Logger.LogInformation("Products initializing not required");
                return;
            }
            _Logger.LogInformation("Sections initializing...");

            var products_sections = TestData.Sections.Join(
                TestData.Products,
                section => section.id,
                product => product.SectionId,
                (section, product) => (section, product));

            foreach (var(section, product) in products_sections)
            {
                section.Products.Add(product);
            }

            var products_brands = TestData.Brands.Join(
                TestData.Products,
                brand => brand.id,
                product => product.BrandId,
                (brand, product) => (brand, product));

            foreach (var(brand, product) in products_brands)
            {
                brand.Products.Add(product);
            }

            var section_section = TestData.Sections.Join(
                TestData.Sections,
                parent => parent.id,
                child => child.ParentId,
                (parent, child) => (parent, child));

            foreach (var(parent, child) in section_section)
            {
                child.Parent = parent;
            }

            foreach (var product in TestData.Products)
            {
                product.id        = 0;
                product.BrandId   = null;
                product.SectionId = 0;
            }

            foreach (var brand in TestData.Brands)
            {
                brand.id = 0;
            }

            foreach (var section in TestData.Sections)
            {
                section.id       = 0;
                section.ParentId = null;
            }

            using (_db.Database.BeginTransaction())
            {
                _db.Products.AddRange(TestData.Products);
                _db.Sections.AddRange(TestData.Sections);
                _db.Brands.AddRange(TestData.Brands);

                _db.SaveChanges();
                _db.Database.CommitTransaction();
            }


            _Logger.LogInformation("Products initialize completed.");
        }
Exemplo n.º 14
0
 public void Create(Mark item)
 {
     _context.Marks.Add(item);
     _context.SaveChanges();
 }
Exemplo n.º 15
0
 public void Delete(WebStoreContext db, User user)
 {
     db.Users.Remove(user);
     db.SaveChanges();
 }
Exemplo n.º 16
0
        public static void Initialize(WebStoreContext context)
        {
            context.Database.EnsureCreated();

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

            var sections = new List <Section>
            {
                new Section()
                {
                    Id       = 1,
                    Name     = "Sportswear",
                    Order    = 0,
                    ParentId = null
                },
                new Section()
                {
                    Id       = 2,
                    Name     = "Nike",
                    Order    = 0,
                    ParentId = 1
                },
                new Section()
                {
                    Id       = 3,
                    Name     = "Under Armour",
                    Order    = 1,
                    ParentId = 1
                },
                new Section()
                {
                    Id       = 4,
                    Name     = "Adidas",
                    Order    = 2,
                    ParentId = 1
                },
                new Section()
                {
                    Id       = 5,
                    Name     = "Puma",
                    Order    = 3,
                    ParentId = 1
                },
                new Section()
                {
                    Id       = 6,
                    Name     = "ASICS",
                    Order    = 4,
                    ParentId = 1
                },
                new Section()
                {
                    Id       = 7,
                    Name     = "Mens",
                    Order    = 1,
                    ParentId = null
                },
                new Section()
                {
                    Id       = 8,
                    Name     = "Fendi",
                    Order    = 0,
                    ParentId = 7
                },
                new Section()
                {
                    Id       = 9,
                    Name     = "Guess",
                    Order    = 1,
                    ParentId = 7
                },
                new Section()
                {
                    Id       = 10,
                    Name     = "Valentino",
                    Order    = 2,
                    ParentId = 7
                },
                new Section()
                {
                    Id       = 11,
                    Name     = "Dior",
                    Order    = 3,
                    ParentId = 7
                },
                new Section()
                {
                    Id       = 12,
                    Name     = "Versace",
                    Order    = 4,
                    ParentId = 7
                },
                new Section()
                {
                    Id       = 13,
                    Name     = "Armani",
                    Order    = 5,
                    ParentId = 7
                },
                new Section()
                {
                    Id       = 14,
                    Name     = "Prada",
                    Order    = 6,
                    ParentId = 7
                },
                new Section()
                {
                    Id       = 15,
                    Name     = "Dolce and Gabbana",
                    Order    = 7,
                    ParentId = 7
                },
                new Section()
                {
                    Id       = 16,
                    Name     = "Chanel",
                    Order    = 8,
                    ParentId = 7
                },
                new Section()
                {
                    Id       = 17,
                    Name     = "Gucci",
                    Order    = 1,
                    ParentId = 7
                },
                new Section()
                {
                    Id       = 18,
                    Name     = "Womens",
                    Order    = 2,
                    ParentId = null
                },
                new Section()
                {
                    Id       = 19,
                    Name     = "Fendi",
                    Order    = 0,
                    ParentId = 18
                },
                new Section()
                {
                    Id       = 20,
                    Name     = "Guess",
                    Order    = 1,
                    ParentId = 18
                },
                new Section()
                {
                    Id       = 21,
                    Name     = "Valentino",
                    Order    = 2,
                    ParentId = 18
                },
                new Section()
                {
                    Id       = 22,
                    Name     = "Dior",
                    Order    = 3,
                    ParentId = 18
                },
                new Section()
                {
                    Id       = 23,
                    Name     = "Versace",
                    Order    = 4,
                    ParentId = 18
                },
                new Section()
                {
                    Id       = 24,
                    Name     = "Kids",
                    Order    = 3,
                    ParentId = null
                },
                new Section()
                {
                    Id       = 25,
                    Name     = "Fashion",
                    Order    = 4,
                    ParentId = null
                },
                new Section()
                {
                    Id       = 26,
                    Name     = "Households",
                    Order    = 5,
                    ParentId = null
                },
                new Section()
                {
                    Id       = 27,
                    Name     = "Interiors",
                    Order    = 6,
                    ParentId = null
                },
                new Section()
                {
                    Id       = 28,
                    Name     = "Clothing",
                    Order    = 7,
                    ParentId = null
                },
                new Section()
                {
                    Id       = 29,
                    Name     = "Bags",
                    Order    = 8,
                    ParentId = null
                },
                new Section()
                {
                    Id       = 30,
                    Name     = "Shoes",
                    Order    = 9,
                    ParentId = null
                }
            };

            using (var trans = context.Database.BeginTransaction())
            {
                foreach (var section in sections)
                {
                    context.Sections.Add(section);
                }

                context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Sections] ON");
                context.SaveChanges();
                context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Sections] OFF");
                trans.Commit();
            }

            var brands = new List <Brand>
            {
                new Brand()
                {
                    Id    = 1,
                    Name  = "Acne",
                    Order = 0
                },
                new Brand()
                {
                    Id    = 2,
                    Name  = "Grüne Erde",
                    Order = 1
                },
                new Brand()
                {
                    Id    = 3,
                    Name  = "Albiro",
                    Order = 2
                },
                new Brand()
                {
                    Id    = 4,
                    Name  = "Ronhill",
                    Order = 3
                },
                new Brand()
                {
                    Id    = 5,
                    Name  = "Oddmolly",
                    Order = 4
                },
                new Brand()
                {
                    Id    = 6,
                    Name  = "Boudestijn",
                    Order = 5
                },
                new Brand()
                {
                    Id    = 7,
                    Name  = "Rösch creative culture",
                    Order = 6
                },
            };

            using (var trans = context.Database.BeginTransaction())
            {
                foreach (var brand in brands)
                {
                    context.Brands.Add(brand);
                }

                context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Brands] ON");
                context.SaveChanges();
                context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Brands] OFF");
                trans.Commit();
            }

            var products = new List <Product>
            {
                new Product()
                {
                    Id        = 1,
                    Name      = "Easy Polo Black Edition",
                    Price     = 1025,
                    ImageUrl  = "product1.jpg",
                    Order     = 0,
                    SectionId = 2,
                    BrandId   = 1,
                    Quantity  = 5,
                    Condition = "New"
                },
                new Product()
                {
                    Id        = 2,
                    Name      = "Easy Polo Black Edition",
                    Price     = 1025,
                    ImageUrl  = "product2.jpg",
                    Order     = 1,
                    SectionId = 2,
                    BrandId   = 1,
                    Quantity  = 7,
                    Condition = "New"
                },
                new Product()
                {
                    Id        = 3,
                    Name      = "Easy Polo Black Edition",
                    Price     = 1025,
                    ImageUrl  = "product3.jpg",
                    Order     = 2,
                    SectionId = 2,
                    BrandId   = 1,
                    Quantity  = 10,
                    Condition = "Used"
                },
                new Product()
                {
                    Id        = 4,
                    Name      = "Easy Polo Black Edition",
                    Price     = 1025,
                    ImageUrl  = "product4.jpg",
                    Order     = 3,
                    SectionId = 2,
                    BrandId   = 1,
                    Quantity  = 2,
                    Condition = "New"
                },
                new Product()
                {
                    Id        = 5,
                    Name      = "Easy Polo Black Edition",
                    Price     = 1025,
                    ImageUrl  = "product5.jpg",
                    Order     = 4,
                    SectionId = 2,
                    BrandId   = 2,
                    Quantity  = 4,
                    Condition = "New"
                },
                new Product()
                {
                    Id        = 6,
                    Name      = "Easy Polo Black Edition",
                    Price     = 1025,
                    ImageUrl  = "product6.jpg",
                    Order     = 5,
                    SectionId = 2,
                    BrandId   = 2,
                    Quantity  = 5,
                    Condition = "Used"
                },
                new Product()
                {
                    Id        = 7,
                    Name      = "Easy Polo Black Edition",
                    Price     = 1025,
                    ImageUrl  = "product7.jpg",
                    Order     = 6,
                    SectionId = 2,
                    BrandId   = 2,
                    Quantity  = 2,
                    Condition = "New"
                },
                new Product()
                {
                    Id        = 8,
                    Name      = "Easy Polo Black Edition",
                    Price     = 1025,
                    ImageUrl  = "product8.jpg",
                    Order     = 7,
                    SectionId = 25,
                    BrandId   = 2,
                    Quantity  = 1,
                    Condition = "New"
                },
                new Product()
                {
                    Id        = 9,
                    Name      = "Easy Polo Black Edition",
                    Price     = 1025,
                    ImageUrl  = "product9.jpg",
                    Order     = 8,
                    SectionId = 25,
                    BrandId   = 2,
                    Quantity  = 3,
                    Condition = "New"
                },
                new Product()
                {
                    Id        = 10,
                    Name      = "Easy Polo Black Edition",
                    Price     = 1025,
                    ImageUrl  = "product10.jpg",
                    Order     = 9,
                    SectionId = 25,
                    BrandId   = 3,
                    Quantity  = 15,
                    Condition = "Used"
                },
                new Product()
                {
                    Id        = 11,
                    Name      = "Easy Polo Black Edition",
                    Price     = 1025,
                    ImageUrl  = "product11.jpg",
                    Order     = 10,
                    SectionId = 25,
                    BrandId   = 3,
                    Quantity  = 7,
                    Condition = "Used"
                },
                new Product()
                {
                    Id        = 12,
                    Name      = "Easy Polo Black Edition",
                    Price     = 1025,
                    ImageUrl  = "product12.jpg",
                    Order     = 11,
                    SectionId = 25,
                    BrandId   = 3,
                    Quantity  = 0,
                    Condition = "New"
                },
            };

            using (var trans = context.Database.BeginTransaction())
            {
                foreach (var product in products)
                {
                    context.Products.Add(product);
                }
                context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Products] ON");
                context.SaveChanges();
                context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Products] OFF");
                trans.Commit();
            }

            var employees = new List <Employee>
            {
                new Employee
                {
                    Id         = 1,
                    IsMan      = true,
                    FirstName  = "Иван",
                    SecondName = "Иванов",
                    Patronymic = "Иванович",
                    Age        = 20,
                    SecretName = "Корпоративный герой",
                    Position   = "Продавец"
                },
                new Employee
                {
                    Id         = 2,
                    IsMan      = false,
                    FirstName  = "Наталья",
                    SecondName = "Сидорова",
                    Patronymic = "Владимировна",
                    Age        = 23,
                    SecretName = "Девушка с большой буквы \"С\"",
                    Position   = "Системный администратор"
                },
                new Employee
                {
                    Id         = 3,
                    IsMan      = true,
                    FirstName  = "Семён",
                    SecondName = "Семёнов",
                    Patronymic = "Семёнович",
                    Age        = 40,
                    SecretName = "Любитель перерывов",
                    Position   = "Бухгалтер"
                }
            };

            using (var trans = context.Database.BeginTransaction())
            {
                foreach (var employee in employees)
                {
                    context.Employees.Add(employee);
                }
                context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Employees] ON");
                context.SaveChanges();
                context.Database.ExecuteSqlCommand("SET IDENTITY_INSERT [dbo].[Employees] OFF");
                trans.Commit();
            }
        }
Exemplo n.º 17
0
 public void Post(WebStoreContext db, User user)
 {
     db.Users.Add(user);
     db.SaveChanges();
 }
Exemplo n.º 18
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }
Exemplo n.º 19
0
 public void Create(Role item)
 {
     db.Roles.Add(item);
     db.SaveChanges();
 }
Exemplo n.º 20
0
 public void Create(Order item)
 {
     _context.Orders.Add(item);
     _context.SaveChanges();
 }
Exemplo n.º 21
0
 public void Save()
 {
     db.SaveChanges();
 }
        public static void Initialize(WebStoreContext context)
        {
            context.Database.EnsureCreated();
            if (context.Products.Any())
            {
                return;
            }
            var categories = new List <Category>()
            {
                new Category()
                {
                    Id       = 1,
                    Name     = "Sportswear 2",
                    Order    = 0,
                    ParentId = null
                },
                new Category()
                {
                    Id       = 2,
                    Name     = "Nike",
                    Order    = 1,
                    ParentId = 1
                },
                new Category()
                {
                    Id       = 3,
                    Name     = "Under Armour",
                    Order    = 1,
                    ParentId = 1
                },
                new Category()
                {
                    Id       = 4,
                    Name     = "Adidas",
                    Order    = 2,
                    ParentId = 1
                },
                new Category()
                {
                    Id       = 5,
                    Name     = "Puma",
                    Order    = 3,
                    ParentId = 1
                },
                new Category()
                {
                    Id       = 6,
                    Name     = "ASICS",
                    Order    = 4,
                    ParentId = 1
                },
                new Category()
                {
                    Id       = 7,
                    Name     = "Mens",
                    Order    = 1,
                    ParentId = null
                },
                new Category()
                {
                    Id       = 8,
                    Name     = "Fendi",
                    Order    = 0,
                    ParentId = 7
                },
                new Category()
                {
                    Id       = 9,
                    Name     = "Guess",
                    Order    = 1,
                    ParentId = 7
                },
                new Category()
                {
                    Id       = 10,
                    Name     = "Valentino",
                    Order    = 2,
                    ParentId = 7
                },
                new Category()
                {
                    Id       = 11,
                    Name     = "Dior",
                    Order    = 3,
                    ParentId = 7
                },
                new Category()
                {
                    Id       = 12,
                    Name     = "Versace",
                    Order    = 4,
                    ParentId = 7
                },
                new Category()
                {
                    Id       = 13,
                    Name     = "Armani",
                    Order    = 5,
                    ParentId = 7
                },
                new Category()
                {
                    Id       = 14,
                    Name     = "Prada",
                    Order    = 6,
                    ParentId = 7
                },
                new Category()
                {
                    Id       = 15,
                    Name     = "Dolce and Gabbana",
                    Order    = 7,
                    ParentId = 7
                },
                new Category()
                {
                    Id       = 16,
                    Name     = "Chanel",
                    Order    = 8,
                    ParentId = 7
                },
                new Category()
                {
                    Id       = 17,
                    Name     = "Gucci",
                    Order    = 1,
                    ParentId = 7
                },
                new Category()
                {
                    Id       = 18,
                    Name     = "Womens",
                    Order    = 2,
                    ParentId = null
                },
                new Category()
                {
                    Id       = 19,
                    Name     = "Fendi",
                    Order    = 0,
                    ParentId = 18
                },
                new Category()
                {
                    Id       = 20,
                    Name     = "Guess",
                    Order    = 1,
                    ParentId = 18
                },
                new Category()
                {
                    Id       = 21,
                    Name     = "Valentino",
                    Order    = 2,
                    ParentId = 18
                },
                new Category()
                {
                    Id       = 22,
                    Name     = "Dior",
                    Order    = 3,
                    ParentId = 18
                },
                new Category()
                {
                    Id       = 23,
                    Name     = "Versace",
                    Order    = 4,
                    ParentId = 18
                },
                new Category()
                {
                    Id       = 24,
                    Name     = "Kids",
                    Order    = 3,
                    ParentId = null
                },
                new Category()
                {
                    Id       = 25,
                    Name     = "Fashion",
                    Order    = 4,
                    ParentId = null
                },
                new Category()
                {
                    Id       = 26,
                    Name     = "Households",
                    Order    = 5,
                    ParentId = null
                },
                new Category()
                {
                    Id       = 27,
                    Name     = "Interiors",
                    Order    = 6,
                    ParentId = null
                },
                new Category()
                {
                    Id       = 28,
                    Name     = "Clothing",
                    Order    = 7,
                    ParentId = null
                },
                new Category()
                {
                    Id       = 29,
                    Name     = "Bags",
                    Order    = 8,
                    ParentId = null
                },
                new Category()
                {
                    Id       = 30,
                    Name     = "Shoes",
                    Order    = 9,
                    ParentId = null
                }
            };
            var brands = new List <Brand>()
            {
                new Brand()
                {
                    Id    = 1,
                    Name  = "Acne 5",
                    Order = 0
                },
                new Brand()
                {
                    Id    = 2,
                    Name  = "Grüne Erde",
                    Order = 1
                },
                new Brand()
                {
                    Id    = 3,
                    Name  = "Albiro",
                    Order = 2
                },
                new Brand()
                {
                    Id    = 4,
                    Name  = "Ronhill",
                    Order = 3
                },
                new Brand()
                {
                    Id    = 5,
                    Name  = "Oddmolly",
                    Order = 4
                },
                new Brand()
                {
                    Id    = 6,
                    Name  = "Boudestijn",
                    Order = 5
                },
                new Brand()
                {
                    Id    = 7,
                    Name  = "Rösch creative culture",
                    Order = 6
                },
            };
            var Products = new List <Product>()
            {
                new Product()
                {
                    Id         = 1,
                    Name       = "Easy Polo Black Edition",
                    Price      = 1025,
                    ImageUrl   = "product1.jpg",
                    Order      = 0,
                    CategoryId = 2,
                    BrandId    = 1
                },
                new Product()
                {
                    Id         = 2,
                    Name       = "Easy Polo Black Edition",
                    Price      = 1025,
                    ImageUrl   = "product2.jpg",
                    Order      = 1,
                    CategoryId = 2,
                    BrandId    = 1
                },
                new Product()
                {
                    Id         = 3,
                    Name       = "Easy Polo Black Edition",
                    Price      = 1025,
                    ImageUrl   = "product3.jpg",
                    Order      = 2,
                    CategoryId = 2,
                    BrandId    = 1
                },
                new Product()
                {
                    Id         = 4,
                    Name       = "Easy Polo Black Edition",
                    Price      = 1025,
                    ImageUrl   = "product4.jpg",
                    Order      = 3,
                    CategoryId = 2,
                    BrandId    = 1
                },
                new Product()
                {
                    Id         = 5,
                    Name       = "Easy Polo Black Edition",
                    Price      = 1025,
                    ImageUrl   = "product5.jpg",
                    Order      = 4,
                    CategoryId = 2,
                    BrandId    = 2
                },
                new Product()
                {
                    Id         = 6,
                    Name       = "Easy Polo Black Edition",
                    Price      = 1025,
                    ImageUrl   = "product6.jpg",
                    Order      = 5,
                    CategoryId = 2,
                    BrandId    = 2
                },
                new Product()
                {
                    Id         = 7,
                    Name       = "Easy Polo Black Edition",
                    Price      = 1025,
                    ImageUrl   = "product7.jpg",
                    Order      = 6,
                    CategoryId = 2,
                    BrandId    = 2
                },
                new Product()
                {
                    Id         = 8,
                    Name       = "Easy Polo Black Edition",
                    Price      = 1025,
                    ImageUrl   = "product8.jpg",
                    Order      = 7,
                    CategoryId = 25,
                    BrandId    = 2
                },
                new Product()
                {
                    Id         = 9,
                    Name       = "Easy Polo Black Edition",
                    Price      = 1025,
                    ImageUrl   = "product9.jpg",
                    Order      = 8,
                    CategoryId = 25,
                    BrandId    = 2
                },
                new Product()
                {
                    Id         = 10,
                    Name       = "Easy Polo Black Edition",
                    Price      = 1025,
                    ImageUrl   = "product10.jpg",
                    Order      = 9,
                    CategoryId = 25,
                    BrandId    = 3
                },
                new Product()
                {
                    Id         = 11,
                    Name       = "Easy Polo Black Edition",
                    Price      = 1025,
                    ImageUrl   = "product11.jpg",
                    Order      = 10,
                    CategoryId = 25,
                    BrandId    = 3
                },
                new Product()
                {
                    Id         = 12,
                    Name       = "Easy Polo Black Edition",
                    Price      = 1025,
                    ImageUrl   = "product12.jpg",
                    Order      = 11,
                    CategoryId = 25,
                    BrandId    = 3
                },
            };


            using (var trans = context.Database.BeginTransaction())
            {
                foreach (var section in categories)
                {
                    context.Categorys.Add(section);
                }
                context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Categories] ON");
                context.SaveChanges();
                context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Categories] OFF");
                context.Database.CommitTransaction();
            }


            using (var trans = context.Database.BeginTransaction())
            {
                foreach (var brand in brands)
                {
                    context.Brands.Add(brand);
                }

                context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Brand] ON");
                context.SaveChanges();
                context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Brand] OFF");
                context.Database.CommitTransaction();
            }


            using (var trans = context.Database.BeginTransaction())
            {
                foreach (var product in Products)
                {
                    context.Products.Add(product);
                }
                context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Products] ON");
                context.SaveChanges();
                context.Database.ExecuteSqlRaw("SET IDENTITY_INSERT [dbo].[Products] OFF");
                context.Database.CommitTransaction();
            }
        }
Exemplo n.º 23
0
 public void Put(WebStoreContext db, Product product)
 {
     db.Update(product);
     db.SaveChanges();
 }
Exemplo n.º 24
0
 public void Create(Photo item)
 {
     _context.Photos.Add(item);
     _context.SaveChanges();
 }
Exemplo n.º 25
0
        public OrderDTO CreateOrder(CreateOrderModel OrderDetails, string UserName)
        {
            using (logger.BeginScope($"Попытка добавления заказа для пользователя {UserName}"))
            {
                if (OrderDetails is null || OrderDetails.Order is null)
                {
                    logger.LogError("При попытке добавления заказа обнаружено, что передана пустая ссылка на тип.");
                    throw new ArgumentNullException(nameof(OrderDetails));
                }
                var user = userManager.FindByNameAsync(UserName).Result;
                if (user is null)
                {
                    logger.LogError($"Пользователь с именем {UserName} не найден в системе.");
                    throw new ArgumentException("Пользователь не найден", nameof(UserName));
                }
                if (OrderDetails.OrderItems?.Count > 0)
                {
                    using (var trans = context.Database.BeginTransaction())
                    {
                        Order order = new Order
                        {
                            Address  = OrderDetails.Order.Address,
                            DateTime = DateTime.Now,
                            Phone    = OrderDetails.Order.Phone,
                            User     = user
                        };
                        context.Orders.Add(order);
                        logger.LogInformation($"Добавление заказа: Адрес - {OrderDetails.Order.Address}, телефон - {OrderDetails.Order.Phone}");
                        foreach (var item in OrderDetails.OrderItems)
                        {
                            var product = context.Products.FirstOrDefault(p => p.Id == item.ProductId);
                            if (product is null)
                            {
                                logger.LogError($"Товар заявленный в заказе не найден в БД магазина. (ИД {item.ProductId})");
                                throw new InvalidOperationException("Товар не найден в БД");
                            }
                            var orderItem = new OrderItem
                            {
                                Order      = order,
                                Product    = product,
                                Quantity   = item.Quantity,
                                TotalPrice = item.Quantity * product.Price
                            };
                            context.OrderItems.Add(orderItem);
                            logger.LogInformation($"Добавление продукта с id {product.Id} к заказу.");
                        }
                        if (context.SaveChanges() > 0)
                        {
                            logger.LogInformation($"Заказ с id {order.Id} успешно записан в БД");
                        }
                        else
                        {
                            logger.LogError($"При записи заказа в БД возникли ошибки.");
                        }
                        trans.Commit();

                        return(order.ToDTO());
                    }
                }
                else
                {
                    logger.LogError($"Заказ содержит пустой список товаров.");
                    throw new ArgumentException("OrderItems не содержит элементов", nameof(OrderDetails));
                }
            }
        }