Exemplo n.º 1
0
        public HttpResponseMessage GetCourseListByStuIdAndTerm([FromBody] JObject stuIdAndTerm)
        {
            List <Dictionary <string, string> > retData = new List <Dictionary <string, string> >();
            Dictionary <string, string>         courseInfo;

            try
            {
                string signature = HttpUtil.GetAuthorization(Request);
                if (signature == null || !redis.IsSet(signature))
                {
                    return(new Response(2001, "未登录账户").Convert());
                }
                var    jsonParams = Request.GetQueryNameValuePairs().ToDictionary(k => k.Key, v => v.Value);
                string term       = jsonParams["term"];
                bool   isLogin    = redis.IsSet(signature);
                if (!isLogin)
                {
                    return(new Response(2001, "未登录账户").Convert());
                }
                string        targetId   = redis.Get <string>(signature);
                int           termId     = CourseDao.GetTermByName(term).id;
                List <Course> courseList = CourseDao.GetCoursesByStuIdAndTermId(targetId, termId).ToList();
                foreach (Course c in courseList)
                {
                    courseInfo = new Dictionary <string, string>
                    {
                        { "id", c.id.ToString() },
                        { "name", c.name },
                    };
                    if (c.term_id == null)
                    {
                        courseInfo.Add("semester", "");
                    }
                    else
                    {
                        courseInfo.Add("semester", CourseDao.GetTermById((int)c.term_id).name);
                    }
                    courseInfo.Add("teacher", UserDao.GetUserById(c.teacher_id).name);
                    courseInfo.Add("department", CourseDao.GetDepartmentById(c.department_id).name);
                    retData.Add(courseInfo);
                }
                return(new Response(1001, "获取成功", retData).Convert());
            }
            catch (Exception e)
            {
                ErrorLogUtil.WriteLogToFile(e, Request);
                return(Response.Error());
            }
        }
Exemplo n.º 2
0
        public HttpResponseMessage GetUnfinishedExperiment([FromUri] JObject conditions)//fromUri 没用
        {
            //Dictionary<string, string> retData = new Dictionary<string, string>();
            List <Dictionary <string, string> > retData = new List <Dictionary <string, string> >();
            Dictionary <string, string>         expInfo;

            try
            {
                var    jsonParams  = Request.GetQueryNameValuePairs().ToDictionary(k => k.Key, v => v.Value);
                var    currentTime = DateTime.Now;
                string signature   = HttpUtil.GetAuthorization(Request);
                if (signature == null || !redis.IsSet(signature))
                {
                    return(new Response(2001, "未登录账户").Convert());
                }
                //var jsonParams = HttpUtil.Deserialize(conditions);
                int termId = Convert.ToInt32(jsonParams["termId"]);

                bool isLogin = redis.IsSet(signature);
                if (!isLogin)
                {
                    return(new Response(2001, "未登录账户").Convert());
                }

                string id = redis.Get <string>(signature);

                //string id = "16211094";
                //List<Course_student_mapping> courseList = CourseDao.GetMapByStudentId(id);
                List <Course>     courseList    = CourseDao.GetCoursesByStuIdAndTermId(id, termId);
                List <Experiment> allExperiment = new List <Experiment>();
                foreach (var map in courseList)
                {
                    List <Experiment> exp = ExperimentDao.GetExperimentByCourseId(map.id);
                    allExperiment = allExperiment.Union(exp).ToList();
                }
                allExperiment = allExperiment.OrderBy(i => i.id).ToList();
                List <Assignment>      allAssignments        = AssignmentDao.GetAssignmentsByStuId(id).OrderBy(i => i.experiment_id).ToList();
                List <Peer_assessment> peerAssessments       = PeerAssessmentDao.getPeerAssessmentByStuId(id);
                List <Experiment>      assignmentFinishedExp = allExperiment.Where(e => allAssignments.Exists(a => a.experiment_id == e.id)).ToList();
                allExperiment = allExperiment.Except(assignmentFinishedExp).ToList();                                //没完成作业的

                List <Experiment> peerExp = assignmentFinishedExp.Where(e => e.is_peer_assessment == true).ToList(); //作业完成但要互评
                foreach (Experiment e in peerExp)
                {
                    if (PeerAssessmentDao.getPeerAssessmentByAssessorId(id, e.id).Where(p => p.appeal_status == 1).Count() > 0)
                    {
                        allExperiment.Add(e);
                    }
                }//得到没完成作业的&没互评的

                allExperiment = allExperiment.Where(e => (e.is_peer_assessment == false && DateTime.Compare(Convert.ToDateTime(e.deadline), currentTime) > 0 ||
                                                          e.is_peer_assessment == true && DateTime.Compare(Convert.ToDateTime(e.peer_assessment_deadline), currentTime) > 0)).ToList();
                //得到ddl前的
                return(new Response(1001, "获取成功", ExperimentDao.GetExpRet(allExperiment)).Convert());
            }
            catch (Exception e)
            {
                ErrorLogUtil.WriteLogToFile(e, Request);
                return(Response.Error());
            }
        }