Esempio n. 1
0
        public IActionResult GetCertificate(int courseId)
        {
            var course = courseService.Get(courseId);

            course = null;
            var email = User.FindFirst("Email");
            var user  = userService.Get(email.Value);

            if (course == null || user == null)
            {
                return(View(nameof(Index)));
            }

            try
            {
                string file_type = "application/pdf";
                string file_name = "certificate.pdf";
                return(File(certificateService.CreateFilePDF(course.CourseId, user.UserId), file_type, file_name));
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(nameof(Index)));
            }
        }