Esempio n. 1
0
        public void AddApplicationBody(ApplicationDoc doc, Func <Application, CurrentUser, bool> privilege)
        {
            if (!PdfHelper.Check(doc.ApplicationId, doc.RelativeURL))
            {
                throw new OtherException("申请书正文格式错误");
            }

            //保存到数据库
            using (var ctx = new AspodesDB())
            {
                var application = ctx.Applications.FirstOrDefault(a => a.ApplicationId == doc.ApplicationId);
                if (null == application)
                {
                    throw new NotFoundException("未找到申请书");
                }

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

                var pre = ctx.ApplicationDocs.Where(ad => ad.ApplicationId == doc.ApplicationId && ad.Type == doc.Type);

                //申请书正文只有一份,附件可以有多份
                ctx.ApplicationDocs.Add(doc);
                ctx.ApplicationDocs.RemoveRange(pre);
                ctx.SaveChanges();
            }
        }