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 GetHomeworkStatus([FromBody] JObject expInfo) { try { var jsonParams = Request.GetQueryNameValuePairs().ToDictionary(k => k.Key, v => v.Value); int experimentId = Convert.ToInt32(jsonParams["id"]); string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } bool login = redis.IsSet(signature); if (!login) { return(new Response(2001, "未登录账户").Convert()); } string id = redis.Get <string>(signature); //string id = "16211084"; User user = UserDao.GetUserById(id); Experiment experiment = ExperimentDao.GetExperimentById(experimentId); Course course = CourseDao.GetCourseInfoById((int)experiment.course_id); //if (user.role < 2 && CourseDao.GetAssistantsByCourseId(course.id).Where(a => a.student_id == id).ToList().Count() == 0) //{ // return new Response(2002, "无权限查看助教").Convert(); //} //if (user.role == 3 && user.department_id != course.department_id) //{ // return new Response(2002, "无权限查看助教").Convert(); //} List <Dictionary <string, string> > ret = new List <Dictionary <string, string> >(); Dictionary <string, string> retData; List <User> students = CourseDao.GetStudentsById(course.id); List <Assignment> assignments = AssignmentDao.GetAssignmentsByExpId(experiment.id); string fileId = ""; string homeworkStatus = ""; string uploadTime = ""; foreach (User stu in students) { retData = new Dictionary <string, string>(); Assignment assignment = assignments.Where(a => a.student_id == stu.id).SingleOrDefault(); if (assignment == null) { fileId = ""; homeworkStatus = "未提交"; uploadTime = ""; } else { fileId = assignment.file; homeworkStatus = "已提交"; uploadTime = assignment.submit_time; } retData.Add("stuId", stu.id); retData.Add("stuName", stu.name); retData.Add("fileID", fileId == null? "" : fileId); retData.Add("homeworkStatus", homeworkStatus); retData.Add("uploadTime", uploadTime); retData.Add("score", assignment == null ? "" : assignment.score.ToString()); ret.Add(retData); } return(new Response(1001, "成功", ret).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()); } }