Пример #1
0
        public async Task DeleteAsync(int id)
        {
            var item = await GetByIdAsync(id);

            _dbContext.Remove(item);
            await _dbContext.SaveChangesAsync();
        }
Пример #2
0
        public async Task <IActionResult> Create(ProductModel model)
        {
            if (!ModelState.IsValid)
            {
                // ViewData["Categories"] = SampleDB.Categories;
                var categories = await _categoryHelper.GetAllAsync();

                ViewData["Categories"] = categories;

                return(View(model));
            }

            // SampleDB.Products.Add(model);
            //await _productHelper.AddAsync(model);

            // with dapper
            await _productHelper.AddWithSPAsync(model);

            //with ef core
            var productModel = new Products {
                CategoryId  = model.CategoryId,
                ProductName = model.ProductName,
                UnitPrice   = model.UnitPrice
            };

            //syntax1
            await _coreLearningContext.AddAsync(productModel);

            //syntax2
            //await _coreLearningContext.Products.AddAsync(productModel);

            await _coreLearningContext.SaveChangesAsync();


            return(RedirectToAction("Index"));
        }