public ResultViewModel <SubCategoryEditViewModel> Update(SubCategoryEditViewModel SubCategory) { ResultViewModel <SubCategoryEditViewModel> result = new ResultViewModel <SubCategoryEditViewModel>(); try { if (!ModelState.IsValid) { result.Message = "In Valid Model State"; } else { SubCategoryEditViewModel selectedSubCategory = subCategoryService.Update(SubCategory); result.Successed = true; result.Data = selectedSubCategory; } } catch (Exception ex) { result.Successed = false; result.Message = "Semething Went Wrong"; } return(result); }
private SubProductCategory CreateSubCategory(SubCategoryEditViewModel viewModel) { return(new SubProductCategory { Id = viewModel.Id, Title = viewModel.Title, Category = _categoryRepository.GetById(viewModel.SelectedCategoryId) }); }
public IActionResult Edit(int id) { var viewModel = new SubCategoryEditViewModel(); var subCategoryToEdit = _subCategoryRepository.GetById(id); viewModel.Id = subCategoryToEdit.Id; viewModel.Title = subCategoryToEdit.Title; viewModel.SelectedCategoryId = _categoryRepository.GetBySubCategoryId(id).Id; viewModel.Categories = EditGetCategoryListItems(); return(View(viewModel)); }
public IActionResult Edit(SubCategoryEditViewModel viewModel) { if (ModelState.IsValid) { var updatedSubCategory = CreateSubCategory(viewModel); _subCategoryRepository.Update(updatedSubCategory); return(RedirectToAction("Index")); } var subCategoryToEdit = _subCategoryRepository.GetById(viewModel.Id); viewModel.Id = subCategoryToEdit.Id; viewModel.Title = subCategoryToEdit.Title; viewModel.SelectedCategoryId = _categoryRepository.GetBySubCategoryId(viewModel.Id).Id; viewModel.Categories = EditGetCategoryListItems(); return(View(viewModel)); }