Example #1
0
        public async Task <IActionResult> Create([Bind("ProductCategoryId,ProductCategoryName")] ProductCategory productCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(productCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(productCategory));
        }
Example #2
0
        public async Task <IActionResult> Edit(int id, ProductViewModel product)
        {
            if (id != product.ProductId)
            {
                return(NotFound());
            }


            var p = await _context.Products.SingleOrDefaultAsync(m => m.ProductId == id);

            var pt = await _context.ProductTranslations.SingleOrDefaultAsync(m => m.ProductId == id && m.Language == CultureInfo.CurrentUICulture.TwoLetterISOLanguageName);

            p.ProductId           = product.ProductId;
            p.ProductCategoryId   = product.ProductCategoryId;
            p.ProductCategory     = product.ProductCategory;
            p.Price               = product.Price;
            p.PictureURL          = product.PictureURL;
            pt.ProductDescription = product.ProductDescription;
            pt.ProductName        = product.ProductName;


            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(p);
                    _context.Update(pt);


                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.ProductId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }
            ViewData["ProductCategoryId"] = new SelectList(_context.ProductCategories, "ProductCategoryId", "ProductCategoryName", product.ProductCategoryId);
            return(View(product));
        }
Example #3
0
        public IActionResult Delete(int id)
        {
            var product            = _context.Products.SingleOrDefault(m => m.ProductId == id);
            var TranslationProduct = _context.ProductTranslations.SingleOrDefault(m => m.ProductId == id && m.Language == CultureInfo.CurrentUICulture.TwoLetterISOLanguageName);

            _context.Products.Remove(product);
            _context.ProductTranslations.Remove(TranslationProduct);

            _context.SaveChangesAsync();

            return(new NoContentResult());
        }