Esempio n. 1
0
        /// <summary>
        /// 保存申请书,主要操作是生成申请书PDF文档,将申请书的状态修改为ApplicationStatus.NEW
        /// </summary>
        /// <param name="applicationId">申请书ID</param>
        /// <returns>
        /// 成功,返回ResponseStatus.success,
        /// 没有找申请书,返回ResponseStatus.parameter_error,
        /// 出错,返回ResponseStatus.unknown_error和错误信息
        /// </returns>
        public GetApplicationDTO SaveApplication(string applicationId, Func <Application, CurrentUser, bool> privilege)
        {
            using (var ctx = new AspodesDB())
            {
                //取出申请书信息
                Application application = ctx.Applications.FirstOrDefault(a => a.ApplicationId == applicationId);
                if (null == application)
                {
                    throw new NotFoundException("未找到申请书");
                }

                if (!privilege(application, UserHelper.GetCurrentUser()))
                {
                    throw new UnauthorizationException();
                }

                //生成申请书PDF文档
                var body   = ctx.ApplicationDocs.FirstOrDefault(ad => ad.ApplicationId == application.ApplicationId && ad.Type == ApplicationDocType.BODY);
                var oldPdf = ctx.ApplicationDocs.FirstOrDefault(ad => ad.ApplicationId == application.ApplicationId && ad.Type == ApplicationDocType.PDF);
                if (null != oldPdf)
                {
                    ApplicationDocRepository.Delete(oldPdf.ApplicationDocId.Value, (a, u) => true);
                }

                var  pdfName   = body.Name.Replace(".docx", "") + "PDF";
                bool createPDF = PdfHelper.CreatePdf(application.ApplicationId, body.RelativeURL, pdfName, SystemConfig.ApplicationStartYear);
                if (!createPDF)
                {
                    throw new OtherException("PDF生成失败");
                }
                //添加PDF文档记录
                ApplicationDoc pdf = new ApplicationDoc()
                {
                    Name          = pdfName + ".pdf",
                    RelativeURL   = body.RelativeURL.Replace(body.Name, pdfName + ".pdf"),
                    Type          = ApplicationDocType.PDF,
                    ApplicationId = applicationId
                };
                ctx.ApplicationDocs.Add(pdf);
                //修改申请书状态
                application.Status = ApplicationStatus.NEW;
                ctx.SaveChanges();

                return(Mapper.Map <GetApplicationDTO>(application));
            }
        }
Esempio n. 2
0
        public void CreateApplicationPDF(string applicationId)
        {
            using (var ctx = new AspodesDB())
            {
                //取出申请书信息
                Application application = ctx.Applications.FirstOrDefault(a => a.ApplicationId == applicationId);
                if (null == application)
                {
                    throw new NotFoundException("未找到申请书");
                }

                //生成申请书PDF文档
                var body   = ctx.ApplicationDocs.FirstOrDefault(ad => ad.ApplicationId == application.ApplicationId && ad.Type == ApplicationDocType.BODY);
                var oldPdf = ctx.ApplicationDocs.FirstOrDefault(ad => ad.ApplicationId == application.ApplicationId && ad.Type == ApplicationDocType.PDF);
                if (null != oldPdf)
                {
                    ApplicationDocRepository.Delete(oldPdf.ApplicationDocId.Value, (a, u) => true);
                }

                var  pdfName   = body.Name.Replace(".docx", "") + "PDF";
                bool createPDF = PdfHelper.CreatePdf(application.ApplicationId, body.Name, pdfName, SystemConfig.ApplicationStartYear);
                if (!createPDF)
                {
                    throw new OtherException("PDF生成失败");
                }
                //添加PDF文档记录
                ApplicationDoc pdf = new ApplicationDoc()
                {
                    Name          = pdfName + ".pdf",
                    RelativeURL   = body.RelativeURL.Replace(body.Name, pdfName + ".pdf"),
                    Type          = ApplicationDocType.PDF,
                    ApplicationId = applicationId
                };
                ctx.ApplicationDocs.Add(pdf);

                ctx.SaveChanges();
            }
        }