public async Task <HandlingReportCollection> GetHandlingReport() { const string Query = @" select [Containers].Customer, [Handlings].HandlingType, Count([Handlings].HandlingType) as HandlingAmount from Handlings INNER JOIN [Containers] on [Handlings].[ContainerId] = [Containers].[Id] GROUP BY [Containers].Customer, [Handlings].[HandlingType] ORDER BY [Containers].Customer, [Handlings].[HandlingType]"; IEnumerable <HandlingReportEntry> entries = await _connection .QueryAsync <HandlingReportEntry>(Query); IEnumerable <HandlingReport> data = entries.GroupBy(report => report.Customer) .Select(reportGroup => new HandlingReport { Customer = reportGroup.Key, ReportEntries = reportGroup.AsList() }); const string QueryImportationCount = @" select Count(*) from [Containers] where [Category] = 0"; const string QueryExportationCount = @" select Count(*) from [Containers] where [Category] = 1"; int totalImportation = await _connection.ExecuteScalarAsync <int>(QueryImportationCount); int totalExportation = await _connection.ExecuteScalarAsync <int>(QueryExportationCount); var reportCollection = new HandlingReportCollection { Data = data, TotalExportation = totalExportation, TotalImportation = totalImportation }; return(reportCollection); }
public async Task <ActionResult <HandlingReportCollectionViewModel> > GetHandlingReport() { HandlingReportCollection report = await _reportRepository.GetHandlingReport(); return(_mapper.Map <HandlingReportCollectionViewModel>(report)); }