public IHttpActionResult Upload(string projectId, string refTableName, Guid?requirementId = null) { using (TransactionScope tranScope = new TransactionScope()) { var refTableId = Attachment.GetRefTableId(refTableName, projectId); if (refTableId == Guid.Empty.ToString()) { var newId = Guid.NewGuid(); refTableId = newId.ToString(); switch (refTableName) { case "MajorLeaseChangePackage": { var entity = new MajorLeaseChangePackage(); entity.ProjectId = projectId; entity.Id = newId; entity.CreateTime = DateTime.Now; entity.CreateUserAccount = ClientCookie.UserCode; entity.IsHistory = false; entity.Add(); } break; case "ReimageSummary": { var entity = new ReimageSummary(); entity.ProjectId = projectId; entity.Id = newId; entity.CreateTime = DateTime.Now; entity.CreateUserAccount = ClientCookie.UserCode; entity.IsHistory = false; entity.Add(); } break; case "ReimageConsInfo": { var entity = new ReimageConsInfo(); entity.ProjectId = projectId; entity.Id = newId; entity.CreateTime = DateTime.Now; entity.CreateUserAccount = ClientCookie.UserCode; entity.IsHistory = false; entity.Add(); } break; case "ReimagePackage": { var entity = new ReimagePackage(); entity.ProjectId = projectId; entity.Id = newId; entity.CreateTime = DateTime.Now; entity.CreateUserAccount = ClientCookie.UserCode; entity.IsHistory = false; entity.Add(); } break; case "RebuildLegalReview": { var entity = new RebuildLegalReview(); entity.ProjectId = projectId; entity.Id = newId; entity.CreateTime = DateTime.Now; entity.CreateUserAccount = ClientCookie.UserCode; entity.IsHistory = false; entity.Add(); } break; case "ClosureLegalReview": { var entity = new ClosureLegalReview(); entity.ProjectId = projectId; entity.Id = newId; entity.CreateTime = DateTime.Now; entity.CreateUserAccount = ClientCookie.UserCode; entity.IsHistory = false; entity.Add(); } break; case "ClosureExecutiveSummary": { var entity = new ClosureExecutiveSummary(); entity.ProjectId = projectId; entity.Id = newId; entity.CreateTime = DateTime.Now; entity.CreatorAccount = ClientCookie.UserCode; entity.IsHistory = false; entity.Add(); } break; case "ClosurePackage": { var entity = new ClosurePackage(); entity.ProjectId = projectId; entity.Id = newId; entity.CreateTime = DateTime.Now; entity.CreateUserAccount = ClientCookie.UserCode; entity.IsHistory = false; entity.Add(); } break; } } var userRole = ProjectUsers.Get(ClientCookie.UserCode, projectId); var files = HttpContext.Current.Request.Files; if (requirementId.HasValue) { var attReq = AttachmentRequirement.Get(requirementId.Value); var projectInfo = ProjectInfo.Get(projectId, attReq.FlowCode); var store = StoreBasicInfo.GetStorInfo(projectInfo.USCode); var attachNode = NodeInfo.FirstOrDefault(n => n.FlowCode == attReq.FlowCode && n.Code == attReq.NodeCode); if (attachNode != null) { ProjectInfo.FinishNode(projectId, attReq.FlowCode, attReq.NodeCode); } var file = files[0]; string fileName = Path.GetFileName(file.FileName); string fileExtension = Path.GetExtension(file.FileName); var current = System.Web.HttpContext.Current; string internalName = Guid.NewGuid() + fileExtension; string absolutePath = current.Server.MapPath("~/") + "UploadFiles/" + internalName; file.SaveAs(absolutePath); Attachment att = Attachment.Get(refTableId, requirementId.Value); if (att == null) { att = new Attachment(); att.InternalName = internalName; att.RefTableName = refTableName; att.RefTableID = refTableId; att.RelativePath = "//"; att.Name = fileName; att.Extension = fileExtension; att.Length = file.ContentLength; att.CreateTime = DateTime.Now; att.CreatorNameZHCN = ClientCookie.UserNameZHCN; att.CreatorNameENUS = ClientCookie.UserNameENUS; att.CreatorID = ClientCookie.UserCode; att.ID = Guid.NewGuid(); att.RequirementId = requirementId; att.TypeCode = ""; Attachment.Add(att); } else { att.InternalName = internalName; att.RefTableName = refTableName; att.RefTableID = refTableId; att.RelativePath = "//"; att.Name = fileName; att.Extension = fileExtension; att.Length = file.ContentLength; att.CreateTime = DateTime.Now; att.CreatorNameZHCN = ClientCookie.UserNameZHCN; att.CreatorNameENUS = ClientCookie.UserNameENUS; att.CreatorID = ClientCookie.UserCode; Attachment.Update(att); } //TempClosure上传SignAgreement //if (requirementId.Value.Equals(new Guid("1E9B17AF-357A-4DC9-8A60-17766663FB75"))) //{ // var url = "/TempClosure/Main#/ClosureMemo?projectId=" + projectId; // var actor = ProjectUsers.FirstOrDefault(pu => pu.ProjectId == projectId && pu.RoleCode == ProjectUserRoleCode.AssetActor); // var title = string.Concat(projectId, " ", store.NameZHCN, " ", store.NameENUS); // TaskWork.Finish(t => t.ReceiverAccount == ClientCookie.UserCode && t.RefID == projectId && t.Status == TaskWorkStatus.UnFinish && t.TypeCode == FlowCode.TempClosure_ClosurePackage); // //TaskWork.SendTask(projectId, title, projectInfo.USCode, url, actor, FlowCode.TempClosure, FlowCode.TempClosure_ClosureMemo, "Start"); //} } else { List <Attachment> attachments = new List <Attachment>(); string typeCode = ""; if (refTableName == "RebuildLegalReview") { typeCode = "Contract"; } for (int i = 0; i < files.Count; i++) { var file = files[i]; string fileName = Path.GetFileName(file.FileName); string fileExtension = Path.GetExtension(file.FileName); var current = System.Web.HttpContext.Current; string internalName = Guid.NewGuid() + fileExtension; string absolutePath = current.Server.MapPath("~/") + "UploadFiles/" + internalName; file.SaveAs(absolutePath); Attachment att = new Attachment(); att.InternalName = internalName; att.RefTableName = refTableName; att.RefTableID = refTableId; att.RelativePath = "//"; att.Name = fileName; att.Extension = fileExtension; att.Length = file.ContentLength; att.CreateTime = DateTime.Now; att.CreatorNameZHCN = ClientCookie.UserNameZHCN; att.CreatorNameENUS = ClientCookie.UserNameENUS; att.CreatorID = ClientCookie.UserCode; att.ID = Guid.NewGuid(); att.RequirementId = requirementId; att.TypeCode = typeCode; attachments.Add(att); } Attachment.Add(attachments.ToArray()); } tranScope.Complete(); return(Ok()); } }
public Guid?GetRefId(string projectId, string flowTable) { Guid?refId = null; switch (flowTable) { case "MajorLeaseConsInfo": var majorConsInfo = MajorLeaseConsInfo.FirstOrDefault(e => e.ProjectId == projectId && !e.IsHistory); if (majorConsInfo != null && majorConsInfo.Id != Guid.Empty) { refId = majorConsInfo.Id; } else { refId = Guid.NewGuid(); majorConsInfo = new MajorLeaseConsInfo { Id = refId.Value, ProjectId = projectId, CreateTime = DateTime.Now, IsHistory = false }; MajorLeaseConsInfo.Add(majorConsInfo); } break; case "MajorLeaseConsInvtChecking": var checkInfo = MajorLeaseConsInvtChecking.Search(e => e.ProjectId == projectId && !e.IsHistory).FirstOrDefault(); if (checkInfo != null && checkInfo.Id != Guid.Empty) { refId = checkInfo.Id; } else { refId = Guid.NewGuid(); checkInfo = new MajorLeaseConsInvtChecking { Id = refId.Value, ProjectId = projectId, CreateTime = DateTime.Now, IsHistory = false }; MajorLeaseConsInvtChecking.Add(checkInfo); } break; case "ReimageConsInfo": var reimageConsInfo = ReimageConsInfo.FirstOrDefault(e => e.ProjectId == projectId && !e.IsHistory); if (reimageConsInfo != null && reimageConsInfo.Id != Guid.Empty) { refId = reimageConsInfo.Id; } else { refId = Guid.NewGuid(); reimageConsInfo = new ReimageConsInfo { Id = refId.Value, ProjectId = projectId, IsHistory = false, CreateTime = DateTime.Now, CreateUserAccount = ClientCookie.UserCode }; ReimageConsInfo.Add(reimageConsInfo); } break; case "ReimageConsInvtChecking": var reimageCheckInfo = ReimageConsInvtChecking.Search(e => e.ProjectId == projectId && !e.IsHistory).FirstOrDefault(); if (reimageCheckInfo != null && reimageCheckInfo.Id != Guid.Empty) { refId = reimageCheckInfo.Id; } else { refId = Guid.NewGuid(); reimageCheckInfo = new ReimageConsInvtChecking { Id = refId.Value, ProjectId = projectId, CreateTime = DateTime.Now, IsHistory = false }; ReimageConsInvtChecking.Add(reimageCheckInfo); } break; case "RebuildConsInfo": var rbdConsInfo = RebuildConsInfo.FirstOrDefault(e => e.ProjectId == projectId && !e.IsHistory); if (rbdConsInfo != null && rbdConsInfo.Id != Guid.Empty) { refId = rbdConsInfo.Id; } else { refId = Guid.NewGuid(); rbdConsInfo = new RebuildConsInfo { Id = refId.Value, ProjectId = projectId, IsHistory = false, CreateTime = DateTime.Now, LastUpdateTime = DateTime.Now, CreateUserAccount = ClientCookie.UserCode, CreateUserNameENUS = ClientCookie.UserNameENUS, CreateUserNameZHCN = ClientCookie.UserNameZHCN }; RebuildConsInfo.Add(rbdConsInfo); } break; case "RebuildConsInvtChecking": var rbdCheckInfo = RebuildConsInvtChecking.Search(e => e.ProjectId == projectId && !e.IsHistory).FirstOrDefault(); if (rbdCheckInfo != null && rbdCheckInfo.Id != Guid.Empty) { refId = rbdCheckInfo.Id; } else { refId = Guid.NewGuid(); rbdCheckInfo = new RebuildConsInvtChecking { Id = refId.Value, ProjectId = projectId, IsHistory = false, CreateTime = DateTime.Now, LastUpdateTime = DateTime.Now, CreateUserAccount = ClientCookie.UserCode, CreateUserNameENUS = ClientCookie.UserNameENUS, CreateUserNameZHCN = ClientCookie.UserNameZHCN }; RebuildConsInvtChecking.Add(rbdCheckInfo); } ProjectInfo.FinishNode(projectId, FlowCode.Rebuild_ConsInvtChecking, NodeCode.Rebuild_ConsInvtChecking_Downlod); ProjectInfo.FinishNode(projectId, FlowCode.Rebuild_ConsInvtChecking, NodeCode.Rebuild_ConsInvtChecking_Input); ProjectInfo.FinishNode(projectId, FlowCode.Rebuild_ConsInvtChecking, NodeCode.Rebuild_ConsInvtChecking_Upload); break; case "ClosureWOCheckList": var closureWOCheckList = ClosureWOCheckList.Get(projectId); if (closureWOCheckList != null && closureWOCheckList.Id != Guid.Empty) { refId = closureWOCheckList.Id; _woCheckList = closureWOCheckList; } else { refId = Guid.NewGuid(); closureWOCheckList = new ClosureWOCheckList { Id = refId.Value, ProjectId = projectId, CreateTime = DateTime.Now, CreateUserAccount = ClientCookie.UserCode, CreateUserName = ClientCookie.UserNameENUS, IsHistory = false }; ClosureWOCheckList.Add(closureWOCheckList); } break; } return(refId); }