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);
        }
Esempio n. 2
0
 private SubProductCategory CreateSubCategory(SubCategoryEditViewModel viewModel)
 {
     return(new SubProductCategory
     {
         Id = viewModel.Id,
         Title = viewModel.Title,
         Category = _categoryRepository.GetById(viewModel.SelectedCategoryId)
     });
 }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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));
        }