public IActionResult Edit(GradeEditViewModel gradeEditViewModel) { if (ModelState.IsValid) { var updateGradeResponse = _gradeService.Edit(new UpdateGradeRequest { ID = gradeEditViewModel.GradeView.ID, CourseID = gradeEditViewModel.GradeView.CourseID, GradeNumber = gradeEditViewModel.GradeView.GradeNumber, Value = gradeEditViewModel.GradeView.Value, Note = gradeEditViewModel.GradeView.Note, }); if (updateGradeResponse.IsSuccess == true) { return(View("Index")); } else { ModelState.AddModelError(string.Empty, "Loading Error ;)"); gradeEditViewModel.SelectListItems = PopulateCoursesDropDownList(); return(View("Edit", gradeEditViewModel)); } } else { ModelState.AddModelError(string.Empty, "Invalid Input Error"); gradeEditViewModel.SelectListItems = PopulateCoursesDropDownList(); return(View("Edit", gradeEditViewModel)); } }
public async Task <ActionResult> EditGrade(GradeEditViewModel model) { if (ModelState.IsValid) { var grade = await InstitutionManager.FindGradeByIdAsync(model.Id); if (grade == null) { ModelState.AddModelError("", "未找到此项grade"); return(View(model)); } grade.GradeNum = model.GradeNumber; await InstitutionManager.UpdateGradeAsync(grade); return(RedirectToAction("AllGrade")); } return(View(model)); }