public IActionResult EditCourses(int StudentId, List <EditStudentCoursesViewModel> model) { if (StudentId == 0) { return(View("NotFound")); } for (int i = 0; i < model.Count; i++) { if (model[i].IsSelected == true && !(studentCourseRepository.IsRelationExist(StudentId, model[i].CourseId))) { var studentCourseRelation = new StudentCourseRelation { StudentId = StudentId, CourseId = model[i].CourseId }; studentCourseRepository.Add(studentCourseRelation); } else if (model[i].IsSelected == false && studentCourseRepository.IsRelationExist(StudentId, model[i].CourseId)) { studentCourseRepository.Delete(StudentId, model[i].CourseId); } else { continue; } } return(RedirectToAction("Details", new { id = StudentId })); }
public IActionResult EditStudentGrades(int StudentId, List <EditStudentGradesViewModel> model) { if (ModelState.IsValid) { foreach (var item in model) { if (studentCourseRepository.IsRelationExist(StudentId, item.CourseId)) { StudentCourseRelation studentCourse = studentCourseRepository.GetReltionById(StudentId, item.CourseId); studentCourse.GPA = item.CourseGPA; studentCourseRepository.Update(studentCourse); } else { return(View("CourseStudentError")); } } return(RedirectToAction("Details", new { id = StudentId })); } return(View(model)); }
public IActionResult GetChoice(GetChoiceRequest request) { StudentCourseRelation studentCourseRelation = new StudentCourseRelation() { //获取创建时间 CreateTime = DateTime.Now, CourseId = request.CourseId, StudentNo = request.StudentNo }; bool cor = _dbContxt.db.Queryable <StudentCourseRelation>().Where(it => it.CourseId == request.CourseId).Any(); if (cor == false) { return(Failure(ResultCode.COURSE_NAME_EXIST)); } //执行提交课程 var ch = _dbContxt.db.Insertable(studentCourseRelation).ExecuteCommand(); //判断是否成功 return(ch > 0 ? Success() : Failure(ResultCode.DEFEAT)); }