Пример #1
0
        public async Task<Product> Add(Product product)
        {

            await _context.Products.AddAsync(product);
            await _context.SaveChangesAsync();
            return product;
        }
Пример #2
0
        public async Task <ProductCategory> Add(ProductCategory productCategory)
        {
            await _context.ProductCategories.AddAsync(productCategory);

            await _context.SaveChangesAsync();

            return(productCategory);
        }
Пример #3
0
        public static async Task AddTestData(
            CoreWebApiTestDBContext context,
            UserDbContext userDbContect, UserManager <IdentityUser> userManager)
        {
            if (context.Products.Any())
            {
                // Already has data
                return;
            }


            ProductCategory cat1 = new ProductCategory();

            cat1.ProductCategoryName = "Cell Phones";


            cat1.Products.Add(new Product
            {
                ProductTitle       = "Android Phone V1",
                ProductDescription = "Android Phone V1 Description",
                ProductPrice       = 1000,
                ProductImagePath   = "",
            });
            cat1.Products.Add(new Product
            {
                ProductTitle       = "iPhone Phone V1",
                ProductDescription = "iPhone Phone V1 Description",
                ProductPrice       = 2000,
                ProductImagePath   = "",
            });



            ProductCategory cat2 = new ProductCategory();

            cat2.ProductCategoryName = "Electronics";


            cat2.Products.Add(new Product
            {
                ProductTitle       = "Samsung TV",
                ProductDescription = "Samsung TV Description",
                ProductPrice       = 10000,
                ProductImagePath   = "",
            });
            cat2.Products.Add(new Product
            {
                ProductTitle       = "Sony TV",
                ProductDescription = "Sony TV Description",
                ProductPrice       = 20000,
                ProductImagePath   = "",
            });

            context.ProductCategories.Add(cat1);
            context.ProductCategories.Add(cat2);
            await context.SaveChangesAsync();

            var user = new IdentityUser {
                UserName = "******", Email = "*****@*****.**"
            };
            var result = await userManager.CreateAsync(user, "Test@@123");
        }