public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description")] ProductCategory productCategory) { if (id != productCategory.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(productCategory); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductCategoryExists(productCategory.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(productCategory)); }
public async Task <IActionResult> Edit(int id, [Bind("UserId,UserName,UserEmail,UserPassword")] UserEditViewModel user_evm) { if (id != user_evm.UserId) { return(NotFound()); } if (ModelState.IsValid) { try { User user = new User { UserId = user_evm.UserId, UserName = user_evm.UserName, UserEmail = user_evm.UserEmail, UserPassword = user_evm.UserPassword }; _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user_evm.UserId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(user_evm)); }
public IActionResult Edit(int id, [Bind("Id,Name,PCode,Description,PurchasePrice,SellPrice,InStock,Sale,CreatedDate,ProductCategoryID,CategoryCatId,Photo,PhtotPath")] ProductEditViewModel productVM) { if (id != productVM.Id) { return(NotFound()); } if (ModelState.IsValid) { try { if (ModelState.IsValid) { string uniqueFileName = UploadedFile(productVM); Product products = new Product { Id = productVM.Id, Name = productVM.Name, PCode = productVM.PCode, Description = productVM.Description, PurchasePrice = (decimal)productVM.PurchasePrice, SellPrice = productVM.SellPrice, InStock = productVM.InStock, Sale = productVM.Sale, CreatedDate = DateTime.Now, ProductCategoryID = productVM.ProductCategoryID, CategoryCatId = productVM.CategoryCatId }; if (uniqueFileName == null) { products.ImagePath = productVM.PhtotPath; } else if (productVM.PhtotPath != null) { string filePath = Path.Combine(webHostEnvironment.WebRootPath, "images", productVM.PhtotPath); System.IO.File.Delete(filePath); products.ImagePath = uniqueFileName; } else { products.ImagePath = uniqueFileName; } _context.Update(products); _context.SaveChanges(); // return RedirectToAction(nameof(Index)); } } catch (DbUpdateConcurrencyException) { if (!ProductExists(productVM.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ProductCategoryID"] = new SelectList(_context.ProductCategory, "Id", "Name", productVM.ProductCategoryID); ViewData["CategoryCatId"] = new SelectList(_context.Category, "CatId", "CatTitle", productVM.CategoryCatId); return(View(productVM)); }