/* TODO(andgein): Remove isRightAnswer? */ public async Task<UserExerciseSubmission> AddUserExerciseSubmission(string courseId, Guid slideId, string code, bool isRightAnswer, string compilationError, string output, string userId, string executionServiceName, string displayName) { if (string.IsNullOrWhiteSpace(code)) code = "// no code"; var hash = (await textsRepo.AddText(code)).Hash; var compilationErrorHash = (await textsRepo.AddText(compilationError)).Hash; var outputHash = (await textsRepo.AddText(output)).Hash; var automaticChecking = new AutomaticExerciseChecking { CourseId = courseId, SlideId = slideId, UserId = userId, Timestamp = DateTime.Now, CompilationErrorHash = compilationErrorHash, IsCompilationError = !string.IsNullOrWhiteSpace(compilationError), OutputHash = outputHash, ExecutionServiceName = executionServiceName, DisplayName = displayName, Status = AutomaticExerciseCheckingStatus.Waiting, IsRightAnswer = isRightAnswer, }; db.AutomaticExerciseCheckings.Add(automaticChecking); var submission = new UserExerciseSubmission { CourseId = courseId, SlideId = slideId, UserId = userId, Timestamp = DateTime.Now, SolutionCodeHash = hash, CodeHash = code.Split('\n').Select(x => x.Trim()).Aggregate("", (x, y) => x + y).GetHashCode(), Likes = new List<Like>(), AutomaticChecking = automaticChecking, AutomaticCheckingIsRightAnswer = isRightAnswer, }; db.UserExerciseSubmissions.Add(submission); try { await db.SaveChangesAsync(); } catch (DbEntityValidationException e) { log.Error(e); throw new Exception( string.Join("\r\n", e.EntityValidationErrors.SelectMany(v => v.ValidationErrors).Select(err => err.PropertyName + " " + err.ErrorMessage))); } return submission; }
private RunnerSubmission ToRunnerSubmition(UserExerciseSubmission submission) { if (submission.IsWebSubmission) { return new FileRunnerSubmission { Id = submission.Id.ToString(), Code = submission.SolutionCode.Text, Input = "", NeedRun = true }; } var exerciseSlide = (ExerciseSlide)courseManager .GetCourse(submission.CourseId) .GetSlideById(submission.SlideId); courseManager.WaitWhileCourseIsLocked(submission.CourseId); return exerciseSlide.Exercise.CreateSubmition( submission.Id.ToString(), submission.SolutionCode.Text); }
private ExerciseBlockData CreateExerciseBlockData(Course course, Slide slide, UserExerciseSubmission submission, bool onlyAccepted, string currentUserId) { var userId = submission?.UserId ?? currentUserId; var visit = visitsRepo.FindVisiter(course.Id, slide.Id, userId); var solution = submission?.SolutionCode.Text; var submissionReviews = submission?.ManualCheckings.LastOrDefault()?.NotDeletedReviews; var hasUncheckedReview = submission?.ManualCheckings.Any(c => !c.IsChecked) ?? false; var hasCheckedReview = submission?.ManualCheckings.Any(c => c.IsChecked) ?? false; var reviewState = hasCheckedReview ? ExerciseReviewState.Reviewed : hasUncheckedReview ? ExerciseReviewState.WaitingForReview : ExerciseReviewState.NotReviewed; var submissions = onlyAccepted ? solutionsRepo.GetAllAcceptedSubmissionsByUser(course.Id, slide.Id, userId) : solutionsRepo.GetAllSubmissionsByUser(course.Id, slide.Id, userId); var topUserReviewComments = slideCheckingsRepo.GetTopUserReviewComments(course.Id, slide.Id, currentUserId, 10); return new ExerciseBlockData(course.Id, (ExerciseSlide) slide, visit?.IsSkipped ?? false, solution) { Url = Url, Reviews = submissionReviews?.ToList() ?? new List<ExerciseCodeReview>(), ReviewState = reviewState, IsGuest = false, SubmissionSelectedByUser = submission, Submissions = submissions.ToList(), TopUserReviewComments = topUserReviewComments, }; }
public async Task RemoveSubmission(UserExerciseSubmission submission) { if (submission.Likes != null) db.SolutionLikes.RemoveRange(submission.Likes); if (submission.AutomaticChecking != null) db.AutomaticExerciseCheckings.Remove(submission.AutomaticChecking); if (submission.ManualCheckings != null) db.ManualExerciseCheckings.RemoveRange(submission.ManualCheckings); db.UserExerciseSubmissions.Remove(submission); await db.SaveChangesAsync(); }