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 List <NavigateInfo> GetCurrentByProjectId(string projectId, string flowCode, string subFlowCode, string userAccount)
        {
            var flowList = FlowInfo.Search(e => e.ParentCode == FlowCode.Closure).OrderBy(e => e.LayoutSequence);

            //获取当前用户的项目任务
            var sql = string.Format(@"SELECT tb_users.*,tb_work.Status AS TaskStatus,tb_work.TypeCode,tb_work.Url,
            tb_work.ProcInstID,tb_users.ProjectId
            FROM dbo.ProjectUsers tb_users
            RIGHT JOIN dbo.TaskWork tb_work
            ON tb_users.UserAccount = tb_work.ReceiverAccount
            AND tb_work.RefID = tb_users.ProjectId
            WHERE tb_work.RefID = '{0}' AND tb_work.ReceiverAccount ='{1}'
            AND ISNULL(RoleCode,'')!='View' AND tb_work.Status = 0  ", projectId, userAccount);

            var navigateList = new List <NavigateInfo>();

            var result = ProjectUsers.SqlQuery <ProjectUsersEntity>(sql, null);
            var list   = result.ToList();



            //获取已完成的项目列表
            var finishedProjectList = ProjectInfo.Search(e => e.ProjectId == projectId && e.Status == ProjectStatus.Finished).ToList();

            NavigateInfo navigateItem  = null;
            var          viewPageStuff = "/View/param?projectId=" + projectId;
            var          editPageStuff = "/" + projectId;

            //是否是编辑页

            foreach (var flowItem in flowList)
            {
                var isEditPage = false;
                navigateItem          = new NavigateInfo();
                navigateItem.NameZHCN = flowItem.NameZHCN;
                navigateItem.Linked   = true;
                navigateItem.Code     = flowItem.Code;
                navigateItem.Href     = string.Empty;

                //设置当前的子流程的为选中状态
                if (flowItem.Code == subFlowCode)
                {
                    navigateItem.IsSelected = true;
                }

                //设置流程的完成状态
                foreach (var project in finishedProjectList)
                {
                    if (flowItem.Code == project.FlowCode)
                    {
                        navigateItem.IsFinished = true;
                    }
                }


                //默认的链接 主流程Code+/+子流程Code
                string defaultUrl = "#/" + flowItem.FlowCodePrefix + "/" + flowItem.Code.Split('_')[1];

                //判断当前用户是否有待办任务
                foreach (var item in list)
                {
                    if (item.TypeCode == flowItem.Code)
                    {
                        if (item.TaskStatus == TaskWorkStatus.UnFinish)
                        {
                            //如果有待办任务导航tab的链接为待办任务的链接
                            navigateItem.Href = item.Url;
                            if (item.ProcInstID.HasValue && !string.IsNullOrEmpty(item.ProjectId))
                            {
                                navigateItem.Href += "&projectId=" + item.ProjectId;
                            }
                        }
                        //如果任务已结束设置为只读页面的链接
                        else if (item.TaskStatus == TaskWorkStatus.Finished ||
                                 item.TaskStatus == TaskWorkStatus.K2ProcessApproved || navigateItem.IsFinished)
                        {
                            navigateItem.Href = defaultUrl + viewPageStuff;
                        }
                    }
                }


                //获取当前用户的项目组头衔

                var projectUser = ProjectUsers.Get(ClientCookie.UserCode, projectId);

                if (string.IsNullOrEmpty(navigateItem.Href))
                {
                    if (projectUser != null)
                    {
                        if (!string.IsNullOrEmpty(flowItem.RoleCode) &&
                            flowItem.RoleCode.Split('_').Contains(projectUser.RoleCode) && !navigateItem.IsFinished)
                        {
                            isEditPage = true;
                        }

                        if (isEditPage)
                        {
                            navigateItem.Href = defaultUrl + editPageStuff;
                        }
                        else
                        {
                            navigateItem.Href = defaultUrl + viewPageStuff;
                        }
                    }
                    else
                    {
                        navigateItem.Href = defaultUrl + viewPageStuff;
                    }
                }


                navigateList.Add(navigateItem);
            }


            return(navigateList);
        }