public HttpResponseMessage getStusWithoutVMByExpId([FromBody] JObject expInfo) { try { List <Dictionary <string, string> > retData = new List <Dictionary <string, string> >(); Dictionary <string, string> stuidInfo; 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); bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string userid = redis.Get <string>(signature); int expid = Convert.ToInt32(jsonParams["expid"]); Experiment exp = ExperimentDao.GetExperimentById(expid); if (exp.course_id == null) { return(new Response(1001, "该实验没有所属课程").Convert()); } int courseId = (int)ExperimentDao.GetExperimentById(expid).course_id; User user = UserDao.GetUserById(userid); if ((user.role == 2 && CourseDao.GetCourseInfoById(courseId).teacher_id == user.id) || (user.role == 1 && CourseDao.GetAssistantsByCourseId(courseId).Where(a => a.student_id == user.id).Count() != 0)) { List <User> stulist = CourseDao.GetStudentsById(courseId); List <VMConfig> vmlist = VMDao.GetVMsByVmName(exp.vm_name); foreach (User stu in stulist) { if (vmlist.Find(vm => vm.student_id.Equals(stu.id)) == null) { stuidInfo = new Dictionary <string, string> { { "id", stu.id }, }; retData.Add(stuidInfo); } } return(new Response(1001, "Success", retData).Convert()); } else { return(new Response(2001, "没有权限获取信息").Convert()); } } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
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()); } }