public AnnualTaskDoc AddBody(AnnualTaskDoc doc) { var task = _ctx.AnnualTasks.FirstOrDefault(at => at.AnnualTaskId == doc.AnnualTaskId); if (null == task) { throw new NotFoundException("未找到年度任务"); } if (!task.Editable()) { throw new OtherException("申请书状态不允许上传该文档"); } var transaction = _ctx.Database.BeginTransaction(); try { //task.Status = AnnualTaskStatus.INST_CHECK; var pre = _ctx.AnnualTaskDocs.Where(atd => atd.AnnualTaskId == doc.AnnualTaskId && atd.Type == doc.Type); _ctx.AnnualTaskDocs.RemoveRange(pre); var cur = _ctx.AnnualTaskDocs.Add(doc); _ctx.SaveChanges(); transaction.Commit(); return(cur); } catch (Exception e) { transaction.Commit(); throw e; } }
public HttpResponseMessage Upload([FromUri] int annualTaskId, [FromUri] AnnualTaskDocType docType) { try { AnnualTaskDoc doc = reciveFile(annualTaskId, (AnnualTaskDocType)docType); if (docType == AnnualTaskDocType.BODY) { doc = _repository.AddBody(doc); } else if (docType == AnnualTaskDocType.ANNUAL_REPORT) { doc = _repository.AddAnnualReport(doc); //用户上传年度报告 //通知打点:发给所在单位所有管理员 //_noticeService.AddNoticeList( // _noticeService.GetInstManagerListByAnnualTaskId(doc.AnnualTaskId.Value), 49); //通知信打点:发给自己 //_noticeService.AddNotice( // _noticeService.GetUserIdByAnnualTaskId(doc.AnnualTaskId.Value), 32); } else { doc = _repository.AddAttachment(doc); } return(ResponseWrapper.SuccessResponse(doc)); } catch (Exception e) { return(ResponseWrapper.ExceptionResponse(e)); } }
public AnnualTaskDoc AddAttachment(AnnualTaskDoc doc) { var task = _ctx.AnnualTasks.FirstOrDefault(at => at.AnnualTaskId == doc.AnnualTaskId); if (!task.Editable()) { throw new OtherException("申请书状态不允许上传该文档"); } var entity = _ctx.AnnualTaskDocs.Add(doc); _ctx.SaveChanges(); return(entity); }
public AnnualTask SubmitAnnualTask(int id) { var task = _context.AnnualTasks.FirstOrDefault(at => at.AnnualTaskId == id); if (task == null) { throw new NotFoundException("未找到年度任务"); } if (!task.Editable()) { throw new OtherException("任务书状态不符合条件"); } var body = _context.AnnualTaskDocs.FirstOrDefault(atd => atd.AnnualTaskId == task.AnnualTaskId && atd.Type == AnnualTaskDocType.BODY); if (body == null) { throw new NotFoundException("未找到年度任务正文"); } var pdfName = DateTime.Now.ToFileTime() + task.Project.Name; if (!PdfHelper.CreateTaskPdf(task.AnnualTaskId.Value, body.Name, pdfName, task.Year.Value)) { throw new OtherException("生成PDF文件失败"); } var pre = _context.AnnualTaskDocs.Where(atd => atd.Type == AnnualTaskDocType.PDF && atd.AnnualTaskId == task.AnnualTaskId); _context.AnnualTaskDocs.RemoveRange(pre); AnnualTaskDoc pdf = new AnnualTaskDoc() { AnnualTaskId = task.AnnualTaskId, Name = pdfName + ".pdf", RelativeURL = body.RelativeURL.Replace(body.Name, pdfName + ".pdf"), Type = AnnualTaskDocType.PDF }; _context.AnnualTaskDocs.Add(pdf); task.Status = AnnualTaskStatus.INST_CHECK; _context.SaveChanges(); return(task); }
private static AnnualTaskDoc reciveFile(int annualTaskId, AnnualTaskDocType docType) { var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SystemConfig.AnnualTaskPathWin, annualTaskId.ToString()); //获取绝对路径 DirectoryInfo dir = Directory.CreateDirectory(path); //保存文件 string saveName = FileHelper.Upload(HttpContext.Current, dir.FullName); //生成AnnualTaskDoc对象 string url = "/" + Path.Combine(SystemConfig.AnnualTaskPathWeb, annualTaskId.ToString(), saveName).Replace(@"\", @"/"); AnnualTaskDoc doc = new AnnualTaskDoc() { RelativeURL = url, Type = docType, Name = saveName, AnnualTaskId = annualTaskId }; return(doc); }
public AnnualTaskDoc AddAnnualReport(AnnualTaskDoc doc) { var task = _ctx.AnnualTasks.Include("Project") .FirstOrDefault(at => at.AnnualTaskId == doc.AnnualTaskId); if (null == task) { throw new NotFoundException("未找到年度任务"); } if (!task.Terminable()) { throw new OtherException("申请书状态不允许上传该文档"); } var pdfName = DateTime.Now.ToFileTime() + task.Project.Name; if (!PdfHelper.ConvertTaskPdf(task.AnnualTaskId.Value, doc.Name, pdfName)) { throw new OtherException("生成PDF文档错误"); } doc.RelativeURL = doc.RelativeURL.Replace(doc.Name, pdfName + ".pdf"); doc.Name = pdfName + ".pdf"; var pre = _ctx.AnnualTaskDocs.Where(atd => atd.AnnualTaskId == doc.AnnualTaskId && atd.Type == AnnualTaskDocType.ANNUAL_REPORT); _ctx.AnnualTaskDocs.RemoveRange(pre); var cur = _ctx.AnnualTaskDocs.Add(doc); task.Status = AnnualTaskStatus.INST_REVIEW_ANNUAL_REPORT; _ctx.SaveChanges(); return(cur); }