public async Task <IActionResult> Create(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.InsertAsync(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)); } }