public IActionResult GetMySeminarGroup(long seminarId)
        {
            // Authentication
            // 老师无法使用此API,返回403
            if (User.Type() == Shared.Models.Type.Teacher)
            {
                return(StatusCode(403, new { msg = "老师无法获得自己的小组信息!" }));
            }

            try
            {
                // Fetch data from database
                SeminarGroup seminarGroup = _iSeminarGroupService.GetSeminarGroupById(seminarId, User.Id());

                // 转换成VO对象
                GroupVO myGroup = seminarGroup;

                //获取Members
                IList <UserInfo> memberList = _iSeminarGroupService.ListSeminarGroupMemberByGroupId(seminarGroup.Id);
                List <UserVO>    members    = new List <UserVO>();
                foreach (UserInfo u in memberList)
                {
                    members.Add(u);
                }
                myGroup.Members = members;

                //获取Topics和PresentationGrade
                IList <SeminarGroupTopic> seminarGroupTopicList = _iTopicService.ListSeminarGroupTopicByGroupId(seminarGroup.Id);
                List <TopicVO>            topics = new List <TopicVO>();
                List <int> pGrades = new List <int>();
                foreach (SeminarGroupTopic sgt in seminarGroupTopicList)
                {
                    topics.Add(sgt.Topic);
                    pGrades.Add((int)sgt.PresentationGrade);
                }
                myGroup.Topics = topics;
                myGroup.Grade.PresentationGrade = pGrades;

                //获取Name
                myGroup.GetName();

                // Success
                return(Json(myGroup));
            }
            //If seminar not found, 返回404
            catch (SeminarNotFoundException)
            {
                return(NotFound(new { msg = "未找到该讨论课!" }));
            }
            //If group not found, 返回404
            catch (GroupNotFoundException)
            {
                return(NotFound(new { msg = "讨论课尚未分组!" }));
            }
            //seminarId 格式错误,返回400
            catch (ArgumentException)
            {
                return(BadRequest(new { msg = "错误的ID格式!" }));
            }
        }
示例#2
0
        public IActionResult GetGradeByCourseId([FromRoute] long courseId)
        {
            Grade gg = new Grade();

            try
            {
                IList <Seminar> ils = _seminarservice.ListSeminarByCourseId(courseId);
                foreach (var i in ils)
                {
                    SeminarGroup sm = _seminargroupservice.GetSeminarGroupById(i.Id, User.Id());//这里这里
                    gg.grade       = sm.FinalGrade;
                    gg.name        = i.Name;
                    gg.description = i.Description;
                    break;
                }
                return(Json(gg));
            }
            catch (GroupNotFoundException)
            {
                return(StatusCode(404, new { msg = "学生不属于任何组啊" }));
            }
            catch (SeminarNotFoundException)
            {
                return(StatusCode(404, new { msg = "该courseId下无任何讨论课" }));
            }
            catch (ArgumentException)
            {
                return(StatusCode(400, new { msg = "格式错误!" }));
            }
        }
        /// <summary>
        /// 按课程id获取学生该课程所有讨论课
        /// @author Group ViceVersa
        /// 通过课程id获取该课程下学生所有讨论课详细信息(包括成绩)
        /// </summary>
        /// <param name="userId">学生id</param>
        /// <param name="courseId">课程id</param>
        /// <returns>list 该课程下所有讨论课列表</returns>
        /// <exception cref="T:System.ArgumentException">id格式错误</exception>
        /// <seealso cref="M:Xmu.Crms.Shared.Service.ISeminarService.ListSeminarByCourseId(System.Int64)"/>
        /// <seealso cref="M:Xmu.Crms.Shared.Service.ISeminarGroupService.ListSeminarGroupBySeminarId(System.Int64)"/>
        public IList <SeminarGroup> ListSeminarGradeByCourseId(long userId, long courseId)
        {
            List <SeminarGroup> seminarGroupList = new List <SeminarGroup>();

            try
            {
                //调用SeminarService 中 IList<Seminar> ListSeminarByCourseId(long courseId)方法
                IList <Seminar> seminarList = _iSeminarService.ListSeminarByCourseId(courseId);

                //调用SeminarGroupService 中 SeminarGroup GetSeminarGroupById(long seminarId, long userId)
                for (int i = 0; i < seminarList.Count; i++)
                {
                    SeminarGroup seminarGroup = _iSeminarGroupService.GetSeminarGroupById(seminarList[i].Id, userId);
                    if (seminarGroup != null)
                    {
                        seminarGroupList.Add(seminarGroup);
                    }
                }
            }
            catch (CourseNotFoundException cre)
            {
                throw cre;
            }
            catch (Exception e)
            {
                throw e;
            }
            return(seminarGroupList);
        }
        /***************************我是萌萌哒的分界线*******************************************/

        /*
         * author:孙仲玄
         * QQ:1731744887
         */

        /// <summary>
        /// 创建讨论课小组.
        /// </summary>
        /// <param name="seminarId">讨论课的id</param>
        /// <param name="seminarGroup">小组信息</param>
        /// <returns>long 返回该小组的id</returns>
        /// <seealso cref="M:Xmu.Crms.Shared.Service.ISeminarGroupService.InsertSeminarGroupMemberById(System.Int64,System.Int64)"/>
        /// <exception cref="T:System.ArgumentException">id格式错误</exception>
        public long InsertSeminarGroupBySeminarId(long seminarId, long classId, SeminarGroup seminarGroup)
        {
            //id <= 0
            if (seminarId <= 0 || classId <= 0)
            {
                throw new ArgumentException("id格式错误");
            }
            Seminar seminar = _db.Seminar.Find(seminarId);

            if (seminar == null)
            {
                throw new SeminarNotFoundException();
            }
            ClassInfo classInfo = _db.ClassInfo.Find(classId);

            if (classInfo == null)
            {
                throw new ClassNotFoundException();
            }

            seminarGroup.Seminar   = seminar;
            seminarGroup.ClassInfo = classInfo;
            _db.SeminarGroup.Add(seminarGroup);
            _db.SaveChanges();

            return(seminarGroup.Id

                   );
        }
        //@author cuisy

        //<summary>按讨论课小组id获取讨论课小组</summary>
        //<param name="userId">讨论课小组Id</param>
        //<param name="seminarGroupId">讨论课小组Id</param>
        //<returns>SeminarGroup 讨论课小组信息</returns>
        //<exception cref="T:System.ArgumentException">SeminarId格式错误</exception>
        //<exception cref="T:System.ArgumentException">UserId格式错误</exception>
        public SeminarGroup GetSeminarGroupBySeminarGroupId(long seminarGroupId)
        {
            if (seminarGroupId <= 0)
            {
                throw new ArgumentException(nameof(seminarGroupId));
            }

            SeminarGroup group = _db.SeminarGroup.SingleOrDefault(c => c.Id == seminarGroupId)
                                 ?? throw new InvalidOperationException();

            return(group);
        }
        /// <summary>
        /// 按ID设置小组报告分.
        /// </summary>
        /// <param name="seminarGroupId">讨论课组id</param>
        /// <param name="grade">分数</param>
        public void UpdateGroupByGroupId(long seminarGroupId, int grade)
        {
            if (seminarGroupId <= 0)
            {
                throw new ArgumentException(nameof(seminarGroupId));
            }

            SeminarGroup smg = _db.SeminarGroup.Find(seminarGroupId);

            smg.ReportGrade = grade;

            _db.SaveChanges();
        }
示例#7
0
        public IActionResult GetGroupSeminarGrade(long groupId)
        {
            try
            {
                SeminarGroup seminarGroup = _iSeminarGroupService.GetSeminarGroupByGroupId(groupId);
                // 转换成VO对象
                GroupVO myGroup = seminarGroup;

                //获取Members
                IList <UserInfo> memberList = _iSeminarGroupService.ListSeminarGroupMemberByGroupId(seminarGroup.Id);
                List <UserVO>    members    = new List <UserVO>();
                foreach (UserInfo u in memberList)
                {
                    members.Add(u);
                }
                myGroup.Members = members;

                //获取Topics和PresentationGrade
                IList <SeminarGroupTopic> seminarGroupTopicList = _iTopicService.ListSeminarGroupTopicByGroupId(seminarGroup.Id);
                List <TopicVO>            topics = new List <TopicVO>();
                List <int> pGrades = new List <int>();
                foreach (SeminarGroupTopic sgt in seminarGroupTopicList)
                {
                    topics.Add(sgt.Topic);
                    pGrades.Add((int)sgt.PresentationGrade);
                }
                myGroup.Topics = topics;
                myGroup.Grade.PresentationGrade = pGrades;

                //获取Name
                myGroup.GetName();

                // Success
                return(Json(myGroup));
            }
            catch (SeminarNotFoundException)
            {
                return(NotFound());
            }
            catch (GroupNotFoundException)
            {
                return(NotFound());
            }
            catch (ArgumentException)
            {
                return(BadRequest());
            }
        }
示例#8
0
 public SeminarGroup GetSeminarGroupBySeminarGroupId(long seminarGroupId)
 {
     try
     {
         SeminarGroup group = _db.SeminarGroup.SingleOrDefault(c => c.Id == seminarGroupId);
         if (group == null)
         {
             throw new GroupNotFoundException();
         }
         return(group);
     }
     catch
     {
         throw;
     }
 }
        /// <summary>
        /// 创建小组成员信息.
        /// 将小组成员加入某一小组
        /// </summary>
        /// <param name="groupId">小组的id</param>
        /// <param name="seminarGroupMember">小组成员信息</param>
        /// <returns>long 返回该小组成员表的id</returns>
        public long InsertSeminarGroupMemberByGroupId(long groupId, SeminarGroupMember seminarGroupMember)
        {
            if (groupId <= 0)
            {
                throw new ArgumentException("groupId格式错误");
            }
            SeminarGroup sg = _db.SeminarGroup.Find(groupId);

            if (sg == null)
            {
                throw new GroupNotFoundException();
            }

            seminarGroupMember.SeminarGroup = sg;
            _db.SeminarGroupMember.Add(seminarGroupMember);
            _db.SaveChanges();

            return(seminarGroupMember.Id);
        }
示例#10
0
        /// <summary>
        /// 小组取消选择话题.
        /// 删除seminar_group_topic表的记录
        /// </summary>
        /// <param name="groupId">小组Id</param>
        /// <param name="topicId">话题Id</param>
        /// <exception cref="T:System.ArgumentException">groupId格式错误或topicId格式错误时抛出</exception>
        public void DeleteSeminarGroupTopicById(long groupId, long topicId)
        {
            if (groupId <= 0)
            {
                throw new ArgumentException("groupId格式错误");              //groupId不合法时抛出异常
            }
            if (topicId <= 0)
            {
                throw new ArgumentException("topicId格式错误"); //topicId不合法时抛出异常
            }
            Topic topic = _db.Topic.Find(topicId);          //根据topicId找到topic实体

            if (topic == null)
            {
                throw new TopicNotFoundException();              //找不到topic时抛出
            }
            SeminarGroup group = _db.SeminarGroup.Find(groupId); //根据groupId找到group实体

            if (group == null)
            {
                throw new GroupNotFoundException();               //找不到group时抛出
            }
            //链接三表查询
            List <SeminarGroupTopic> sgtList = _db.SeminarGroupTopic.Include(x => x.Topic)
                                               .Include(x => x.SeminarGroup)
                                               .Where(x => x.Topic == topic && x.SeminarGroup == group).ToList();

            //级联查找student_score_group表中的记录
            List <StudentScoreGroup> ssgList = _db.StudentScoreGroup
                                               .Include(x => x.SeminarGroupTopic)
                                               .ToList();

            List <StudentScoreGroup> ssgListToDelete = ssgList.FindAll(x => sgtList.Contains(x.SeminarGroupTopic));

            _db.StudentScoreGroup.RemoveRange(ssgListToDelete);//级联删除student_score_group表中的记录

            //删除找到的记录,此记录只有一条,但由于存储在List中,故使用RemoveRange()
            _db.SeminarGroupTopic.RemoveRange(sgtList);
            _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));
        }
示例#12
0
 public void UpdateGroupByGroupId(long seminarGroupId, int grade)
 {
     using (var scope = _db.Database.BeginTransaction())
     {
         try
         {
             SeminarGroup seminarGroup = _db.SeminarGroup.SingleOrDefault(s => s.Id == seminarGroupId);
             //如果找不到该组
             if (seminarGroup == null)
             {
                 throw new GroupNotFoundException();
             }
             //更新报告分
             seminarGroup.ReportGrade = grade;
             _db.SaveChanges();
         }
         catch
         {
             scope.Rollback();
             throw;
         }
     }
 }
 public void UpdateSeminarGroupById(long groupId, SeminarGroup group)
 {
     throw new NotImplementedException();
 }
示例#14
0
 public IActionResult UpdateGroupById([FromRoute] long groupId, [FromBody] SeminarGroup updated)
 {
     return(NoContent());
 }
示例#15
0
        /// <summary>
        /// 定时器方法:讨论课结束后计算本次讨论课得分.
        /// @author fengjinliu
        /// 条件: 讨论课已结束,展示得分已算出  *GradeService
        /// </summary>
        /// <param name="seminarId">讨论课id</param>
        /// <exception cref="T:System.ArgumentException">id格式错误</exception>
        ///

        public void CountGroupGradeBySerminarId(long seminarId)//成功测试!!!1
        {
            using (var scope = _db.Database.BeginTransaction())
            {
                List <SeminarGroup> seminarGroupList = _db.SeminarGroup.Include(u => u.Seminar).Include(u => u.ClassInfo).Where(u => u.Seminar.Id == seminarId).ToList();
                //根据seminarGroupList中元素,依次计算
                //SeminarGroup实体中保存了ClassInfo实体对象,可以查到成绩计算方法
                double[] tempTotalGrade = new double[seminarGroupList.Count];
                long[]   tempId         = new long[seminarGroupList.Count];
                foreach (var seminarGroup in seminarGroupList)
                {
                    //根据seminarGroupId获得seminarGroupTopicList,计算每一个seminarGroup的展示分数
                    List <SeminarGroupTopic> seminarGroupTopicList = _db.SeminarGroupTopic.Include(u => u.SeminarGroup).Where(u => u.SeminarGroup.Id == seminarGroup.Id).ToList();
                    if (seminarGroupTopicList == null)//该组没有展示分数
                    {
                        seminarGroupList.Remove(seminarGroup);
                    }
                    int?grade  = 0;
                    int number = 0;
                    foreach (var seminarGroupTopic in seminarGroupTopicList)
                    {
                        grade += seminarGroupTopic.PresentationGrade;
                        number++;
                    }
                    try
                    {
                        //更新seminarGroup中的展示成绩
                        int?avgPreGrade = grade / number;
                        _db.SeminarGroup.Attach(seminarGroup);
                        seminarGroup.PresentationGrade = avgPreGrade;
                        _db.SaveChanges();
                    }
                    catch
                    {
                        scope.Rollback(); throw;
                    }
                }
                for (int i = 0; i < seminarGroupList.Count; i++)
                {
                    tempTotalGrade[i] = ((double)(seminarGroupList[i].ClassInfo.PresentationPercentage * seminarGroupList[i].PresentationGrade
                                                  + seminarGroupList[i].ClassInfo.ReportPercentage * seminarGroupList[i].ReportGrade)) / 100;
                    tempId[i] = seminarGroupList[i].Id;
                }
                //排序
                //将小组总成绩从大到小排序
                quick_sort(tempId, tempTotalGrade, 0, seminarGroupList.Count - 1);
                //根据排序和比例计算组数,四舍五入
                int Five  = Convert.ToInt32(seminarGroupList.Count * seminarGroupList[0].ClassInfo.FivePointPercentage * 0.01);
                int Four  = Convert.ToInt32(seminarGroupList.Count * seminarGroupList[0].ClassInfo.FourPointPercentage * 0.01);
                int Three = Convert.ToInt32(seminarGroupList.Count * seminarGroupList[0].ClassInfo.ThreePointPercentage * 0.01);
                if (Five + Four + Three != seminarGroupList.Count)
                {
                    throw new ArgumentException("比例设置问题,与人数冲突");
                }
                //各小组按比例给分
                for (int i = 0; i < seminarGroupList.Count; i++)
                {
                    SeminarGroup seminarGroup = _db.SeminarGroup.SingleOrDefault(s => s.Id == tempId[i]);
                    //更新报告分

                    if (i >= 0 && i < Five)
                    {
                        seminarGroup.FinalGrade = 5; _db.SaveChanges();
                    }                                                                          //每一步都保存。我真的是怕了。
                    else if (i >= Five && i < Five + Four)
                    {
                        seminarGroup.FinalGrade = 4; _db.SaveChanges();
                    }
                    else if (i >= Four + Five && i < seminarGroupList.Count)
                    {
                        seminarGroup.FinalGrade = 3; _db.SaveChanges();
                    }

                    _db.SaveChanges();
                }
                _db.SaveChanges();
            }//using scope end
        }
        /// <summary>
        /// 定时器方法:讨论课结束后计算本次讨论课得分.
        /// @author fengjinliu
        /// 条件: 讨论课已结束,展示得分已算出  *GradeService
        /// </summary>
        /// <param name="seminarId">讨论课id</param>
        /// <exception cref="T:System.ArgumentException">id格式错误</exception>
        ///

        public void CountGroupGradeBySerminarId(long seminarId, IList <SeminarGroup> seminarGroupList)
        {
            using (var scope = _db.Database.BeginTransaction())
            {
                //根据seminarGroupList中元素,依次计算
                //SeminarGroup实体中保存了ClassInfo实体对象,可以查到成绩计算方法
                double[] tempTotalGrade = new double[seminarGroupList.Count];
                long[]   tempId         = new long[seminarGroupList.Count];
                foreach (var seminarGroup in seminarGroupList)
                {
                    //根据seminarGroupId获得seminarGroupTopicList,计算每一个seminarGroup的展示分数
                    List <SeminarGroupTopic> seminarGroupTopicList = _db.SeminarGroupTopic.Include(u => u.SeminarGroup).Where(u => u.SeminarGroup.Id == seminarGroup.Id).ToList();
                    if (seminarGroupTopicList == null)//该组没有展示分数
                    {
                        seminarGroupList.Remove(seminarGroup);
                    }
                    int?grade  = 0;
                    int number = 0;
                    foreach (var seminarGroupTopic in seminarGroupTopicList)
                    {
                        grade += seminarGroupTopic.PresentationGrade;
                        number++;
                    }
                    try
                    {
                        //更新seminarGroup中的展示成绩
                        int?avgPreGrade = grade / number;
                        _db.SeminarGroup.Attach(seminarGroup);
                        seminarGroup.PresentationGrade = avgPreGrade;
                        _db.SaveChanges();
                    }
                    catch
                    {
                        scope.Rollback(); throw;
                    }
                }
                for (int i = 0; i < seminarGroupList.Count; i++)
                {
                    tempTotalGrade[i] = ((double)(seminarGroupList[i].ClassInfo.PresentationPercentage * seminarGroupList[i].PresentationGrade
                                                  + seminarGroupList[i].ClassInfo.ReportPercentage * seminarGroupList[i].ReportGrade)) / 100;
                    tempId[i] = seminarGroupList[i].Id;
                }
                //排序
                //将小组总成绩从大到小排序
                QuickSort(tempId, tempTotalGrade, 0, seminarGroupList.Count - 1);
                //根据排序和比例计算组数
                int A = Convert.ToInt32(seminarGroupList.Count * seminarGroupList[0].ClassInfo.FivePointPercentage * 0.01);
                int B = Convert.ToInt32(seminarGroupList.Count * seminarGroupList[0].ClassInfo.FourPointPercentage * 0.01);
                int C = Convert.ToInt32(seminarGroupList.Count * seminarGroupList[0].ClassInfo.ThreePointPercentage * 0.01);

                //各小组按比例给分
                for (int i = 0; i < A; i++)
                {
                    try
                    {
                        ////更新报告分
                        //_db.SeminarGroup.Attach(seminarGroupList[i]);
                        //seminarGroupList[i].FinalGrade = 3;
                        //_db.SaveChanges();

                        SeminarGroup seminarGroup = _db.SeminarGroup.SingleOrDefault(s => s.Id == tempId[i]);
                        //如果找不到该组
                        if (seminarGroup == null)
                        {
                            throw new GroupNotFoundException();
                        }
                        //更新报告分
                        seminarGroup.FinalGrade = 5;
                        _db.SaveChanges();
                    }
                    catch
                    {
                        scope.Rollback();
                        throw;
                    }
                }
                for (int i = B; i < B + C; i++)
                {
                    try
                    {
                        SeminarGroup seminarGroup = _db.SeminarGroup.SingleOrDefault(s => s.Id == tempId[i]);
                        //如果找不到该组
                        if (seminarGroup == null)
                        {
                            throw new GroupNotFoundException();
                        }
                        //更新报告分
                        seminarGroup.FinalGrade = 4;
                        _db.SaveChanges();
                    }
                    catch
                    {
                        scope.Rollback();
                        throw;
                    }
                }
                for (int i = B + C; i < seminarGroupList.Count; i++)
                {
                    try
                    {
                        SeminarGroup seminarGroup = _db.SeminarGroup.SingleOrDefault(s => s.Id == tempId[i]);
                        //如果找不到该组
                        if (seminarGroup == null)
                        {
                            throw new GroupNotFoundException();
                        }
                        //更新报告分
                        seminarGroup.FinalGrade = 3;
                        _db.SaveChanges();
                    }
                    catch
                    {
                        scope.Rollback();
                        throw;
                    }
                }
            }//using scope end
        }
        /// <summary>
        /// 定时器方法:自动分组.
        /// </summary>
        ///
        /// 根据讨论课id和班级id,对签到的学生进行自动分组
        ///
        /// <param name="seminarId">讨论课的id</param>
        /// <param name="classId">班级的id</param>
        /// <returns>Boolean 自动分组成功返回true,否则返回false</returns>
        /// <seealso cref="M:Xmu.Crms.Shared.Service.IUserService.ListAttendanceById(System.Int64,System.Int64)"/>
        /// <exception cref="T:System.ArgumentException">id格式错误</exception>
        /// <exception cref="T:Xmu.Crms.Shared.Exceptions.SeminarNotFoundException">未找到讨论课</exception>
        /// <exception cref="T:Xmu.Crms.Shared.Exceptions.ClassNotFoundException">未找到班级</exception>
        public void AutomaticallyGrouping(long seminarId, long classId)
        {
            List <Attendance>   attendances;
            List <SeminarGroup> groups;
            Seminar             seminar;
            ClassInfo           classInfo;

            //调用ListAttendanceById获取签到学生信息
            attendances = _us.ListAttendanceById(classId, seminarId).ToList();

            //获取讨论课
            if ((seminar = _db.Seminar.Find(seminarId)) == null)
            {
                throw new SeminarNotFoundException();
            }

            //获取班级
            if ((classInfo = _db.ClassInfo.Find(classId)) == null)
            {
                throw new ClassNotFoundException();
            }

            var studentcount = _db.CourseSelection.Where(c => c.ClassId == classId).ToList().Count();
            var groupcount   = studentcount / 5 + 1;

            while (groupcount > 0)
            {
                SeminarGroup group = new SeminarGroup
                {
                    ClassId   = classId,
                    SeminarId = seminarId,
                };
                InsertSeminarGroupBySeminarId(seminarId, classId, group);
                groupcount--;
            }
            _db.SaveChanges();
            //获取该讨论课的所有队伍
            groups = _db.SeminarGroup
                     .Include(x => x.Seminar)
                     .Include(x => x.ClassInfo)
                     .Where(x => (x.Seminar.Id == seminarId && x.ClassInfo.Id == classId)).ToList();

            //对于每个签到的学生
            foreach (Attendance atten in attendances)
            {
                //如果是出勤或迟到状态,进入分配
                if (atten.AttendanceStatus == AttendanceStatus.Present)
                {
                    //获取该学生(需要返回的list有include学生对象)
                    UserInfo student = atten.Student;

                    try
                    {
                        //如果该学生已经分配了小组,就不需要再分配
                        GetSeminarGroupById(seminarId, student.Id);
                        continue;
                    }
                    //抛异常说明没有分配,则进入分配
                    catch (GroupNotFoundException)
                    {
                        //记录当前小组的最少人数和对应的组
                        int          MinNum      = 99999;
                        SeminarGroup InsertGroup = null;

                        //找到每个组的成员个数
                        foreach (SeminarGroup group in groups)
                        {
                            int num = 0;
                            //找到该组的成员个数
                            num = _db.SeminarGroupMember.Include(x => x.SeminarGroup)
                                  .Where(x => x.SeminarGroup == group).ToList().Count;

                            //如果个数少于当前最少个数,赋值给MinNum和InsertGroup
                            if (num < MinNum)
                            {
                                MinNum      = num;
                                InsertGroup = group;
                            }
                        }

                        //如果出错,返回false
                        if (MinNum == 99999 || InsertGroup == null)
                        {
                            throw new InvalidOperationException("随机分组失败");
                        }

                        //往人数最少的组添加一个成员
                        InsertSeminarGroupMemberById(student.Id, InsertGroup.Id);
                    }
                }
            }
            return;
        }