示例#1
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());
            }
        }