예제 #1
0
 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());
     }
 }