public HttpResponseMessage AdminGetAllExperiments() { 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 termId = 0; int courseId = 0; if (jsonParams.ContainsKey("termId")) { termId = Convert.ToInt32(jsonParams["termId"]); } if (jsonParams.ContainsKey("courseId")) { courseId = Convert.ToInt32(jsonParams["courseId"]); } bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string id = redis.Get <string>(signature); //string id = "admin"; User user = UserDao.GetUserById(id); if (user.role < 3) { return(new Response(2002, "权限不足").Convert()); } List <Experiment> experiments = ExperimentDao.GetExperimentByCourseIdAndTermId(courseId, termId); if (user.role == 3) { List <Course> courses = CourseDao.GetCourseByDepId(user.department_id); experiments = experiments.Where(e => courses.Exists(c => c.id == e.course_id)).ToList(); } return(new Response(1001, "获取成功", ExperimentDao.GetExpRet(experiments)).Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }