protected override async Task <byte[]> Handle(RequestContext context, GenerateReportCommand request, CancellationToken cancellationToken) { var errand = await GetErrand(request.ErrandId, cancellationToken) ?? throw new NotFoundException("Завдання не знайдено."); var providerSignature = await fileStorage.ReadFile(Path.Combine("signatures", context.CurrentUser.UserId.ToString())); var providerSeal = await fileStorage.ReadFile(Path.Combine("seals", context.CurrentUser.UserId.ToString())); reportBuilder .AddVerticalSpace() .AddText(errand.Provider.ProviderName, Align.Center, 32) .AddSignature(providerSignature) .AddSeal(providerSeal) .AddVerticalSpace() .AddVerticalSpace() .AddText(errand.Facility.GetInfo(), Align.Center, 24) .AddVerticalSpace() .AddText(errand.Description, Align.Center, 20) .AddVerticalSpace(); foreach (var grouped in errand.PointReviewHistory .OrderBy(p => p.PerimeterId) .ThenBy(p => p.TrapId) .GroupBy(p => new { p.Perimeter, p.Trap, p.Supplement })) { reportBuilder .AddVerticalSpace() .AddText($"Периметр - {grouped.Key.Perimeter.PerimeterName}, {grouped.Key.Trap.TrapName} - {grouped.Key.Supplement.SupplementName}", Align.Center, 20) .AddVerticalSpace(); var tableColumns = new List <Column> { new Column(1, "№ п/п", grouped.Key.Trap.Color) }; tableColumns.AddRange(grouped.Key.Trap.Fields.OrderBy(f => f.Order).Select(f => new Column(f.Order + 1, f.FieldName))); var table = new Table(tableColumns); foreach (var point in grouped.OrderBy(p => p.PointOrder)) { Row row = table.NewRow(); row[tableColumns[0]] = point.PointOrder.ToString(); foreach (var record in point.Records) { row[tableColumns[record.Field.Order]] = record.GetValue(); } } reportBuilder .AddTable(table) .AddVerticalSpace() .AddVerticalSpace(); } return(reportBuilder.GetReport()); }