public IActionResult EditTest(ManageTestViewModel manageTestViewModel) { if (manageTestViewModel == null || !this.ModelState.IsValid || manageTestViewModel.Questions.Any(q => q.Answers.All(a => !a.IsCorrect))) { manageTestViewModel.CategoryNames = this.categoryService.GetAllCategoriesNames().ToList(); return(this.View(manageTestViewModel)); } var logggedUserId = this.userManager.GetUserId(this.HttpContext.User); var editTestDto = this.mapper.MapTo <ManageTestDto>(manageTestViewModel); editTestDto.CreatedByUserId = logggedUserId; try { this.testService.EditTest(editTestDto); } catch (Exception) { manageTestViewModel.CategoryNames = this.categoryService.GetAllCategoriesNames().ToList(); return(this.View(manageTestViewModel)); } return(RedirectToRoute(new { area = "Admin", controller = "Manage", action = "Index" })); }
public IActionResult CreateTest() { var model = new ManageTestViewModel() { CategoryNames = this.categoryService.GetAllCategoriesNames().ToList() }; return(View(model)); }