public HttpResponseMessage FindWeight() { try { string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } //var jsonParams = HttpUtil.Deserialize(paInfo); var jsonParams = Request.GetQueryNameValuePairs().ToDictionary(k => k.Key, v => v.Value); //Console.WriteLine(jsonParams); bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string stuid = jsonParams["stuid"]; string userid = jsonParams["userid"]; int expid = Convert.ToInt32(jsonParams["expid"]); Peer_assessment OldPa = PeerAssessmentDao.getPeerAssessment(stuid, userid, expid); if (OldPa == null) { return(new Response(1001, "暂无分数", -1).Convert()); } return(new Response(1001, "成功", OldPa.score).Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
/* * Create By xzy *增加一条新的互评信息 * 2019/7/18 add */ public static void AddPeerAssessment(Peer_assessment peerassessment) { using (var dbContext = new DataModels()) { dbContext.Peer_assessment.Add(peerassessment); dbContext.SaveChanges(); } }
/* * Create By xzy *修改互评信息 * 2019/7/18 add */ public static int ChangePeerAssessmentInfo(Peer_assessment newpa) { using (var dbContext = new DataModels()) { Peer_assessment peerassessment = dbContext.Peer_assessment.Find(newpa.student_id, newpa.assessor_id, newpa.experiment_id); QuickCopy.Copy(newpa, ref peerassessment); return(dbContext.SaveChanges()); } }
public HttpResponseMessage dealAppeal([FromBody] JObject paInfo) { 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 jsonParams = HttpUtil.Deserialize(paInfo); //string id = jsonParams.id; string student_id = jsonParams.student_id; string assessor_id = jsonParams.assessor_id; int experiment_id = jsonParams.experiment_id; float score = Convert.ToSingle(jsonParams.score); User user = UserDao.GetUserById(id); Experiment exp = ExperimentDao.GetExperimentById(experiment_id); Course course = CourseDao.GetCourseInfoById((int)exp.course_id); ///权限控制,该课程助教与老师可以访问 if (CourseDao.GetAssistantsByCourseId(course.id).Where(a => a.student_id == id).Count() == 1 || id == course.teacher_id) { Peer_assessment peer_Assessment = new Peer_assessment(); QuickCopy.Copy(paInfo, ref peer_Assessment); peer_Assessment.appeal_status = 2; Peer_assessment OldPa = PeerAssessmentDao.getPeerAssessment(student_id, assessor_id, experiment_id); if (OldPa == null) { return(new Response(3001, "参数无效").Convert()); } if (PeerAssessmentDao.ChangePeerAssessmentInfo(peer_Assessment) == 1) { return(new Response(1001, "Success").Convert()); } else { throw new Exception("数据库操作异常"); } } else { return(new Response(2002, "无权访问").Convert()); } } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
/* * 标准作业设置完毕,分配互评作业 * created by xzy * 2019/9/20 */ public static void AssignPeerAsssessment(int expid) { List <Assignment> inputList = GetAssignmentsByExpId(expid); int count = inputList.Count; Assignment[] copyArray = new Assignment[count]; inputList.CopyTo(copyArray); List <Assignment> copyList = new List <Assignment>(); copyList.AddRange(copyArray); List <Assignment> outputList = new List <Assignment>(); Random rd = new Random(DateTime.Now.Millisecond); while (copyList.Count > 0) { int rdIndex = rd.Next(0, copyList.Count - 1); Assignment remove = copyList[rdIndex]; copyList.Remove(remove); outputList.Add(remove); } using (var dbContext = new DataModels()) { for (int i = 0; i < count; i++) { for (int j = 1; j < 4; j++) { Peer_assessment newPR = new Peer_assessment(); newPR.assessor_id = outputList[i].student_id; newPR.student_id = outputList[(i + j) % count].student_id; newPR.experiment_id = expid; newPR.appeal_status = 0; dbContext.Peer_assessment.Add(newPR); dbContext.SaveChanges(); } List <Assignment> standard = GetStandardAssignmentsByExpId(expid); int rdi = rd.Next(0, 3); int rdiTry = 0; Peer_assessment standardPA = new Peer_assessment(); standardPA.assessor_id = outputList[i].student_id; while (PeerAssessmentDao.getPeerAssessment(standard[rdi].student_id, outputList[i].student_id, expid) != null && rdiTry < 4) { rdi = (rdi + 1) % 4; rdiTry++; } if (PeerAssessmentDao.getPeerAssessment(standard[rdi].student_id, outputList[i].student_id, expid) == null) { standardPA.student_id = standard[rdi].student_id; standardPA.experiment_id = expid; standardPA.appeal_status = 0; dbContext.Peer_assessment.Add(standardPA); dbContext.SaveChanges(); } } } }
/* * Create By yixia *查看一条具体互评信息 * 2019/7/18 add */ public static Peer_assessment getPeerAssessment(Peer_assessment newpa) { using (var dbContext = new DataModels()) { Peer_assessment peerAssessment = dbContext.Peer_assessment.Find(newpa.student_id, newpa.assessor_id, newpa.experiment_id); if (peerAssessment == null) { return(null); } return(peerAssessment); } }
public HttpResponseMessage AddPeerAssessment([FromBody] JObject peerAssessment) { try { string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } var jsonParams = HttpUtil.Deserialize(peerAssessment); bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string id = redis.Get <string>(signature); string stuid = jsonParams.student_id; int expid = jsonParams.experiment_id; Peer_assessment peerAssessment2 = new Peer_assessment(); peerAssessment2.assessor_id = id; QuickCopy.Copy(peerAssessment, ref peerAssessment2); Peer_assessment OldPa = PeerAssessmentDao.getPeerAssessment(stuid, id, expid); if (OldPa != null) { if (PeerAssessmentDao.ChangePeerAssessmentInfo(peerAssessment2) == 1) { return(new Response(1001, "Success").Convert()); } else { return(new Response(1001, "数据未变").Convert()); } } Peer_assessment peer_Assessment = new Peer_assessment(); peer_Assessment.assessor_id = id; QuickCopy.Copy(peerAssessment, ref peer_Assessment); Experiment exp = ExperimentDao.GetExperimentById(peer_Assessment.experiment_id); //if (!HttpUtil.IsTimeLater(exp.peer_assessment_deadline)) //return new Response(2002, "互评已结束").Convert(); PeerAssessmentDao.AddPeerAssessment(peer_Assessment); LogUtil.Log(Request, "作业评分", peer_Assessment.student_id, peer_Assessment.assessor_id, 1, "", "", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); return(new Response(1001, "Success").Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
public HttpResponseMessage FindComment([FromBody] JObject paInfo) { try { string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } //var jsonParams = HttpUtil.Deserialize(paInfo); var jsonParams = Request.GetQueryNameValuePairs().ToDictionary(k => k.Key, v => v.Value); //Console.WriteLine(jsonParams); bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string stuid = jsonParams["stuid"]; string userid = redis.Get <string>(signature); int expid = Convert.ToInt32(jsonParams["expid"]);; Peer_assessment peerAssessment = new Peer_assessment(); Peer_assessment OldPa = PeerAssessmentDao.getPeerAssessment(stuid, userid, expid); if (OldPa == null) { return(new Response(1001, "暂无评价").Convert()); } return(new Response(1001, "成功", OldPa.reason).Convert()); //if (PeerAssessmentDao.getPeerAssessment(peer_Assessment) == null) //{ //return new Response(1002, "失败").Convert(); //} } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
public HttpResponseMessage ChangePeerAssessmentInfo([FromBody] JObject paInfo) { try { string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } var jsonParams = HttpUtil.Deserialize(paInfo); bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string stuid = jsonParams.student_id; string userid = redis.Get <string>(signature); int expid = jsonParams.experiment_id; Peer_assessment peer_Assessment = new Peer_assessment(); QuickCopy.Copy(paInfo, ref peer_Assessment); Peer_assessment OldPa = PeerAssessmentDao.getPeerAssessment(stuid, userid, expid); if (OldPa == null) { return(new Response(2002, "无权访问").Convert()); } if (PeerAssessmentDao.ChangePeerAssessmentInfo(peer_Assessment) == 1) { return(new Response(1001, "Success").Convert()); } else { throw new Exception("数据库操作异常"); } } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }