public HttpResponseMessage GetExperimentByTermId() { 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 = Convert.ToInt32(jsonParams["termId"]); bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string id = redis.Get <string>(signature); var retData = ExperimentDao.GetExperimentByTermIdAndStuId(id, termId); return(new Response(1001, "获取成功", ExperimentDao.GetExpRet(retData)).Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
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()); } }
public HttpResponseMessage GetAllExperiments() { try { string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string id = redis.Get <string>(signature); var retData = ExperimentDao.GetExperimentByStuId(id); return(new Response(1001, "获取成功", ExperimentDao.GetExpRet(retData)).Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
public HttpResponseMessage GetUnfinishedExperiment([FromUri] JObject conditions)//fromUri 没用 { //Dictionary<string, string> retData = new Dictionary<string, string>(); List <Dictionary <string, string> > retData = new List <Dictionary <string, string> >(); Dictionary <string, string> expInfo; try { var jsonParams = Request.GetQueryNameValuePairs().ToDictionary(k => k.Key, v => v.Value); var currentTime = DateTime.Now; string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } //var jsonParams = HttpUtil.Deserialize(conditions); int termId = Convert.ToInt32(jsonParams["termId"]); bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string id = redis.Get <string>(signature); //string id = "16211094"; //List<Course_student_mapping> courseList = CourseDao.GetMapByStudentId(id); List <Course> courseList = CourseDao.GetCoursesByStuIdAndTermId(id, termId); List <Experiment> allExperiment = new List <Experiment>(); foreach (var map in courseList) { List <Experiment> exp = ExperimentDao.GetExperimentByCourseId(map.id); allExperiment = allExperiment.Union(exp).ToList(); } allExperiment = allExperiment.OrderBy(i => i.id).ToList(); List <Assignment> allAssignments = AssignmentDao.GetAssignmentsByStuId(id).OrderBy(i => i.experiment_id).ToList(); List <Peer_assessment> peerAssessments = PeerAssessmentDao.getPeerAssessmentByStuId(id); List <Experiment> assignmentFinishedExp = allExperiment.Where(e => allAssignments.Exists(a => a.experiment_id == e.id)).ToList(); allExperiment = allExperiment.Except(assignmentFinishedExp).ToList(); //没完成作业的 List <Experiment> peerExp = assignmentFinishedExp.Where(e => e.is_peer_assessment == true).ToList(); //作业完成但要互评 foreach (Experiment e in peerExp) { if (PeerAssessmentDao.getPeerAssessmentByAssessorId(id, e.id).Where(p => p.appeal_status == 1).Count() > 0) { allExperiment.Add(e); } }//得到没完成作业的&没互评的 allExperiment = allExperiment.Where(e => (e.is_peer_assessment == false && DateTime.Compare(Convert.ToDateTime(e.deadline), currentTime) > 0 || e.is_peer_assessment == true && DateTime.Compare(Convert.ToDateTime(e.peer_assessment_deadline), currentTime) > 0)).ToList(); //得到ddl前的 return(new Response(1001, "获取成功", ExperimentDao.GetExpRet(allExperiment)).Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }