private async Task <Pdf> GenerateOrganizationAgreementAttachmentAsync(int siteId) { var careSetting = await _context.Sites .Where(s => s.Id == siteId) .Select(s => s.CareSettingCode) .SingleOrDefaultAsync(); if (careSetting == null) { return(null); } var agreementType = _organizationService.OrgAgreementTypeForSiteSetting(careSetting.Value); var agreementDto = await _context.Sites .Where(s => s.Id == siteId) .SelectMany(s => s.Organization.Agreements) .Where(a => a.AgreementVersion.AgreementType == agreementType && a.AcceptedDate.HasValue) .OrderByDescending(a => a.AcceptedDate) .Select(a => new { OrganizationName = a.Organization.Name, a.AcceptedDate, a.SignedAgreement }) .FirstOrDefaultAsync(); if (agreementDto == null) { return(null); } byte[] fileData = null; if (agreementDto.SignedAgreement == null) { var html = await _agreementService.RenderOrgAgreementHtmlAsync(agreementType, agreementDto.OrganizationName, agreementDto.AcceptedDate, true); fileData = _pdfService.Generate(html); } else { fileData = await _documentClient.GetFileAsync(agreementDto.SignedAgreement.DocumentGuid); if (fileData == null) { return(await ApologyDocument(agreementDto.SignedAgreement.Filename)); } if (!agreementDto.SignedAgreement.HasFileExtension("pdf")) { var html = await _razorConverterService.RenderTemplateToStringAsync(RazorTemplates.Document, new File(agreementDto.SignedAgreement.Filename, fileData)); fileData = _pdfService.Generate(html); } } return(new Pdf("OrganizationAgreement.pdf", fileData)); }
public async Task <IActionResult> GetDocumentByAccessToken(Guid accessTokenId) { var documentAccessToken = await _documentAccessTokenService.GetDocumentAccessNoTrackingAsync(accessTokenId); if (documentAccessToken == null) { return(NotFound()); } var response = await _documentManagerClient.GetFileAsync(documentAccessToken.DocumentGuid); if (response == null) { return(NotFound()); } Response.Headers.Add("Content-Disposition", response.Content.Headers.ContentDisposition.ToString()); return(File(await response.Content.ReadAsStreamAsync(), "application/octet-stream")); }
public async Task <Stream> GetStreamForLatestBusinessLicenceDocument(int siteId) { var licence = await _siteService.GetLatestBusinessLicenceAsync(siteId); return(await _documentManagerClient.GetFileAsync(licence.DocumentGuid)); }