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)); }
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)); }
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()); }