Пример #1
0
        public async Task <ActionResult <FileStream> > Download(int id)
        {
            var certificate = await _certificatesRepository.FindByIdAsync(id);

            if (certificate is null)
            {
                return(NotFound($"No existe un certificado con el id {id}"));
            }

            var serviceNames = certificate.WorkOrder.Activity.ActivitiesServices
                               .Select(a => a.Service).Select(s => s.Name);

            var stream = _pdfGenerator.GenerateCertificate(certificate.Id,
                                                           certificate.WorkOrder.Activity.Client.TradeName, certificate.WorkOrder.Activity.Client.NIT,
                                                           certificate.WorkOrder.ExecutionDate, string.Join(", ", serviceNames));

            stream.Position = 0;

            return(File(stream, "application/octet-stream"));
        }