示例#1
0
 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());
     }
 }