// GET: Categories/Edit/5 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } try { var category = await _context.Categories.FindAsync(id); if (category == null) { return(NotFound()); } var categoryView = _categoryFactory.CreateCategoryViewModel(category); ViewData["ParentCategoryId"] = new SelectList(_context.Categories, "Id", "Name", category.ParentCategoryId); return(View(categoryView)); } catch (Exception ex) { log.Error(ex); ShowOperationMessage(ex.Message); return(RedirectToAction("Index", "Error")); } }
// [Authorize(Roles = "Admin,Manager")] public ActionResult Edit(int id = -1) { try { var category = _categoryRepository.Get(id); if (category == null) { return(NotFound()); } ViewData["ParentCategoryId"] = new SelectList(_context.Categories, "Id", "Name", category.ParentCategoryId); return(View(_categoryFactory.CreateCategoryViewModel(category))); //return View(_categoryFactory.CreateCategoryViewModel(_categoryRepository.Get(id))); } catch (Exception ex) { log.Error(ex); ShowOperationMessage(ex.Message); return(RedirectToAction("Index", "Error")); } }