Esempio n. 1
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());
            }
        }
Esempio n. 2
0
        public HttpResponseMessage GetExperimentDetail([FromBody] JObject account)
        {
            try
            {
                var jsonParams = Request.GetQueryNameValuePairs().ToDictionary(k => k.Key, v => v.Value);
                int id         = Convert.ToInt32(jsonParams["id"]); //experimentid

                string signature = HttpUtil.GetAuthorization(Request);
                if (signature == null || !redis.IsSet(signature))
                {
                    return(new Response(2001, "未登录账户").Convert());
                }
                //var jsonParams = HttpUtil.Deserialize(account);


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

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

                //string userId = "16211084";
                User              user       = UserDao.GetUserById(userId);
                Experiment        experiment = ExperimentDao.GetExperimentById(id);
                Course            course     = CourseDao.GetCourseInfoById(experiment.id);
                List <Assignment> assignment = AssignmentDao.GetAssignmentsByStuId(userId);
                bool              flag       = false;
                foreach (var ass in assignment)
                {
                    if (ass.experiment_id == id)
                    {
                        flag = true;
                        break;
                    }
                }

                tmpRetExpDetail ret = new tmpRetExpDetail();
                ret.name   = experiment.name;
                ret.type   = experiment.type.GetValueOrDefault();
                ret.score  = Convert.ToInt32(experiment.vm_status);
                ret.score2 = Convert.ToInt32(experiment.vm_apply_id);
                ret.reason = experiment.vm_name;
                if (experiment.course_id != null)
                {
                    //找出其他任课老师
                    List <Assistant> AssistantTeas = CourseDao.GetAssistantsByCourseId((int)experiment.course_id).ToList();
                    List <string>    teachers      = UserDao.GetUserByRole(2).Where(a => AssistantTeas.Exists(t => t.student_id == a.id)).Select(a => a.name).ToList();

                    ret.course     = CourseDao.GetCourseInfoById((int)experiment.course_id).name;
                    ret.course_id  = (int)experiment.course_id;
                    ret.teacher    = UserDao.GetUserById(CourseDao.GetCourseInfoById((int)experiment.course_id).teacher_id).name;
                    ret.teacher_id = CourseDao.GetCourseInfoById((int)experiment.course_id).teacher_id;
                    if (teachers.Count != 0)
                    {
                        foreach (string t in teachers)
                        {
                            ret.teacher = ret.teacher + "," + t;
                        }
                    }
                }
                else
                {
                    ret.course  = "";
                    ret.teacher = "";
                }
                ret.deadline     = experiment.deadline;
                ret.peerDeadline = experiment.peer_assessment_deadline;
                ret.details      = experiment.detail;

                /**
                 * ret.sourcelist = new List<Dictionary<string, string>>();
                 * ret.sourcelist.Add(new Dictionary<string, string> {
                 *  { "source", experiment.resource },
                 *  { "name","" }//TODO:这啥属性?
                 * });
                 **/
                ret.resource           = experiment.resource;
                ret.appealDeadline     = experiment.appeal_deadline;
                ret.peerAssessmentRule = experiment.peer_assessment_rules;
                ret.peerStarted        = experiment.peer_assessment_start == true ? true:false;
                ret.startTime          = experiment.start_time;
                ret.endTime            = experiment.end_time;
                if (user.role == 1)
                {
                    ret.status = flag ? "1" : "0";
                }
                else
                {
                    ret.status = AssignmentDao.GetAssignmentsByExpId(experiment.id).Count().ToString() + "/" + CourseDao.GetMapByCourseId((int)experiment.course_id).Count().ToString();
                }

                return(new Response(1001, "获取成功", ret).Convert());
            }
            catch (Exception e)
            {
                ErrorLogUtil.WriteLogToFile(e, Request);
                return(Response.Error());
            }
        }