private async Task <string> BuildExercise(User user, Models.Exercises.Exercise exercise, UserSolutionsReportOptions options) { var builder = new StringBuilder(); builder.AppendLine($"## {exercise.ExerciseName}"); builder.AppendLine(exercise.ExerciseTask); builder.AppendLine(); var solutionsForExercise = await LoadSolutionsForExercise(exercise.ExerciseID, user.Id); switch (options.SolutionsMode) { case ShowSolutionsMode.AllByDescendingStatus: foreach (var(solution, i) in solutionsForExercise.Select((s, i) => (s, i + 1))) { builder.AppendLine($"### Solution #{i}"); RenderSolution(builder, solution, options.ShowChecks); } break; case ShowSolutionsMode.OnlyBest: builder.AppendLine($"### Best solution"); RenderSolution(builder, solutionsForExercise[0], options.ShowChecks); break; } ; builder.AppendLine("---"); builder.AppendLine(); return(builder.ToString()); }
public async Task <string> CreateMarkdownReport(string userStudentId, Guid challengeId, UserSolutionsReportOptions options = null) { var user = await dbContext.Users.SingleOrDefaultAsync(u => u.StudentID == userStudentId) ?? throw new ArgumentException($"Not found user {userStudentId}"); var challenge = await dbContext.Challenges.SingleOrDefaultAsync(c => c.Id == challengeId) ?? throw new ArgumentException($"Not found challeng {challengeId}"); options ??= defaultOptions; var builder = new StringBuilder(); builder.AppendLine($"## Report about **{challenge.Name}** for **{(options.ShowName ? user.FirstName : user.StudentID)}**"); builder.AppendLine($"### Additional info"); builder.AppendLine($"Field | Value"); builder.AppendLine($"- | -"); builder.AppendLine($"Student ID | {user.StudentID}"); builder.AppendLine($"User ID | {user.Id}"); builder.AppendLine($"Challenge ID | {challenge.Id}"); var exercises = await dbContext.Exercises .Where(e => e.ChallengeId == challenge.Id) .Where(e => e.Solutions.Any(s => s.UserId == user.Id)) .OrderBy(e => e.ExerciseName) .ToListAsync(); var exerciseBlocks = new List <(SolutionStatus status, string view)>(); foreach (var exercise in exercises) { builder.AppendLine(await BuildExercise(user, exercise, options)); } return(builder.ToString()); }