Пример #1
0
        public ActionResult CertificateById(Guid certificateId)
        {
            var redirect = this.GetRedirectToUrlWithTrailingSlash();

            if (redirect != null)
            {
                return(RedirectPermanent(redirect));
            }

            var certificate = certificatesRepo.FindCertificateById(certificateId);

            if (certificate == null)
            {
                return(HttpNotFound());
            }

            if (certificate.IsPreview && !User.HasAccessFor(certificate.Template.CourseId, CourseRole.Instructor))
            {
                return(HttpNotFound());
            }

            var course = courseManager.GetCourse(certificate.Template.CourseId);

            certificateGenerator.EnsureCertificateTemplateIsUnpacked(certificate.Template);

            var certificateUrl      = Url.RouteUrl("Certificate", new { certificateId = certificate.Id }, Request.GetRealScheme());
            var renderedCertificate = certificateGenerator.RenderCertificate(certificate, course, certificateUrl);

            return(View("Certificate", new CertificateViewModel
            {
                Course = course,
                Certificate = certificate,
                RenderedCertificate = renderedCertificate,
            }));
        }