Exemple #1
0
        public HttpResponseMessage GetstandardHW([FromBody] JObject expId)
        {
            try
            {
                string signature = HttpUtil.GetAuthorization(Request);
                if (signature == null || !redis.IsSet(signature))
                {
                    return(new Response(2001, "未登录账户").Convert());
                }
                bool login = redis.IsSet(signature);
                if (!login)
                {
                    return(new Response(2001, "未登录账户").Convert());
                }
                string id = redis.Get <string>(signature);

                var jsonParams = Request.GetQueryNameValuePairs().ToDictionary(k => k.Key, v => v.Value);
                //string id = jsonParams["id"];
                int        expid  = Convert.ToInt32(jsonParams["expid"]);
                User       user   = UserDao.GetUserById(id);
                Experiment exp    = ExperimentDao.GetExperimentById(expid);
                Course     course = CourseDao.GetCourseInfoById((int)exp.course_id);
                ///权限控制,该课程助教与老师可以访问
                if (CourseDao.GetAssistantsByCourseId(course.id).Where(a => a.student_id == id).Count() == 1 || id == course.teacher_id)
                {
                    List <Assignment> assignments = AssignmentDao.GetAssignmentsToMarkByExpId(expid);

                    if (assignments.Count() < 6)
                    {
                        assignments = AssignmentDao.GenAssignmentsToMark(expid);
                        if (assignments == null)
                        {
                            return(new Response(3001, "作业数量不足6份,无法抽取").Convert());
                        }
                    }

                    List <Dictionary <string, string> > retData = new List <Dictionary <string, string> >();
                    Dictionary <string, string>         temp;
                    var props = assignments.First().GetType().GetProperties();
                    int cnt   = 0;
                    foreach (Assignment hw in assignments)
                    {
                        temp = new Dictionary <string, string>();
                        foreach (var pi in props)
                        {
                            var    v = hw.GetType().GetProperty(pi.Name).GetValue(hw, null);
                            string value;
                            if (v != null)
                            {
                                value = v.ToString();
                            }
                            else
                            {
                                value = "";
                            }
                            temp.Add(pi.Name, value);
                        }
                        User student = UserDao.GetUserById(hw.student_id);
                        temp.Add("student_name", student.name.ToString());
                        if (hw.score != null)
                        {
                            cnt++;
                        }
                        retData.Add(temp);
                    }
                    if (cnt == 6)
                    {
                        if (exp.peer_assessment_start == true)
                        {
                            return(new Response(1001, "互评已开始", retData).Convert());
                        }
                        else
                        {
                            return(new Response(1001, "评分已完成,请开始互评", retData).Convert());
                        }
                    }
                    return(new Response(1001, "success", retData).Convert());
                }
                else
                {
                    return(new Response(2002, "无权抽取作业").Convert());
                }
            }
            catch (Exception e)
            {
                ErrorLogUtil.WriteLogToFile(e, Request);
                return(Response.Error());
            }
        }