public async Task <IActionResult> Edit(CategoryAdministrationEditInputModel input) { if (!this.ModelState.IsValid) { var category = this.categoriesService.GetById <CategoryEditInputModel>(input.Id); var forums = this.forumsService.GetAllMissingByCategoryId <ForumEditViewModel>(input.Id).ToArray(); input.Category = category; input.Forums = forums; return(this.View(input)); } var categoryId = await this.categoriesService.EditAsync( input.Id, input.Category.Name, input.Category.Description, input.ForumIds, input.AreSelected); if (categoryId == null) { return(this.NotFound()); } if (categoryId == 0) { this.ModelState.AddModelError( "Category.Name", string.Format(GlobalConstants.CategoryNameAlreadyExistsErrorMessage, input.Category.Name)); } if (!this.ModelState.IsValid) { var category = this.categoriesService.GetById <CategoryEditInputModel>(input.Id); var forums = this.forumsService.GetAllMissingByCategoryId <ForumEditViewModel>(input.Id).ToArray(); input.Category = category; input.Forums = forums; return(this.View(input)); } this.TempData["InfoMessage"] = "Category edited successfully!"; return(this.RedirectToAction(nameof(this.Index))); }
public IActionResult Edit(int id) { var category = this.categoriesService.GetById <CategoryEditInputModel>(id); if (category == null) { return(this.NotFound()); } var forums = this.forumsService.GetAllMissingByCategoryId <ForumEditViewModel>(id).ToArray(); var viewModel = new CategoryAdministrationEditInputModel { Category = category, Forums = forums, }; return(this.View(viewModel)); }