public async Task <ActionResult <byte[]> > GetAccessTermSignable(int enrolleeId, int agreementId)
        {
            var record = await _enrolleeService.GetPermissionsRecordAsync(enrolleeId);

            if (record == null)
            {
                return(NotFound(ApiResponse.Message($"Enrollee not found with id {enrolleeId}")));
            }
            if (!record.ViewableBy(User))
            {
                return(Forbid());
            }

            Agreement agreement = await _agreementService.GetEnrolleeAgreementAsync(enrolleeId, agreementId, true);

            if (agreement == null)
            {
                return(NotFound(ApiResponse.Message($"Agreement not found with id {agreementId} on enrollee with id {enrolleeId}")));
            }

            var html = await _razorConverterService.RenderViewToStringAsync("/Views/TermsOfAccessPdf.cshtml", agreement);

            var download = _pdfService.Generate(html);

            return(Ok(ApiResponse.Result(download)));
        }
示例#2
0
        /// <summary>
        /// Gets the Agreement + text of a given Org Agreement, optionally with the text in the form of a Base 64 encoded PDF.
        /// Returns null if the Agreement does not exist on the given organization.
        /// </summary>
        /// <param name="organizationId"></param>
        /// <param name="agreementId"></param>
        /// <param name="asEncodedPdf"></param>
        /// <returns></returns>
        public async Task <AgreementViewModel> GetOrgAgreementAsync(int organizationId, int agreementId, bool asEncodedPdf = false)
        {
            var agreementVm = await _context.Agreements
                              .AsNoTracking()
                              .Where(a => a.Id == agreementId && a.OrganizationId == organizationId)
                              .ProjectTo <AgreementViewModel>(_mapper.ConfigurationProvider)
                              .SingleOrDefaultAsync();

            if (agreementVm == null)
            {
                return(null);
            }

            var orgName = await _context.Organizations
                          .Where(o => o.Id == organizationId)
                          .Select(o => o.Name)
                          .SingleAsync();

            var html = await RenderOrgAgreementHtmlAsync(agreementVm.AgreementType, orgName, agreementVm.AcceptedDate, asEncodedPdf);

            if (asEncodedPdf)
            {
                var pdf = _pdfService.Generate(html);
                agreementVm.AgreementContent = Convert.ToBase64String(pdf);
            }
            else
            {
                agreementVm.AgreementContent = html;
            }

            return(agreementVm);
        }
示例#3
0
        private async Task <Pdf> GenerateRegistrationReviewAttachmentAsync(int siteId)
        {
            // TODO use Automapper
            var model = await _context.Sites
                        .Where(s => s.Id == siteId)
                        .Select(s => new SiteRegistrationReviewViewModel
            {
                OrganizationName            = s.Organization.Name,
                OrganizationRegistrationId  = s.Organization.RegistrationId,
                OrganizationDoingBusinessAs = s.Organization.DoingBusinessAs,
                SiteName      = s.DoingBusinessAs,
                SiteAddress   = s.PhysicalAddress,
                BusinessHours = s.BusinessHours.Select(h => new BusinessHourViewModel
                {
                    Day       = h.Day,
                    StartTime = h.StartTime,
                    EndTime   = h.EndTime
                }),
                Vendors = s.SiteVendors.Select(sv => new VendorViewModel
                {
                    Name  = sv.Vendor.Name,
                    Email = sv.Vendor.Email
                }),
                RemoteUsers = s.RemoteUsers.Select(ru => new RemoteUserViewModel
                {
                    FullName       = $"{ru.FirstName} {ru.LastName}",
                    Certifications = ru.RemoteUserCertifications.Select(c => new CertViewModel
                    {
                        CollegeName   = c.College.Name,
                        LicenceNumber = c.LicenseNumber
                    })
                }),
                SigningAuthority = new ContactViewModel
                {
                    JobTitle = s.Provisioner.JobRoleTitle,
                    FullName = $"{s.Provisioner.FirstName} {s.Provisioner.LastName}",
                    Phone    = s.Provisioner.Phone,
                    Fax      = s.Provisioner.Fax,
                    SmsPhone = s.Provisioner.SMSPhone,
                    Email    = s.Provisioner.Email
                },
                AdministratorOfPharmaNet = new ContactViewModel
                {
                    JobTitle = s.AdministratorPharmaNet.JobRoleTitle,
                    FullName = $"{s.AdministratorPharmaNet.FirstName} {s.AdministratorPharmaNet.LastName}",
                    Phone    = s.AdministratorPharmaNet.Phone,
                    Fax      = s.AdministratorPharmaNet.Fax,
                    SmsPhone = s.AdministratorPharmaNet.SMSPhone,
                    Email    = s.AdministratorPharmaNet.Email
                },
                PrivacyOfficer = new ContactViewModel
                {
                    JobTitle = s.PrivacyOfficer.JobRoleTitle,
                    FullName = $"{s.PrivacyOfficer.FirstName} {s.PrivacyOfficer.LastName}",
                    Phone    = s.PrivacyOfficer.Phone,
                    Fax      = s.PrivacyOfficer.Fax,
                    SmsPhone = s.PrivacyOfficer.SMSPhone,
                    Email    = s.PrivacyOfficer.Email
                },
                TechnicalSupport = new ContactViewModel
                {
                    JobTitle = s.TechnicalSupport.JobRoleTitle,
                    FullName = $"{s.TechnicalSupport.FirstName} {s.TechnicalSupport.LastName}",
                    Phone    = s.TechnicalSupport.Phone,
                    Fax      = s.TechnicalSupport.Fax,
                    SmsPhone = s.TechnicalSupport.SMSPhone,
                    Email    = s.TechnicalSupport.Email
                },
            })
                        .SingleAsync();

            var html = await _razorConverterService.RenderTemplateToStringAsync(RazorTemplates.SiteRegistrationReview, model);

            return(new Pdf("SiteRegistrationReview.pdf", _pdfService.Generate(html)));
        }