public ActionResult Edit([Bind(Include = "CategoryID,Name")] CategoryView categoryView) { if (ModelState.IsValid) { serviceCategories.UpdateCategory(categoryView.ToCategory()); return(RedirectToAction("Index")); } return(View(categoryView)); }
//public async Task<IActionResult> Edit(int id, [Bind("Id,CategoryId,CategoryName,Description,Picture64")] Categories categories) public async Task<IActionResult> Edit(int categoryId, [FromForm] CategoriesForUpdate category, IFormFile imgFile) { if (categoryId != category.CategoryId) return NotFound(); if (ModelState.IsValid) { try { if (imgFile == null) { category.Picture = TmpPicture .Find(r => r.Id == category.CategoryId.ToString() ) .TmpPicture; } else { var newImgFile = await Utilities.ConvertPictureToBytes(imgFile); category.Picture = newImgFile; } await _serviceCategories.UpdateCategory(category); //TmpPicture = new byte[0]; var TmpPic = TmpPicture .Find(r => r.Id == category.CategoryId.ToString()); TmpPicture.Remove(TmpPic); } catch (DbUpdateConcurrencyException) { if (await CategoryExists(category.CategoryId) == false) return NotFound(); else throw; } //return RedirectToAction(nameof(Index)); return RedirectToAction("Details", new { categoryId = categoryId }); } return View(category); }