private ICollection <RepositoryReport> Analyze(
            IReadOnlyCollection <Repository> repositories,
            Dictionary <int, PackageVersion> latestPackageVersions)
        {
            List <RepositoryReport> repositoriesVersionReports
                = repositories.Select(RepositoryConverter.RepositoryToRepositoryVersionReport).ToList();

            for (int i = 0; i < repositories.Count; i++)
            {
                List <Solution> solutions = repositories
                                            .ElementAt(i)
                                            .Solutions
                                            .ToList();

                for (int j = 0; j < solutions.Count; j++)
                {
                    List <Project> projects = solutions[j]
                                              .Projects
                                              .ToList();

                    for (int k = 0; k < projects.Count; k++)
                    {
                        List <PackageVersionComparisonReport> reports = projects[k]
                                                                        .ProjectPackageVersions
                                                                        .Select(projectPackageVersion => versionsService
                                                                                .Compare(latestPackageVersions[projectPackageVersion.PackageVersion.PackageId],
                                                                                         projectPackageVersion.PackageVersion))
                                                                        .ToList();

                        repositoriesVersionReports[i].Solutions[j].Projects[k].Report = versionsService.CalculateMaxReportLevelStatus(reports);
                    }

                    repositoriesVersionReports[i].Solutions[j].Report = versionsService
                                                                        .CalculateMaxReportLevelStatus(repositoriesVersionReports[i]
                                                                                                       .Solutions[j].Projects
                                                                                                       .Select(projectVersionReport => projectVersionReport.Report)
                                                                                                       .ToList());
                }

                repositoriesVersionReports[i].Report = versionsService
                                                       .CalculateMaxReportLevelStatus(repositoriesVersionReports[i]
                                                                                      .Solutions
                                                                                      .Select(solutionVersionReport => solutionVersionReport.Report)
                                                                                      .ToList());
            }

            return(repositoriesVersionReports);
        }
        public async Task <ProjectReport> GetProjectReportAsync(int projectId)
        {
            Project project = await ProjectRepository.GetByIdWithIncludedPackageAsync(projectId);

            if (project == null)
            {
                return(null);
            }

            IEnumerable <PackageVersion> currentPackageVersions = project
                                                                  .ProjectPackageVersions
                                                                  .Select(projectPackageVersion => projectPackageVersion.PackageVersion);

            IReadOnlyCollection <PackageVersion> latestPackageVersions = await PackageVersionsRepository
                                                                         .GetLatestVersionsAsync(x => currentPackageVersions
                                                                                                 .Select(p => p.PackageId)
                                                                                                 .Contains(x.PackageId));

            List <PackageReport> packageReports = new List <PackageReport>();

            foreach (PackageVersion packageVersion in currentPackageVersions)
            {
                PackageVersion latestVersion        = latestPackageVersions.FirstOrDefault(p => p.PackageId == packageVersion.PackageId);
                PackageReport  packageVersionReport = new PackageReport
                {
                    Id                    = packageVersion.PackageId,
                    LastUpdateTime        = packageVersion.Package.LastUpdateTime,
                    Name                  = packageVersion.Package.Name,
                    CurrentPackageVersion = PackageVersionConverter.PackageVersionToPackageVersionDto(packageVersion),
                    LatestPackageVersion  = PackageVersionConverter.PackageVersionToPackageVersionDto(latestVersion),
                    Report                = versionsAnalyzerService.Compare(latestVersion, packageVersion)
                };
                packageReports.Add(packageVersionReport);
            }

            ProjectReport projectReport = new ProjectReport
            {
                Name     = project.Name,
                Id       = project.Id,
                Packages = packageReports,
                Report   = versionsAnalyzerService
                           .CalculateMaxReportLevelStatus(packageReports.Select(p => p.Report).ToList())
            };

            return(projectReport);
        }