Removed ILogger dependency and all related logging from ReportCreator. Inlined DoCreateReport into CreateReportAsync and eliminated the try-catch block, allowing exceptions to propagate naturally. Improved the error message for missing report data. The class is now more focused and streamlined.
47 lines
1.9 KiB
C#
47 lines
1.9 KiB
C#
using DevExpress.Xpo;
|
|
using DigitalData.Core.Abstraction.Application.Repository;
|
|
using EnvelopeGenerator.Domain.Constants;
|
|
using EnvelopeGenerator.Domain.Entities;
|
|
using EnvelopeGenerator.ServiceHost.Exceptions;
|
|
|
|
namespace EnvelopeGenerator.ServiceHost.Jobs.FinalizeDocument;
|
|
|
|
public class ReportCreator(IRepository<EnvelopeReport> reportRepo)
|
|
{
|
|
public async Task<byte[]> CreateReportAsync(Envelope envelope, CancellationToken cancel = default)
|
|
{
|
|
var reports = await reportRepo.Where(r => r.EnvelopeId == envelope.Id).ToListAsync(cancel);
|
|
|
|
if (reports.Count == 0)
|
|
throw new CreateReportException("Could not prepare report data! No report data found!");
|
|
|
|
var items = reports
|
|
.Select(r => ToReportItem(r, envelope))
|
|
.OrderByDescending(r => r.ItemDate)
|
|
.ToList();
|
|
|
|
var source = new ReportSource { Items = items };
|
|
var report = new rptEnvelopeHistory { DataSource = source, DataMember = "Items" };
|
|
report.CreateDocument();
|
|
using var stream = new MemoryStream();
|
|
report.ExportToPdf(stream);
|
|
return stream.ToArray();
|
|
}
|
|
|
|
private static ReportItem ToReportItem(EnvelopeReport report, Envelope envelope)
|
|
{
|
|
return new ReportItem
|
|
{
|
|
CreatorFullName = envelope.User is not null
|
|
? $"{envelope.User.Prename} {envelope.User.Name}".Trim()
|
|
: string.Empty,
|
|
CreatorEmailAddress = envelope.User?.Email ?? string.Empty,
|
|
EnvelopeTitle = report.HeadTitle ?? string.Empty,
|
|
EnvelopeUuid = report.HeadUuid ?? string.Empty,
|
|
EnvelopeCertificationType = envelope.CertificationType is int certType ? ((CertificationType)certType).ToString() : "null",
|
|
ItemStatus = (EnvelopeStatus)report.PosStatus,
|
|
ItemUserReference = report.PosWho ?? string.Empty,
|
|
ItemDate = report.PosWhen ?? DateTime.MinValue
|
|
};
|
|
}
|
|
} |