public ActionResult Edit(CategoryEditVM viewModel, int id) { if (!ModelState.IsValid) { TempData.SetStatusMessage(Constants.Message.Oops, StatusMessageType.Danger); InitialEditVM(viewModel, id); return View(viewModel); } var category = _categoryRepository.GetById(id); if (category == null || category.IsDelete) { return HttpNotFound(); } var result = _categoryRepository.Edit(category, viewModel); if (result.IsSuccess) { TempData.SetStatusMessage(result.Message); return RedirectToAction("Index"); } TempData.SetStatusMessage(result.Message, StatusMessageType.Danger); InitialEditVM(viewModel, id); return View(viewModel); }
private void InitialEditVM(CategoryEditVM viewModel, int id) { viewModel.Categories = _categoryRepository.Get(x => !x.IsDelete && x.IsPublish && x.Id != id).OrderBy(x => x.Title).ToList(); }