Пример #1
0
        public async Task <IActionResult> Edit(SubCategory subCategory)
        {
            if (!ModelState.IsValid)
            {
                SubCategoryAndCategoryViewModel model = new SubCategoryAndCategoryViewModel()
                {
                    CategoryList    = await _categoryService.FindAllAsync(),
                    SubCategory     = subCategory,
                    SubCategoryList = await _subCategoryService.FindAllNameSCAsync(),
                    StatusMessage   = "",
                };
                return(View(model));
            }

            await _subCategoryService.UpdateAsync(subCategory);

            if (!_subCategoryService.StatusMessage.Contains("Error"))
            {
                Message = _subCategoryService.StatusMessage;
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                SubCategoryAndCategoryViewModel model = new SubCategoryAndCategoryViewModel()
                {
                    CategoryList    = await _categoryService.FindAllAsync(),
                    SubCategory     = subCategory,
                    SubCategoryList = await _subCategoryService.FindAllNameSCAsync(),
                    StatusMessage   = _subCategoryService.StatusMessage,
                };
                return(View(model));
            }
        }