public ActionResult AddContract(Logic.Entity.Contract obj) { var re = new OpResult(); var relativePath = ""; var files = new List <Attachment>(); var path = Sys.SysConstPool.SaveAttachPath(ref relativePath); for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (file.ContentLength <= 0) { continue; } var filename = CommonRules.GUID + Path.GetExtension(file.FileName); string fullname = path + filename; file.SaveAs(fullname); files.Add(new Attachment() { SourceClassify = 1, Title = Path.GetFileName(file.FileName), Size = file.ContentLength / 1024, SaveUrl = relativePath + filename }); } var jia = new Logic.Entity.ContractBoth(); var yi = new Logic.Entity.ContractBoth(); var compname = Request["CompanyName"]; if (!compname.IsNullOrEmpty()) { var comps = compname.Split(','); jia.CompanyName = comps[0]; yi.CompanyName = comps[1]; } var representative = Request["Representative"]; if (!representative.IsNullOrEmpty()) { var repr = representative.Split(','); jia.Representative = repr[0]; yi.Representative = repr[1]; } var tel = Request["Tel"]; if (!tel.IsNullOrEmpty()) { var te = tel.Split(','); jia.Tel = te[0]; yi.Tel = te[1]; } var fax = Request["Fax"]; if (!fax.IsNullOrEmpty()) { var fa = fax.Split(','); jia.Fax = fa[0]; yi.Fax = fa[1]; } var taxnumber = Request["TaxNumber"];//甲方是TaxNumber,乙方是PayNumber,除此之外其余的项甲乙方都相同 if (!taxnumber.IsNullOrEmpty()) { jia.TaxNumber = taxnumber; } var paynumber = Request["PayNumber"];//乙方是PayNumber if (!paynumber.IsNullOrEmpty()) { yi.PayNumber = paynumber; } var url = Request["Url"]; if (!url.IsNullOrEmpty()) { var ur = url.Split(','); jia.Url = ur[0]; yi.Url = ur[1]; } var address = Request["Address"]; if (!address.IsNullOrEmpty()) { var addr = address.Split(','); jia.Address = addr[0]; yi.Address = addr[1]; } var postcode = Request["PostCode"]; if (!postcode.IsNullOrEmpty()) { var pcode = postcode.Split(','); jia.PostCode = pcode[0]; yi.PostCode = pcode[1]; } var bankname = Request["BankName"]; if (!bankname.IsNullOrEmpty()) { var bname = bankname.Split(','); jia.BankName = bname[0]; yi.BankName = bname[1]; } var bankaccount = Request["BankAccount"]; if (!bankaccount.IsNullOrEmpty()) { var baccount = bankaccount.Split(','); jia.BankAccount = baccount[0]; yi.BankAccount = baccount[1]; } obj.CompanyId = CommonService.CompanyId; if (string.IsNullOrEmpty(obj.Id)) { obj.ContractBoths = new List <Logic.Entity.ContractBoth>(); obj.Id = CommonRules.GUID; obj.CreateDT = DateTime.Now; obj.CreateUID = Sys.CurrentUser.UID; obj.ContractSN = ContractBLL.CreateContractSN(); obj.Attachments = files; jia.Signatory = (int)(ContractSignatory.甲方); yi.Signatory = (int)(ContractSignatory.乙方); obj.ContractBoths.Add(jia); obj.ContractBoths.Add(yi); //var existContractSN = ContractBLL.Find(o => o.ContractSN == obj.ContractSN); //if (existContractSN != null) //{ // re.Message = "该合同编号已存在!"; //} //else //{ // re = ContractBLL.Add(obj); //} re = ContractBLL.Add(obj); #region 操作日志 var msg = LogEngine.CompareModelToLog <Contract>(LogModule.合同管理, obj); new LogEngine().WriteInsert(msg, LogModule.合同管理); #endregion } else { var contract = ContractBLL.GetObj(obj.Id); //var oldContractSN = contract.ContractSN; Contract _contract = new Contract(); ExtendHelper.CopyProperty <Contract>(_contract, contract); obj.Version = contract.Version; obj.PId = contract.PId; obj.ToCopyProperty(contract); contract.Attachments.AddRange(files); var detailId = Request["detailId"]; if (!detailId.IsNullOrEmpty()) { var detailIds = detailId.Split(','); var jiaId = int.Parse(detailIds[0]); var yiId = int.Parse(detailIds[1]); jia.Id = jiaId; yi.Id = yiId; jia.Signatory = 1; yi.Signatory = 2; var jiares = contract.ContractBoths.FirstOrDefault(o => o.Id == jiaId); var yires = contract.ContractBoths.FirstOrDefault(o => o.Id == yiId); //jia.ContractId = jiares.ContractId; //yi.ContractId = yires.ContractId; jia.ToCopyProperty(jiares); yi.ToCopyProperty(yires); } //var existContractSN = ContractBLL.FindList(o => o.ContractSN == contract.ContractSN); //if (existContractSN.Count > 0 && oldContractSN != obj.ContractSN) //{ // re.Message = "该合同编号已存在!"; //} //else //{ // re = ContractBLL.Update(contract); //} re = ContractBLL.Update(contract); #region 操作日志 var msg = LogEngine.CompareModelToLog <Contract>(LogModule.合同管理, obj, _contract); new LogEngine().WriteUpdate(msg, LogModule.合同管理); #endregion } return(Content(re.ToJson())); }