/// <summary> /// 用户解绑.学生解绑账号 /// @author dwy /// </summary> /// <param name="userId">用户id</param> /// <returns>true 解绑成功 false 解绑失败</returns> /// <seealso cref="M:Xmu.Crms.Shared.Service.IClassService.DeleteCourseSelectionById(System.Int64,System.Int64)"/> /// <exception cref="T:System.ArgumentException">id格式错误</exception> /// <exception cref="T:Xmu.Crms.Shared.Exceptions.UserNotFoundException">未找到对应用户</exception> public void DeleteStudentAccount(long userId) { if (userId < 0) { throw new ArgumentException("userId格式错误"); } var user = _db.UserInfo.Find(userId) ?? throw new UserNotFoundException(); IList <ClassInfo> courses = _classService.ListClassByUserId(userId); //根据学生ID获取班级列表 IList <SeminarGroup> groups = _seminarGroupService.ListSeminarGroupIdByStudentId(userId); //获取学生的所有讨论课小组 foreach (SeminarGroup s in groups) { if (userId == _seminarGroupService.GetSeminarGroupLeaderByGroupId(s.Id)) //如果是组长 { _seminarGroupService.ResignLeaderById(s.Id, userId); //组长辞职 } _seminarGroupService.DeleteSeminarGroupMemberById(s.Id, userId); //在小组中删除该成员 } foreach (ClassInfo c in courses) { FixGroup fixGroup = _fixGroupService.GetFixedGroupById(userId, c.Id); //找到学生所在的固定小组 _fixGroupService.DeleteFixGroupUserById(fixGroup.Id, userId); //将学生从固定小组中删去 _classService.DeleteCourseSelectionById(userId, c.Id); //学生按班级ID取消选择班级 } _db.RemoveRange(_db.UserInfo.Where(u => u.Id == userId));//删除学生账号 _db.SaveChanges(); }
/* * author:邓帅 * QQ:540043604 */ /// <summary> /// 按courseId删除Seminar. /// 先根据CourseId获得所有的seminar的信息,然后根据seminar信息删除相关topic的记录,然后再根据SeminarId删除SeminarGroup表记录,最后再将seminar的信息删除 /// </summary> /// <param name="courseId">课程Id</param> /// <seealso cref="M:Xmu.Crms.Shared.Service.ISeminarService.ListSeminarByCourseId(System.Int64)"/> /// <seealso cref="M:Xmu.Crms.Shared.Service.ITopicService.DeleteTopicBySeminarId(System.Int64)"/> /// <seealso cref="M:Xmu.Crms.Shared.Service.ISeminarGroupService.DeleteSeminarGroupBySeminarId(System.Int64)"/> /// <exception cref="T:System.ArgumentException">格式错误时抛出</exception> /// <exception cref="T:Xmu.Crms.Shared.Exceptions.CourseNotFoundException">该课程不存在时抛出</exception> public void DeleteSeminarByCourseId(long courseId) { if (courseId < 0) { throw new ArgumentException(); } if (_db.Course.Find(courseId) == null) { throw new CourseNotFoundException(); } var course = _db.Course.Find(courseId); List <Seminar> seminars; seminars = ListSeminarByCourseId(courseId).ToList(); foreach (Seminar seminar in seminars) { _seminarGroupService.DeleteSeminarGroupBySeminarId(seminar.Id); _topicService.DeleteTopicBySeminarId(seminar.Id); } _db.Seminar.RemoveRange(seminars); _db.SaveChanges(); }
/// <summary> /// 按courseId删除课程. /// @author ZhouZhongjun /// </summary> /// <param name="courseId">课程Id</param> /// <seealso cref="M:Xmu.Crms.Shared.Service.ISeminarService.DeleteSeminarByCourseId(System.Int64)"/> /// <seealso cref="M:Xmu.Crms.Shared.Service.IClassService.DeleteClassByCourseId(System.Int64)"/> /// <exception cref="T:System.ArgumentException">courseId格式错误时抛出</exception> /// <exception cref="T:Xmu.Crms.Shared.Exceptions.CourseNotFoundException">未找到课程</exception> public void DeleteCourseByCourseId(long courseId) { if (courseId <= 0) { throw new ArgumentException("格式错误!"); } var course = _db.Course.Where(c => c.Id == courseId).SingleOrDefault(); if (course == null) { throw new CourseNotFoundException(); } //删除course下的所有班级 _classService.DeleteClassByCourseId(courseId); //删除course下的所有Seminar _seminarService.DeleteSeminarByCourseId(courseId); //删除course下的所有课程 _db.Course.Remove(course); _db.SaveChanges(); }
public void DeleteStudentScoreGroupByTopicId(long topicId) { using (var scope = _db.Database.BeginTransaction()) { try { //查找到所有的seminarGroupTopic //查找到所有的studentScoreGroup//.AsNoTracking() List <SeminarGroupTopic> seminarGroupTopicList = _db.SeminarGroupTopic.Include(u => u.Topic).Where(u => u.Topic.Id == topicId).ToList(); if (seminarGroupTopicList == null) { throw new GroupNotFoundException(); } foreach (var seminarGroupTopic in seminarGroupTopicList) { List <StudentScoreGroup> studentScoreGroupList = _db.StudentScoreGroup.Include(u => u.SeminarGroupTopic).Where(u => u.SeminarGroupTopic.Id == seminarGroupTopic.Id).ToList(); foreach (var studentScoreGroup in studentScoreGroupList) { //将实体附加到对象管理器中 _db.StudentScoreGroup.Attach(studentScoreGroup); //删除 _db.StudentScoreGroup.Remove(studentScoreGroup); } } _db.SaveChanges(); } catch { scope.Rollback(); throw; } } }
public void InsertClassAttendanceById(long classId, long seminarId) { if (classId <= 0 || seminarId <= 0) { throw new ArgumentException(); } if (_db.Seminar.Find(seminarId) == null) { throw new SeminarNotFoundException(); } if (_db.ClassInfo.Find(classId) == null) { throw new ClassNotFoundException(); } var students = _db.CourseSelection.Where(c => c.ClassId == classId).ToList(); foreach (var s in students) { Attendance a = new Attendance(); a.ClassInfo = (from i in _db.ClassInfo where i.Id == classId select i).SingleOrDefault(); a.Student = (from j in _db.UserInfo where j.Id == s.StudentId select j).SingleOrDefault(); a.Seminar = (from k in _db.Seminar where k.Id == seminarId select k).SingleOrDefault(); a.AttendanceStatus = AttendanceStatus.Absent; _db.Attendances.Add(a); } _db.SaveChanges(); }
public void UpdateTopicByTopicId(long topicId, Topic topic) { var top = GetTopicByTopicId(topicId); top.Description = topic.Description; top.GroupNumberLimit = topic.GroupNumberLimit; top.GroupStudentLimit = topic.GroupStudentLimit; top.Serial = topic.Serial ?? top.Serial; _db.SaveChanges(); }
public long InsertClassById(long courseId, ClassInfo classInfo) { var c = _db.Course.Find(courseId) ?? throw new CourseNotFoundException(); classInfo.Course = c; var ent = _db.ClassInfo.Add(classInfo); _db.SaveChanges(); return(ent.Entity.Id); }
public void DeleteFixGroupByClassId(long classId) //测试成功 zhh { //1. //if (classId <= 0) //{ // throw new ArgumentException(); //} //var class1 = (from class2 in _db.ClassInfo //判断是否有这个班级 // where class2.Id == classId // select class2).SingleOrDefault(); //if (class1 == null) // throw new ClassNotFoundException(); //var fgm = (from fgmm in _db.FixGroupMember //根据班级删除班级里所有fixgroup的成员 // from fg in _db.FixGroup // where fgmm.FixGroup.Id == fg.Id && fg.ClassInfo.Id == classId // select fgmm).ToList(); //foreach (var i in fgm) //{ // //Console.WriteLine("\n1\n"); // _db.FixGroupMember.Remove(i); //} //var u = (from group1 in _db.FixGroup //删除班级里所有fixgroup // where group1.ClassInfo.Id == classId // select group1).ToList(); //foreach (var i in u) //{ // //Console.WriteLine("\n1\n"); // _db.FixGroup.Remove(i); //} //_db.SaveChanges(); //2. IList <FixGroup> fg = ListFixGroupByClassId(classId); Console.WriteLine("fgleagth:" + fg.Count()); foreach (var i in fg) { DeleteFixGroupMemberByFixGroupId(i.Id); //Console.WriteLine("1"); } var u = (from group1 in _db.FixGroup //删除班级里所有fixgroup where group1.ClassInfo.Id == classId select group1).ToList(); foreach (var i in u) { //Console.WriteLine("\n1\n"); _db.FixGroup.Remove(i); } _db.SaveChanges(); }
/// <summary> /// 按班级id删除班级. /// @author cuiheyu /// </summary> /// <param name="classId">班级ID</param> public void DeleteClassByClassId(long classId) { if (classId < 0) { //classId不合法时抛出异常 throw new ArgumentException("classId格式错误"); } ClassInfo classinfo = _db.ClassInfo.Find(classId); if (classinfo == null) { throw new ClassNotFoundException(); } /* * //级联查找FixGroup实体集 * List<FixGroup> fgList = _db.FixGroup.Include(c => c.ClassInfo).ToList(); * * //根据classinfo找到fixgroup实体 * List<FixGroup> fgListToDelete = fgList.FindAll(c => c.ClassInfo==classinfo); * * //级联查找courseSelection表中的记录 * List<CourseSelection> csList = _db.CourseSelection.Include(c => c.ClassInfo).ToList(); * * //根据classinfo找到courseselection实体 * List<CourseSelection> csListToDelete = csList.FindAll(c => csListToDelete.Contains(c.ClassInfo)); */ _db.ClassInfo.RemoveRange(_db.ClassInfo.Where(c => c.Id == classId)); _db.CourseSelection.Remove(_db.CourseSelection.SingleOrDefault(c => c.ClassInfo.Id == classId)); _db.FixGroup.RemoveRange(_db.FixGroup.Where(f => f.ClassInfo.Id == classId)); _db.SaveChanges(); }
//插入attendance记录 public void AddAttendance(Attendance attendance) { using (var scope = _db.Database.BeginTransaction()) { try { _db.Attendences.Add(attendance); _db.SaveChanges(); } catch (System.Exception e) { scope.Rollback(); throw e; } } }
/// <summary> /// 按courseId删除Seminar. /// @author zhouzhongjun /// </summary> /// /// 先根据CourseId获得所有的seminar的信息,然后根据seminar信息删除相关topic的记录,然后再根据SeminarId删除SeminarGroup表记录,最后再将seminar的信息删除 /// /// <param name="courseId">课程Id</param> /// <returns>true删除成功 false删除失败</returns> /// <seealso cref="M:Xmu.Crms.Shared.Service.ISeminarService.ListSeminarByCourseId(System.Int64)"/> /// <seealso cref="M:Xmu.Crms.Shared.Service.ITopicService.DeleteTopicBySeminarId(System.Int64)"/> /// <seealso cref="M:Xmu.Crms.Shared.Service.ISeminarGroupService.DeleteSeminarGroupBySeminarId(System.Int64)"/> /// <exception cref="ArgumentException">格式错误时抛出</exception> /// <exception cref="CourseNotFoundException">该课程不存在时抛出</exception> public void DeleteSeminarByCourseId(long courseId) { if (courseId < 0) { throw new ArgumentException(); } var course = _db.Course.Where(u => u.Id == courseId).SingleOrDefault() ?? throw new CourseNotFoundException(); var seminars = _db.Seminar.Where(_seminar => _seminar.Course.Id == courseId).ToList(); for (int i = 0; i < seminars.Count; i++) { DeleteSeminarBySeminarId(seminars[i].Id); } _db.SaveChanges(); }
//按topicId删除SeminarGroupTopic表信息. public void DeleteSeminarGroupTopicByTopicId(long topicId) { using (var scope = _db.Database.BeginTransaction()) { try { IList <SeminarGroupTopic> list = _db.SeminarGroupTopic.Where(s => s.Topic.Id == topicId).ToList <SeminarGroupTopic>(); if (list == null) { throw new TopicNotFoundException(); } foreach (var l in list) { List <StudentScoreGroup> list2 = _db.StudentScoreGroup.Include(s => s.SeminarGroupTopic).Where(t => t.SeminarGroupTopic.Id == l.Id).ToList <StudentScoreGroup>(); foreach (var l2 in list2) { _db.StudentScoreGroup.Remove(l2); } _db.SeminarGroupTopic.Remove(l); _db.SaveChanges(); } scope.Commit(); } catch (System.Exception re) { scope.Rollback(); throw re; } } }
/// <summary> /// 用户解绑.学生解绑账号 /// @author dwy /// </summary> /// <param name="userId">用户id</param> /// <returns>true 解绑成功 false 解绑失败</returns> /// <seealso cref="M:Xmu.Crms.Shared.Service.IClassService.DeleteCourseSelectionById(System.Int64,System.Int64)"/> /// <exception cref="T:System.ArgumentException">id格式错误</exception> /// <exception cref="T:Xmu.Crms.Shared.Exceptions.UserNotFoundException">未找到对应用户</exception> public void DeleteStudentAccount(long userId) { if (userId < 0) { throw new ArgumentException("userId格式错误"); } var user = _db.UserInfo.Find(userId) ?? throw new UserNotFoundException(); IList <ClassInfo> courses = _classService.ListClassByUserId(userId);//根据学生ID获取班级列表 foreach (ClassInfo c in courses) { FixGroup fixGroup = _fixGroupService.GetFixedGroupById(userId, c.Id); //找到学生所在的固定小组 _fixGroupService.DeleteFixGroupUserById(fixGroup.Id, userId); //将学生从固定小组中删去 _classService.DeleteCourseSelectionById(userId, c.Id); //学生按班级ID取消选择班级 } _db.RemoveRange(_db.UserInfo.Where(u => u.Id == userId)); //删除学生账号 _db.SaveChanges(); }
/// <summary> /// 添加学校. /// @author LiuAiqi /// </summary> /// <param name="school">学校的信息</param> /// <returns>schoolId 学校的id</returns> public long InsertSchool(School school) { if (school == null) { throw new NotImplementedException(); } _db.School.Add(school); _db.SaveChanges(); return(school.Id); }
//昶辉 public void InsertAttendanceById(long classId, long seminarId, long userId, double longitude, double latitude) { Attendance att = new Attendance(); var attendanceLocation = _db.Location.Where(p => p.Seminar.Id == seminarId).SingleOrDefault(); var user = _db.UserInfo.Where(p => p.Id == userId).SingleOrDefault(); var class1 = _db.ClassInfo.Where(p => p.Id == classId).SingleOrDefault(); var seminar = _db.Seminar.Where(p => p.Id == seminarId).SingleOrDefault(); if (classId < 0 || seminarId < 0 || userId < 0) { if (classId < 0) { throw new System.ArgumentException("Parameter format error", "classId"); } else if (seminarId < 0) { throw new System.ArgumentException("Parameter format error", "seminarId"); } else { throw new System.ArgumentException("Parameter format error", "userId"); } } if (attendanceLocation.Longitude == longitude && attendanceLocation.Latitude == latitude) { if (class1 == null) { throw new ClassNotFoundException(); } if (seminar == null) { throw new SeminarNotFoundException(); } att.Student = user; att.ClassInfo = class1; att.Seminar = seminar; } _db.Attendences.Add(att); _db.SaveChanges(); }
public void DeleteCourseByCourseId(long courseId) { try { Course course = _db.Course.Where(c => c.Id == courseId).SingleOrDefault(); if (course == null) { throw new CourseNotFoundException(); } //将实体附加到对象管理器中 _db.Course.Attach(course); //删除 _db.Course.Remove(course); _db.SaveChanges(); } catch { throw; } }
/// <summary> /// 按courseId删除Seminar. /// @author zhouzhongjun /// </summary> /// /// 先根据CourseId获得所有的seminar的信息,然后根据seminar信息删除相关topic的记录,然后再根据SeminarId删除SeminarGroup表记录,最后再将seminar的信息删除 /// /// <param name="courseId">课程Id</param> /// <returns>true删除成功 false删除失败</returns> /// <seealso cref="M:Xmu.Crms.Shared.Service.ISeminarService.ListSeminarByCourseId(System.Int64)"/> /// <seealso cref="M:Xmu.Crms.Shared.Service.ITopicService.DeleteTopicBySeminarId(System.Int64)"/> /// <seealso cref="M:Xmu.Crms.Shared.Service.ISeminarGroupService.DeleteSeminarGroupBySeminarId(System.Int64)"/> /// <exception cref="ArgumentException">格式错误时抛出</exception> /// <exception cref="CourseNotFoundException">该课程不存在时抛出</exception> public void DeleteSeminarByCourseId(long courseId) { if (courseId < 0) { throw new ArgumentException(); } var seminars = _db.Seminar.Where(_seminar => _seminar.Course.Id == courseId).ToList(); if (seminars == null) { throw new SeminarNotFoundException(); } for (int i = 0; i <= seminars.Count; i++) { _db.Seminar.Remove(seminars[i]); } _db.SaveChanges(); }
/// <summary> /// 手机号注册. /// @author Group HighGrade /// 手机号注册 User中只有phone和password,userId是注册后才有并且在数据库自增 /// </summary> /// <param name="user">用户信息(手机号Phone和密码Password)</param> /// <returns>user 该用户信息</returns> public UserInfo SignUpPhone(UserInfo user) { // MD5 md5 = new MD5CryptoServiceProvider(); //byte[] byteArray1= System.Text.Encoding.Default.GetBytes(user.Password); var u = new UserInfo { Phone = user.Phone, Password = GetMd5(user.Password), }; //Password= md5.ComputeHash(user.Password) _db.UserInfo.Add(u); _db.SaveChanges(); return(u); }
///<summary> ///上传用户头像名单 ///上传用户头像 ///</summary> ///<param name="userId">用户ID</param> ///<param name="pathName">文件路径</param> public void UploadAvater(long userId, string pathName) { var user = _db.UserInfo.SingleOrDefault(u => u.Id == userId); if (user == null) { throw new UserNotFoundException(); } user.Avatar = pathName ?? throw new ArgumentException(); _db.SaveChanges(); }
public void UpdateTopicByTopicId(long topicId, Topic topic) { if (topicId < 0) { throw new System.ArgumentException("Parameter format error", "topicId"); } else { var t = _db.Topic.Where(p => p.Id == topicId).SingleOrDefault(); if (t == null) { throw new TopicNotFoundException(); } else { t.Id = topic.Id; t.Name = topic.Name; t.Description = topic.Description; t.GroupNumberLimit = topic.GroupNumberLimit; t.GroupStudentLimit = topic.GroupStudentLimit; t.Seminar = topic.Seminar; } } _db.SaveChanges(); }
/* * author:汪亚东 * QQ:994094745 */ /// <summary> /// 按topicId删除SeminarGroupTopic表信息. /// </summary> /// <param name="topicId">讨论课Id</param> /// <exception cref="T:System.ArgumentException">topicId格式错误</exception> /// /// <exception cref="T:TopicNotFoundException">topic不存在</exception> public void DeleteSeminarGroupTopicByTopicId(long topicId) { if (topicId <= 0) { throw new ArgumentException("topicId格式错误"); //topicId不合法时抛出异常 } Topic topic = _db.Topic.Find(topicId); //根据topicId找到topic实体 if (topic == null) { throw new TopicNotFoundException(); //找不到topic时抛出 } //将两表连接起来查询 List <SeminarGroupTopic> sgtList = _db.SeminarGroupTopic.Include(x => x.Topic).ToList(); //根据topic实体找到SeminarGroupTopic实体集 List <SeminarGroupTopic> sgtListToDelete = sgtList.FindAll(x => x.Topic == topic); //级联查找student_score_group表中的记录 List <StudentScoreGroup> ssgList = _db.StudentScoreGroup .Include(x => x.SeminarGroupTopic) .ToList(); List <StudentScoreGroup> ssgListToDelete = ssgList.FindAll(x => sgtListToDelete.Contains(x.SeminarGroupTopic)); _db.StudentScoreGroup.RemoveRange(ssgListToDelete); //级联删除student_score_group表中的记录 _db.SeminarGroupTopic.RemoveRange(sgtListToDelete); //删除找到的SeminarGroupTopic实体集 _db.SaveChanges(); //提交事务 }
public IActionResult UploadReport([FromQuery] long seminarId) { // 先存入服务端的wwwroot下的report文件夹 var files = Request.Form.Files; string fileUrl = null; foreach (var file in files) { var filename = ContentDispositionHeaderValue .Parse(file.ContentDisposition) .Name .Trim('"'); //filename = hostingEnv.WebRootPath + $@"\report\{filename}"; fileUrl = Path.Combine(_hostingEnv.WebRootPath + "/report/" + filename); using (FileStream fs = System.IO.File.Create(fileUrl)) { file.CopyTo(fs); fs.Flush(); } } // 插入当前用户所在的SeminarGroup表中的Report属性 try { // 先查SeminarGroup SeminarGroup seminarGroup = _iSeminarGroupService.GetSeminarGroupById(seminarId, User.Id()); // 改SeminarGroup表中的Report属性 _db.SeminarGroup.Attach(seminarGroup); seminarGroup.Report = fileUrl; _db.SaveChanges(); } catch (GroupNotFoundException) { return(NotFound()); } return(Created(fileUrl, files)); }
//插入学校 public long AddSchool(School school) { using (var scope = _db.Database.BeginTransaction()) { try { _db.School.Add(school); _db.SaveChanges(); return(school.Id); } catch (System.Exception e) { scope.Rollback(); throw e; } } }
public long InsertSchool(School school) { var s = new School { Id = school.Id, Name = school.Name, Province = school.Province, City = school.City }; var sch = _db.School.Where(sc => sc.Name == s.Name).ToList(); if (sch == null) { throw new Exception(); } _db.School.Add(s); _db.SaveChanges(); return(s.Id); }
public IActionResult InsertMemberByStudentId([FromRoute] long groupId, [FromRoute] long studentId) { try { //将学生加入讨论课小组 _seminarGroupService.InsertSeminarGroupMemberById(studentId, groupId); var group = _seminarGroupService.GetSeminarGroupByGroupId(groupId); var attendance = _db.Attendances.SingleOrDefault(s => (s.SeminarId == group.SeminarId && s.ClassId == group.ClassId && s.StudentId == studentId)); attendance.AttendanceStatus = AttendanceStatus.Present; _db.SaveChanges(); return(NoContent()); } catch (GroupNotFoundException) { return(StatusCode(404, new { msg = "该小组不存在" })); } catch (ArgumentException) { return(StatusCode(400, new { msg = "组号格式错误" })); } }
void DeleteStudentScoreGroupByTopicId(long topicId) { var sem = (from temp in _db.Topic where Id = topicId select seminarId); if (sem = null) { throw new ArgumentException(); } foreach (var i in sem) { var sem1 = (from sem in _db.SeminarGroup where seminarId = sem.seminarId select sem); foreach (var j in sem1) { _db.SeminarGroup.Remove(j); } } _db.SaveChanges(); }
//删除班级和学生选课表 public void Delete(long id) { using (var scope = _db.Database.BeginTransaction()) { try { ClassInfo c = _db.ClassInfo.Where(u => u.Id == id).SingleOrDefault <ClassInfo>(); if (c == null) { throw new ClassNotFoundException(); } //根据class信息删除courseSelection表 DeleteSelection(0, c.Id); _db.ClassInfo.Attach(c); _db.ClassInfo.Remove(c); _db.SaveChanges(); scope.Commit(); } catch (ClassNotFoundException e) { scope.Rollback(); throw e; } } }
/// <summary> /// 按班级id删除班级. /// @author cuiheyu /// </summary> /// <param name="classId">班级ID</param> public void DeleteClassByClassId(long classId)//测试成功 { if (classId < 0) { //classId不合法时抛出异常 throw new ArgumentException("classId格式错误"); } ClassInfo classinfo = _db.ClassInfo.Find(classId); if (classinfo == null) { throw new ClassNotFoundException(); } //删除班级信息表相关信息 _db.ClassInfo.RemoveRange(_db.ClassInfo.Where(c => c.Id == classId)); //删除课程选择表当前classId记录 _db.CourseSelection.RemoveRange(_db.CourseSelection.Where(c => c.ClassInfo.Id == classId)); //删除固定分组表当前classID记录 _db.FixGroup.RemoveRange(_db.FixGroup.Where(f => f.ClassInfo.Id == classId)); _db.SaveChanges(); }
/// <summary> /// 仅作为普通方法,被下面的定时器方法调用. /// 讨论课结束后计算展示得分. /// @author fengjinliu /// 条件: 讨论课已结束 *GradeService /// </summary> /// <param name="seminarId">讨论课id</param> /// <exception cref="T:System.ArgumentException">id格式错误</exception> public void CountPresentationGrade(long seminarId, IList <Topic> topicList) { foreach (var topic in topicList) { //通过seminarGroupId获得List<SeminarGroupTopic> //通过seminarGrouptopicId获得List<StudentScoreGroup> long[] idList; double[] gradeList; //获取选择该topic的所有小组 var seminarGroupTopicList = _db.SeminarGroupTopic.Include(u => u.SeminarGroup).Include(u => u.Topic).Where(u => u.Topic.Id == topic.Id).ToList(); if (seminarGroupTopicList == null) { throw new GroupNotFoundException(); } else { idList = new long[seminarGroupTopicList.Count]; gradeList = new double[seminarGroupTopicList.Count]; int groupNumber = 0; //计算一个小组的所有学生打分情况 foreach (var i in seminarGroupTopicList) { //List<StudentScoreGroup> studentScoreList = new List<StudentScoreGroup>(); //获取学生打分列表 var studentScoreList = _db.StudentScoreGroup.Where(u => u.SeminarGroupTopic.Id == i.Id).ToList(); if (studentScoreList == null)//该组没有被打分 { seminarGroupTopicList.Remove(i); } int?grade = 0; int k = 0; foreach (var g in studentScoreList) { grade += g.Grade; k++; } double avg = (double)grade / k; //将小组该讨论课平均分和Id保存 idList[groupNumber] = i.Id; gradeList[groupNumber] = avg; groupNumber++; } //将小组成绩从大到小排序 QuickSort(idList, gradeList, 0, groupNumber - 1); Seminar seminar; ClassInfo classInfo; try { seminar = _db.Seminar.Include(u => u.Course).Where(u => u.Id == seminarId).SingleOrDefault(); if (seminar == null) { throw new SeminarNotFoundException(); } classInfo = _db.ClassInfo.Where(u => u.Id == seminar.Course.Id).SingleOrDefault(); if (classInfo == null) { throw new ClassNotFoundException(); } } catch { throw; } //各小组按比例给分 int Five = Convert.ToInt32(groupNumber * classInfo.FivePointPercentage * 0.01); int Four = Convert.ToInt32(groupNumber * classInfo.FourPointPercentage * 0.01); int Three = Convert.ToInt32(groupNumber * classInfo.ThreePointPercentage * 0.01); for (int i = 0; i < groupNumber; i++) { SeminarGroupTopic seminarGroupTopic = _db.SeminarGroupTopic.SingleOrDefault(s => s.Id == idList[i]); //如果找不到该组 if (seminarGroupTopic == null) { throw new GroupNotFoundException(); } //更新报告分 if (i >= 0 && i < Five) { seminarGroupTopic.PresentationGrade = 5; } if (i >= Five && i < Four) { seminarGroupTopic.PresentationGrade = 4; } if (i >= Four && i < groupNumber) { seminarGroupTopic.PresentationGrade = 3; } _db.SaveChanges(); } } //if end } //foreach topic end }
/* * author:许驹雄 * QQ:980753915 */ /// <summary> /// 成为组长. /// 同学按小组id和自身id成为组长 /// </summary> /// <param name="groupId">小组id</param> /// <param name="userId">学生id</param> /// <exception cref="T:System.ArgumentException">id格式错误</exception> /// <exception cref="T:Xmu.Crms.Shared.Exceptions.UserNotFoundException">不存在该学生</exception> /// <exception cref="T:Xmu.Crms.Shared.Exceptions.GroupNotFoundException">未找到小组</exception> /// <exception cref="T:System.InvalidOperationException">已经有组长了</exception> public void AssignLeaderById(long groupId, long userId) { UserInfo _user; SeminarGroup _group; //id格式异常 if (groupId <= 0 || userId <= 0) { throw new System.ArgumentException("id格式错误"); } //找到user if ((_user = _db.UserInfo.Find(userId)) == null) { throw new UserNotFoundException(); } //找到group并连接user _group = _db.SeminarGroup.Include(sg => sg.Leader).Single(sg => sg.Id == groupId); if (_group == null) { throw new GroupNotFoundException(); } //已经有组长,抛出异常 if (_group.Leader != null) { throw new System.InvalidOperationException("已经有组长了"); } //设置组长 _group.Leader = _user; //保存更改 _db.SaveChanges(); }