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格式!" }));
            }
        }
        public IActionResult GetGroupsUnderTopic(long topicId)
        {
            try
            {
                // Fetch groups belongs to this topic via topicId from database...
                IList <SeminarGroup> seminarGroupList = _iSeminarGroupService.ListGroupByTopicId(topicId);

                // 转换成VO对象
                List <GroupVO> groups = new List <GroupVO>();         //只需要Id和Name
                foreach (SeminarGroup sg in seminarGroupList)
                {
                    GroupVO g = sg;

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

                    //获取Topics和PresentationGrade
                    IList <SeminarGroupTopic> seminarGroupTopicList = _iTopicService.ListSeminarGroupTopicByGroupId(sg.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);
                    }
                    g.Topics = topics;
                    g.Grade.PresentationGrade = pGrades;

                    //获取Name
                    g.GetName();

                    groups.Add(g);
                }

                // Success
                return(Json(groups));
            }
            //If topic not found, 返回404
            catch (TopicNotFoundException)
            {
                return(NotFound(new { msg = "未找到该话题!" }));
            }
            //topicId 格式错误,返回400
            catch (ArgumentException)
            {
                return(BadRequest(new { msg = "错误的ID格式!" }));
            }
        }
Exemplo n.º 3
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());
            }
        }
        public IActionResult GetSeminarGroups(long seminarId, [FromQuery] bool gradeable, [FromQuery] int classId)
        {
            try
            {
                // 先只实现了不分班级小组和不分用户是否可打分小组的方法

                // Fetch data from database
                IList <SeminarGroup> seminarGroupList = _iSeminarGroupService.ListSeminarGroupBySeminarId(seminarId);

                // 转换成VO对象
                List <GroupVO> groups = new List <GroupVO>();
                foreach (var sg in seminarGroupList)
                {
                    GroupVO g = sg;

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

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

                    //获取Name
                    g.GetName();

                    groups.Add(g);
                }

                // Success
                return(Json(groups));
            }
            //If seminar not found, 返回404
            catch (SeminarNotFoundException)
            {
                return(NotFound(new { msg = "未找到该讨论课!" }));
            }
            //seminarId 格式错误,返回400
            catch (ArgumentException)
            {
                return(BadRequest(new { msg = "错误的ID格式!" }));
            }
        }
        public IActionResult GetStudentGradeUnderAllSeminar(long courseId)
        {
            try
            {
                // Fetch data from database
                IList <SeminarGroup> seminarGroupList = _iGradeService.ListSeminarGradeByCourseId(User.Id(), courseId);

                // 转换为SeminarGradeDetailVO的List对象
                List <SeminarGradeDetailVO> seminarGrades = new List <SeminarGradeDetailVO>();
                foreach (SeminarGroup i in seminarGroupList)
                {
                    // 为了获得GroupName,要先建一个GroupVO实体
                    GroupVO g = i;

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

                    //获取Topics和PresentationGrade
                    IList <SeminarGroupTopic> seminarGroupTopicList = _iTopicService.ListSeminarGroupTopicByGroupId(i.Id);
                    List <TopicVO>            topics = new List <TopicVO>();
                    List <int> pGrades = new List <int>();
                    foreach (SeminarGroupTopic sgt in seminarGroupTopicList)
                    {
                        topics.Add(sgt.Topic);
                        if (sgt.PresentationGrade != null)
                        {
                            pGrades.Add((int)sgt.PresentationGrade);
                        }
                        else
                        {
                            pGrades.Add(0);
                        }
                    }
                    g.Topics = topics;
                    g.Grade.PresentationGrade = pGrades;

                    //获取Name
                    g.GetName();

                    SeminarGradeDetailVO seminarGradeDetailVO = new SeminarGradeDetailVO {
                        SeminarName = i.Seminar.Name, GroupName = g.Name, LeaderName = i.Leader.Name, PresentationGrade = i.PresentationGrade == null?0:(int)i.PresentationGrade, ReportGrade = i.ReportGrade == null ? 0 : (int)i.ReportGrade, Grade = i.FinalGrade == null ? 0 : (int)i.FinalGrade
                    };
                    seminarGrades.Add(seminarGradeDetailVO);
                }

                // Success
                return(Json(seminarGrades));
            }
            // 未找到课程,返回404
            catch (CourseNotFoundException)
            {
                return(NotFound(new { msg = "未找到该课程!" }));
            }
            // 错误的ID格式,返回400
            catch (ArgumentException)
            {
                return(BadRequest(new { msg = "错误的ID格式!" }));
            }
        }