Example #1
0
        public ActionResult DownloadTestCertificate(decimal orderDetailId, bool second)
        {
            var orderDetail = OrderDetailsService.FirstOrDefault(x =>
                                                                 x.OrderDetailID == orderDetailId && BerthTypes.AllPaidForTestCerts.Contains(x.StudentInGroup.BerthType_TC));
            var userTestId = orderDetail.UserTestId.Value;

            UserTestService.LoadWith(x => x.Test, x => x.TestPassRule);
            var userTest = UserTestService.GetByPK(userTestId);

            TestCertificatePermission(orderDetail, userTest);
            var certificateFileSys = UserImages.GetTestCertFileSys(userTestId);

            try {
                System.IO.File.Delete(certificateFileSys);
            } catch (Exception e) {
                return(Content("Сертификат уже скачивается"));
            }
            var isEng = orderDetail.Params.Lang == TestCertLang.Eng;

            if (orderDetail.Params.Lang == TestCertLang.RusEng && second)
            {
                isEng = true;
            }
            using (var image = Image.FromFile(UserImages.GetTestCertFileSys(isEng ? 0 : 1))) {
                using (var result = ImageUtils.DrawTestString(image,
                                                              isEng ? User.EngFullName : User.FullName,
                                                              EntityUtils.GetTestCertName(isEng, userTest), userTest.RunDate.DefaultString(), userTest.Id))
                    result.Save(certificateFileSys);
            }
            return(File(certificateFileSys, "image/png", "certificate.png"));
        }