Пример #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());
            }
        }
Пример #2
0
        public HttpResponseMessage GetStuListNoVM([FromBody] JObject account)
        {
            List <Dictionary <string, string> > retData = new List <Dictionary <string, string> >();
            Dictionary <string, string>         stuInfo;

            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);
                int  courseId   = Convert.ToInt32(jsonParams["courseId"]);
                int  expid      = Convert.ToInt32(jsonParams["expId"]);
                bool isLogin    = redis.IsSet(signature);
                if (!isLogin)
                {
                    return(new Response(2001, "未登录账户").Convert());
                }
                string targetId  = redis.Get <string>(signature);
                Course course    = CourseDao.GetCourseInfoById(courseId);
                User   user      = UserDao.GetUserById(targetId);
                User   professor = UserDao.GetUserById(course.teacher_id);

                Dictionary <string, string> department = new Dictionary <string, string>();
                string depart = null;
                if (user.role == 4 || (user.role == 3 && user.department_id == professor.department_id) || user.id == professor.id ||
                    (CourseDao.GetAssistantsByCourseId((courseId)).Where(a => a.student_id == user.id).Count() == 1))
                {
                    //如果是管理员、负责这个学院的部门管理员、课程对应的老师、课程对应的助教才有资格访问
                    List <User>     stuList  = CourseDao.GetStudentsById(courseId);
                    string          temp     = null;
                    Experiment      exp      = ExperimentDao.GetExperimentById(expid);
                    List <VMConfig> virtuals = VMDao.GetVMsByVmName(exp.vm_name);

                    foreach (User stu in stuList)
                    {
                        bool flag = true;
                        if (department.ContainsKey(stu.department_id))
                        {
                            depart = department[stu.department_id];
                        }
                        else
                        {
                            temp = CourseDao.GetDepartmentById(stu.department_id).name;
                            department.Add(stu.department_id, temp);
                            depart = temp;
                        }
                        foreach (VMConfig vm in virtuals)
                        {
                            if (vm.student_id == stu.id)
                            {
                                flag = false;
                            }
                        }
                        if (flag == false)
                        {
                            continue;
                        }



                        stuInfo = new Dictionary <string, string>
                        {
                            { "id", stu.id.ToString() },
                            { "name", stu.name }
                        };
                        retData.Add(stuInfo);
                    }
                    return(new Response(1001, "获取成功", retData).Convert());
                }
                else
                {
                    return(new Response(2002, "没有权限访问该信息").Convert());
                }
            }
            catch (Exception e)
            {
                ErrorLogUtil.WriteLogToFile(e, Request);
                return(Response.Error());
            }
        }