public static ReportData <Row> build(Guid orgId, Guid projId, DateTime?startDate, DateTime?endDate) { var repo = new ReportsRepository(); var allRisks = new RiskMapRepository(orgId).RisksCurrentAndDeleted(); var clients = repo.findClients(projId, null).Include(c => c.Address); var rows = new List <Row>(); foreach (var client in clients) { if (!Reports.activeBetweenDates(client, startDate, endDate)) { continue; } if (client.RiskAssessments == null || client.RiskAssessments.Count == 0) { continue; } var postCode = Reports.firstPartOfPostCode(client); foreach (var rad in client.RiskAssessments) { var row = findRow(rows, postCode); row.bump(); var assessed = rad.Risks().Select(riskId => allRisks.Where(r => r.Id == riskId).Single().Title).ToList(); row.assessed(assessed); var resolved = rad.ResolvedRisks().Select(riskId => allRisks.Where(r => r.Id == riskId).Single().Title).ToList(); row.resolved(resolved); var managed = rad.ManagedRisks().Select(riskId => allRisks.Where(r => r.Id == riskId).Single().Title).ToList(); row.managed(managed); } // foreach RiskAssessment } // foreach Client rows.Sort((lhs, rhs) => postCodeOrder(lhs.PostCode, rhs.PostCode)); var reportData = new ReportData <Row>(rows); reportData.Put("project", repo.projectName(projId)); reportData.Put("startDate", Reports.formatDate(startDate)); reportData.Put("endDate", Reports.formatDate(endDate)); reportData.Put("csvurl", Reports.csvUrl("opendata", orgId, projId, null, startDate, endDate)); return(reportData); } // build
private static string postCode(Client c) { return Reports.firstPartOfPostCode(c); }