public HttpResponseMessage UploadAssignment([FromBody] JObject assignmentInfo) { 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(assignmentInfo); int expID = jsonParams.exp_id; string file = jsonParams.file; Experiment experiment = ExperimentDao.GetExperimentById(expID); List <Course_student_mapping> csm = CourseDao.GetMapByStudentId(id).Where(m => m.course_id == experiment.course_id).ToList(); if (csm.Count > 0) { Assignment assignment = new Assignment { experiment_id = experiment.id, student_id = id, submit_time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), is_standard = 0, file = file }; Assignment oldAssignment = AssignmentDao.GetAssignmentsByStuIdAndExpId(id, expID); if (oldAssignment != null) { LogUtil.Log(Request, "重新提交作业", expID.ToString(), id, 1, "", "", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); AssignmentDao.DeleteAssignment(oldAssignment.id); AssignmentDao.AddAssignment(assignment); return(new Response(1001, "重新提交作业成功").Convert()); } else { LogUtil.Log(Request, "提交作业", expID.ToString(), id, 1, "", "", DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")); AssignmentDao.AddAssignment(assignment); return(new Response(1001, "提交作业成功").Convert()); } } return(new Response(2002).Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
public HttpResponseMessage PeerAssessmentDetails([FromBody] JObject peerDetail) { try { string signature = HttpUtil.GetAuthorization(Request); if (signature == null || !redis.IsSet(signature)) { return(new Response(2001, "未登录账户").Convert()); } //var jsonParams = HttpUtil.Deserialize(peerDetail); var jsonParams = Request.GetQueryNameValuePairs().ToDictionary(k => k.Key, v => v.Value); List <Dictionary <string, string> > retData = new List <Dictionary <string, string> >(); Dictionary <string, string> PaInfo = new Dictionary <string, string>(); bool isLogin = redis.IsSet(signature); if (!isLogin) { return(new Response(2001, "未登录账户").Convert()); } string userid = redis.Get <string>(signature);// jsonParams.stuid;// int expid = Convert.ToInt32(jsonParams["expid"]); Assignment assignment = AssignmentDao.GetAssignmentsByStuIdAndExpId(userid, expid); int cnt = 0; List <Peer_assessment> peer_Assessments = PeerAssessmentDao.getPeerAssessmentByExpId(userid, expid); foreach (Peer_assessment pa in peer_Assessments) { PaInfo = new Dictionary <string, string> { { "assessorId", pa.assessor_id.ToString() }, { "score", pa.origin_score.ToString() }, { "reason", pa.appeal_reason }, { "appealStatus", pa.appeal_status.ToString() }, }; retData.Add(PaInfo); cnt++; if (cnt >= 3 && assignment.is_standard == 2) { break; } } return(new Response(1001, "Success", retData).Convert()); //todo:body.id } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
public HttpResponseMessage DownloadAssignment([FromBody] JObject assignmentInfo) { 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(assignmentInfo); int expID = int.Parse(jsonParams.exp_id.ToString()); string user_id = jsonParams.user_id; Assignment assignment = AssignmentDao.GetAssignmentsByStuIdAndExpId(user_id, expID); if (assignment == null) { return(new Response(3001, "未找到该作业").Convert()); } Experiment exp = ExperimentDao.GetExperimentById((int)assignment.experiment_id); if (assignment.student_id == id || CourseDao.GetAssistantsByCourseId((int)exp.course_id).Where(a => a.student_id == id).ToList().Count > 0 || CourseDao.GetProfessorById((int)exp.course_id).id == id) { Dictionary <string, string> ret = new Dictionary <string, string>(); ret.Add("file", assignment.file); return(new Response(1001, "成功", ret).Convert()); } else { return(new Response(2002).Convert()); } } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
public HttpResponseMessage TryDownloadAssignment() { 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 = Request.GetQueryNameValuePairs().ToDictionary(k => k.Key, v => v.Value); int expId = Convert.ToInt32(jsonParams["expId"]); string stuId = jsonParams["stuId"]; Assignment assignment = AssignmentDao.GetAssignmentsByStuIdAndExpId(stuId, expId); if (assignment == null) { return(new Response(2002, "未找到作业").Convert()); } string fileId = assignment.file; File file = AssignmentDao.GetFileById(fileId); if (file == null) { return(new Response(2002, "未找到作业").Convert()); } string uuid = Guid.NewGuid().ToString(); redis.Set(uuid, file.id, 10); return(new Response(1001, "获取成功", uuid).Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }
public HttpResponseMessage UploadAssignment() { try { 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); HttpContextBase context = (HttpContextBase)Request.Properties["MS_HttpContext"]; HttpRequestBase httpRequest = context.Request; int expId = int.Parse(httpRequest["expId"]); Experiment exp = ExperimentDao.GetExperimentById(expId); if (!HttpUtil.IsTimeLater(exp.deadline)) { return(new Response(2002, "已过提交截止时间").Convert()); } if (exp == null) { return(new Response(3001).Convert()); } Course_student_mapping csm = CourseDao.GetMapByStudentId(id).Where(m => m.course_id == exp.course_id).First(); if (csm == null) { return(new Response(2002).Convert()); } string fileCode = null; if (httpRequest.Files.Count > 0) { string path = httpRequest.MapPath(@"~/Files/Assignment/" + expId + "/"); if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } var uploadedFiles = httpRequest.Files; if (uploadedFiles.Count != 1) { return(new Response(2002, "仅支持单个文件").Convert()); } var uploadedFile = uploadedFiles[0]; Models.File file = HttpUtil.UploadFile(uploadedFile, id, "作业", path, Request); AssignmentDao.AddFile(file); fileCode = file.id; } else if (httpRequest["file"] != null) { fileCode = httpRequest["file"].ToString(); } Assignment assignment = AssignmentDao.GetAssignmentsByStuIdAndExpId(id, expId); if (assignment == null) { assignment = new Assignment { student_id = id, experiment_id = expId, submit_time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"), file = fileCode, is_standard = 0 }; AssignmentDao.AddAssignment(assignment); LogUtil.Log(Request, "提交作业", expId.ToString(), id, 1); } else { string oldFile = assignment.file; assignment.file = fileCode; assignment.submit_time = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); AssignmentDao.ChangeAssignmentInfo(assignment); LogUtil.Log(Request, "重新提交作业", expId.ToString(), id, 1, "", "替换的作业: " + oldFile); } return(new Response(1001).Convert()); } catch (Exception e) { ErrorLogUtil.WriteLogToFile(e, Request); return(Response.Error()); } }