/// <summary> /// Delete the progress for a specific assignment and the currently logged in user. /// </summary> public HttpResponseMessage Delete() { // Tried to fixx the "not being able to start an assignment if you reloaded the page during one" problem. if (_participant.Progress == null) { return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Geen opdracht is gestart.")); } try{ var timeDifference = TimeDifferenceHelper.GetTimeDifference(_participant.Progress.StartTime); if (timeDifference > _participant.Progress.Assignment.MaxSolveTime) { timeDifference = _participant.Progress.Assignment.MaxSolveTime; } var score = ScoreHelper.CreateScore(_participant.Progress.Assignment, _participant, false, timeDifference); _context.Scores.Add(score); _context.Progresses.Remove(_participant.Progress); _context.SaveChanges(); } catch { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Error bij het opslaan in de database.")); throw; } return(Request.CreateResponse(HttpStatusCode.OK)); }
/// <summary> /// Build and runs an assignment and checks the scores for the user submitted code. /// </summary> /// <param name="runJob">See RunController.</param> /// <returns></returns> public HttpResponseMessage Post(RunController.RunJob runJob) { _compiler.CompileFromPlainText(_participant, runJob.Code); var runResult = _runner.RunAndCheckInput(_participant); var correctOutput = IsCorrectOutput(runResult); var timeDifference = TimeDifferenceHelper.GetTimeDifference(_participant.Progress.StartTime); var score = ScoreHelper.CreateScore(_participant.Progress.Assignment, _participant, correctOutput, timeDifference); _context.Scores.Add(score); _context.Progresses.Remove(_participant.Progress); _context.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.Created)); }