/// 新建班级. public long InsertClassById(long courseId, ClassInfo classInfo) { try { Course course = GetCourseByCourseId(courseId); //检查数据是否合法 if (classInfo.ReportPercentage == 0 && classInfo.PresentationPercentage == 0 && classInfo.FivePointPercentage == 0 && classInfo.FourPointPercentage == 0 && classInfo.ThreePointPercentage == 0) { classInfo.ReportPercentage = course.ReportPercentage; classInfo.PresentationPercentage = course.PresentationPercentage; classInfo.FivePointPercentage = course.FivePointPercentage; classInfo.FourPointPercentage = course.FourPointPercentage; classInfo.ThreePointPercentage = course.ThreePointPercentage; } if (classInfo.ReportPercentage < 0 || classInfo.ReportPercentage > 100 || classInfo.PresentationPercentage < 0 || classInfo.PresentationPercentage > 100 || classInfo.ReportPercentage + classInfo.PresentationPercentage != 100 || classInfo.FivePointPercentage < 0 || classInfo.FivePointPercentage > 100 || classInfo.FourPointPercentage < 0 || classInfo.FourPointPercentage > 100 || classInfo.ThreePointPercentage < 0 || classInfo.ThreePointPercentage > 100 || classInfo.FivePointPercentage + classInfo.FourPointPercentage + classInfo.ThreePointPercentage != 100 || classInfo.PresentationPercentage + classInfo.ReportPercentage != 100) { throw new InvalidOperationException(); } classInfo.Course = course; return(_iCourseDao.Save(classInfo)); //返回classid } catch (CourseNotFoundException ec) { throw ec; } }
/// 新建班级. public async Task <long> InsertClassByIdAsync(long courseId, ClassInfo classInfo) { var course = await GetCourseByCourseIdAsync(courseId); //检查数据是否合法 if (classInfo.ReportPercentage < 0 || classInfo.ReportPercentage > 100 || classInfo.PresentationPercentage < 0 || classInfo.PresentationPercentage > 100 || classInfo.ReportPercentage + classInfo.PresentationPercentage != 100 || classInfo.FivePointPercentage < 0 || classInfo.FivePointPercentage > 100 || classInfo.FourPointPercentage < 0 || classInfo.FourPointPercentage > 100 || classInfo.ThreePointPercentage < 0 || classInfo.ThreePointPercentage > 100 || classInfo.FivePointPercentage + classInfo.FourPointPercentage + classInfo.ThreePointPercentage != 100) { throw new InvalidOperationException(); } classInfo.Course = course; return(_iCourseDao.Save(classInfo)); //返回classid }