コード例 #1
0
        protected void Seed(WebApiLabContext context)
        {
            var Phones = new Category {
                Name = "Phones"
            };
            var Laptops = new Category {
                Name = "Laptops"
            };
            var Tablets = new Category {
                Name = "Tablets"
            };

            context.Category.Add(Phones);
            context.Category.Add(Laptops);
            context.Category.Add(Tablets);


            context.Product.Add(
                new Product {
                Name = "Xiaomi MI 10", Price = 500, Category = Phones
            });
            context.Product.Add(
                new Product {
                Name = "Samsung S 11", Price = 900, Category = Phones
            });
            context.Product.Add(
                new Product {
                Name = "Iphone 10", Price = 1000, Category = Phones
            });
            context.Product.Add(
                new Product {
                Name = "Galaxy Tab S", Price = 800, Category = Tablets
            });
            context.Product.Add(
                new Product {
                Name = "Ipad 3", Price = 700, Category = Tablets
            });
            context.Product.Add(
                new Product {
                Name = "Asus Rog", Price = 3000, Category = Laptops
            });
            context.Product.Add(
                new Product {
                Name = "Asus Tuf Gaming", Price = 1500, Category = Laptops
            });
            context.Product.Add(
                new Product {
                Name = "Xiaomi Gaming Laptop", Price = 1000, Category = Laptops
            });
            context.Product.Add(
                new Product {
                Name = "Acer Predator", Price = 2000, Category = Laptops
            });
            context.Product.Add(
                new Product {
                Name = "Macbook Pro", Price = 3999, Category = Laptops
            });

            context.SaveChanges();
        }
コード例 #2
0
        public void Setup()
        {
            var options = new DbContextOptionsBuilder <WebApiLabContext>()
                          .UseInMemoryDatabase(databaseName: "Lab2_Orders")
                          .Options;

            context = new WebApiLabContext(options);

            Seed(context);
        }
コード例 #3
0
 public OrdersController(WebApiLabContext context)
 {
     _context = context;
 }
コード例 #4
0
 public CategoriesController(WebApiLabContext context)
 {
     _context = context;
 }
コード例 #5
0
 public ProductsController(WebApiLabContext context)
 {
     _context = context;
 }