public ActionResult Edit(CourseLevelAddFullViewModel model) { if ((model.AddCourseLevelViewModel.Description != null && OtherFunctions.IsHasJS(model.AddCourseLevelViewModel.Description)) || !ModelState.IsValid || (model.AddCourseLevelViewModel.AutomaticTestId == 0 && model.AddCourseLevelViewModel.ManualTestId == 0)) { var teacher = this.userService.GetTeacherByAppUserId(this.User.Identity.GetUserId()); var autoTest = this.automaticTestService.GetForTeacher(teacher.Id).ToList().ConvertAll(x => new ShowAutomaticTestBaseViewModel { Id = x.Id, Title = x.Title }); var manTest = this.manualTestService.GetForTeacher(teacher.Id).ToList().ConvertAll(x => new ManualTestShowBaseViewModel { Id = x.Id, Title = x.Title }); model.AutomaticTests = autoTest; model.ManualTests = manTest; } if (model.AddCourseLevelViewModel.Description != null && OtherFunctions.IsHasJS(model.AddCourseLevelViewModel.Description)) { ModelState.AddModelError("", Common.FieldDescriptionDanger); return(View(model)); } if (!ModelState.IsValid || (model.AddCourseLevelViewModel.AutomaticTestId == 0 && model.AddCourseLevelViewModel.ManualTestId == 0)) { ModelState.AddModelError("", Common.NoChooseTest); return(View(model)); } var addModel = new CourseLevel { CourseId = model.AddCourseLevelViewModel.CourseId, Name = model.AddCourseLevelViewModel.Name, Id = model.AddCourseLevelViewModel.Id, Description = model.AddCourseLevelViewModel.Description }; if (model.AddCourseLevelViewModel.AutomaticTestId != 0) { addModel.AutomaticTestId = model.AddCourseLevelViewModel.AutomaticTestId; } else if (model.AddCourseLevelViewModel.ManualTestId != 0) { addModel.ManualTestId = model.AddCourseLevelViewModel.ManualTestId; } this.courseLevelService.Update(addModel); return(Redirect("/CourseLevel/Details/" + model.AddCourseLevelViewModel.Id)); }
public ActionResult Edit(int id) { if (BellongToCurrentUSeRLevel(id, this.User.Identity.GetUserId())) { var level = this.courseLevelService.GetById(id); var teacher = this.userService.GetTeacherByAppUserId(this.User.Identity.GetUserId()); var autoTest = this.automaticTestService.GetForTeacher(teacher.Id).ToList().ConvertAll(x => new ShowAutomaticTestBaseViewModel { Id = x.Id, Title = x.Title }); var manTest = this.manualTestService.GetForTeacher(teacher.Id).ToList().ConvertAll(x => new ManualTestShowBaseViewModel { Id = x.Id, Title = x.Title }); var viewModel = new CourseLevelAddFullViewModel { AddCourseLevelViewModel = new AddCourseLevelViewModel { CourseId = level.CourseId, Name = level.Name, Id = level.Id, Description = level.Description }, AutomaticTests = autoTest, ManualTests = manTest }; if (level.AutomaticTestId != null) { viewModel.AddCourseLevelViewModel.AutomaticTestId = level.AutomaticTestId.Value; } if (level.ManualTestId != null) { viewModel.AddCourseLevelViewModel.ManualTestId = level.ManualTestId.Value; } return(View(viewModel)); } return(Redirect("/")); }