public ActionResult AddOffice() { using (var db = new XkSystem.Models.DbContext()) { var vm = new Models.Office.OfficeEditModel(); return(View(vm)); } }
public ActionResult AddOffice(Models.Office.OfficeEditModel vm) { using (var db = new XkSystem.Models.DbContext()) { if (string.IsNullOrEmpty(vm.OfficeEditDto.OfficeFileName) && !string.IsNullOrEmpty(vm.OfficeEditDto.FileContent)) { ModelState.Remove("OfficeEditDto.OfficeFileName"); } else if (!string.IsNullOrEmpty(vm.OfficeEditDto.OfficeFileName) && string.IsNullOrEmpty(vm.OfficeEditDto.FileContent)) { ModelState.Remove("OfficeEditDto.FileContent"); } else if (string.IsNullOrEmpty(vm.OfficeEditDto.OfficeFileName) && string.IsNullOrEmpty(vm.OfficeEditDto.FileContent)) { ModelState.Remove("OfficeEditDto.FileContent"); } var error = new List <string>(); if (error.Count == decimal.Zero) { //保存附件,rar,word(doc),pdf string FileName = string.Empty; if (!string.IsNullOrEmpty(vm.OfficeEditDto.OfficeFileName)) { var file = Request.Files[nameof(vm.OfficeEditDto) + "." + nameof(vm.OfficeEditDto.OfficeFileName)]; var suffix = file.FileName.Substring(file.FileName.LastIndexOf(".")); FileName = System.IO.Path.GetRandomFileName().Replace(".", string.Empty) + suffix; vm.OfficeEditDto.OfficeFileName = file.FileName; file.SaveAs(Server.MapPath("~/Files/OfficeFile/") + FileName); } //审批内容表记录 var tb = new Wechat.Entity.tbWeOAOffice(); tb.OfficeFileFrom = vm.OfficeEditDto.OfficeFileFrom; tb.OfficeFileName = vm.OfficeEditDto.OfficeFileName; tb.OfficeFileNameSeq = FileName; tb.ReceiveFileTime = vm.OfficeEditDto.ReceiveFileTime; tb.Title = vm.OfficeEditDto.Title; tb.FileContent = vm.OfficeEditDto.FileContent; tb.LimitDateTo = vm.OfficeEditDto.LimitDateTo; db.Set <Wechat.Entity.tbWeOAOffice>().Add(tb); db.SaveChanges(); //执行流程引擎 OAWeWorkFlow.ExecuteWorkFlowEngine(db, flowTypeCode, tb.Id, "", "发起流程", false, vm.OfficeEditDto.NextApproveUserId); } else { vm.ErrorMsg = string.Join("\r\n", error); return(View(vm));//包含文件表单的方式 } return(Content("<script type='text/javascript'> window.parent.location.href = '" + Url.Action("OfficeIndex", "Office", new { area = "wechat" }) + "';</script>")); } }