예제 #1
0
        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);
        }
예제 #2
0
 private void InitialEditVM(CategoryEditVM viewModel, int id)
 {
     viewModel.Categories = _categoryRepository.Get(x => !x.IsDelete && x.IsPublish && x.Id != id).OrderBy(x => x.Title).ToList();
 }