Example #1
0
        /// <summary>
        /// 提交Closure
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public IHttpActionResult PostClosure(ClosureInfo entity)
        {
            using (TransactionScope tranScope = new TransactionScope())
            {
                //    bll.BeginTransAction();
                //    try
                //    {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                if (entity.ClosureReasonCode != "Others")
                {
                    entity.ClosureReasonRemark = string.Empty;
                }

                if (entity.Id == new Guid())
                {
                    entity.Id = Guid.NewGuid();

                    entity.CreateDate = DateTime.Now;

                    entity.ProjectId = ProjectInfo.CreateMainProject(FlowCode.Closure, entity.USCode, NodeCode.Start, entity.CreateUserAccount);



                    ClosureInfo.Add(entity);
                }
                else
                {
                    ClosureInfo.Update(entity);
                }
                //    bll.Commit();
                //}
                //catch (Exception ex)
                //{
                //    bll.Rollback();
                //    return BadRequest(ex.Message);
                //}
                var usersList  = new List <ProjectUsers>();
                var assetActor = GetClosureUsers(ProjectUserRoleCode.AssetActor, ProjectUserRoleCode.AssetActor, ProjectUserRoleCode.AssetActor, entity.AssetActorAccount, entity.AssetActorNameENUS, entity.AssetActorNameZHCN, entity.ProjectId);
                usersList.Add(assetActor);
                var assetRep = GetClosureUsers(ProjectUserRoleCode.AssetRep, ProjectUserRoleCode.AssetRep, ProjectUserRoleCode.AssetRep, entity.AssetRepAccount, entity.AssetRepNameENUS, entity.AssetRepNameZHCN, entity.ProjectId);
                usersList.Add(assetRep);
                var finance = GetClosureUsers(ProjectUserRoleCode.Finance, ProjectUserRoleCode.Finance, ProjectUserRoleCode.Finance, entity.FinanceAccount, entity.FinanceNameENUS, entity.FinanceNameZHCN, entity.ProjectId);
                usersList.Add(finance);
                var Legal = GetClosureUsers(ProjectUserRoleCode.Legal, ProjectUserRoleCode.Legal, ProjectUserRoleCode.Legal, entity.LegalAccount, entity.LegalNameENUS, entity.LegalNameZHCN, entity.ProjectId);
                usersList.Add(Legal);
                var PM = GetClosureUsers(ProjectUserRoleCode.PM, ProjectUserRoleCode.PM, ProjectUserRoleCode.PM, entity.PMAccount, entity.PMNameZHCN, entity.PMNameENUS, entity.ProjectId);
                usersList.Add(PM);
                var assertMgr = GetClosureUsers(ProjectUserRoleCode.AssetManager, ProjectUserRoleCode.AssetManager, ProjectUserRoleCode.AssetManager, entity.AssetManagerAccount, entity.AssetManagerNameENUS,
                                                entity.AssetManagerNameZHCN, entity.ProjectId);
                usersList.Add(assertMgr);

                var cm = GetClosureUsers(ProjectUserRoleCode.CM, ProjectUserRoleCode.CM, ProjectUserRoleCode.CM, entity.CMAccount, entity.CMNameENUS,
                                         entity.CMNameZHCN, entity.ProjectId);
                usersList.Add(cm);
                if (entity.NecessaryNoticeUserList != null && entity.NecessaryNoticeUserList.Count > 0)
                {
                    usersList.AddRange(entity.NecessaryNoticeUserList.Select(
                                           user => GetClosureUsers(ProjectUserRoleCode.View, ProjectUserRoleCode.View, ProjectUserRoleCode.View, user.Code, user.NameENUS, user.NameZHCN,
                                                                   entity.ProjectId)));
                }
                if (entity.NoticeUserList != null && entity.NoticeUserList.Count > 0)
                {
                    usersList.AddRange(entity.NoticeUserList.Select(
                                           user => GetClosureUsers(ProjectUserRoleCode.View, ProjectUserRoleCode.View, ProjectUserRoleCode.View, user.Code, user.NameENUS, user.NameZHCN,
                                                                   entity.ProjectId)));
                }

                ProjectUsers.Add(usersList.ToArray());
                SendRemind(entity);
                SendWorkTaskAndEmail(entity);

                //初始化项目信息

                ProjectInfo.CreateSubProject(FlowCode.Closure_WOCheckList, entity.ProjectId, entity.USCode, NodeCode.Start, PM.UserAccount);
                ProjectInfo.CreateSubProject(FlowCode.Closure_LegalReview, entity.ProjectId, entity.USCode, NodeCode.Start, assetActor.UserAccount);
                ProjectInfo.CreateSubProject(FlowCode.Closure_ClosureTool, entity.ProjectId, entity.USCode, NodeCode.Start, finance.UserAccount);

                var store = StoreBasicInfo.GetStorInfo(entity.USCode);

                var closureTool = new ClosureTool();
                closureTool.Id                   = Guid.NewGuid();
                closureTool.ProjectId            = entity.ProjectId;
                closureTool.IsHistory            = false;
                closureTool.IsOptionOffered      = entity.IsRelocation();
                closureTool.PipelineName         = store.PipelineNameENUS;
                closureTool.RelocationPipelineID = store.PipelineID;
                closureTool.Add();

                var woCheckList = new ClosureWOCheckList
                {
                    Id                = Guid.NewGuid(),
                    ProjectId         = entity.ProjectId,
                    CreateTime        = DateTime.Now,
                    CreateUserAccount = ClientCookie.UserCode,
                    CreateUserName    = ClientCookie.UserNameENUS,
                    IsHistory         = false
                };
                woCheckList.Add();

                var legalReview = new ClosureLegalReview
                {
                    Id                = Guid.NewGuid(),
                    ProjectId         = entity.ProjectId,
                    CreateTime        = DateTime.Now,
                    CreateUserAccount = ClientCookie.UserCode,
                    CreateUserName    = ClientCookie.UserNameENUS,
                    IsHistory         = false
                };
                legalReview.Add();

                var executiveSummary = new ClosureExecutiveSummary
                {
                    Id             = Guid.NewGuid(),
                    ProjectId      = entity.ProjectId,
                    CreateTime     = DateTime.Now,
                    CreatorAccount = ClientCookie.UserCode,
                    CreatorName    = ClientCookie.UserNameENUS,
                    IsHistory      = false
                };
                executiveSummary.Add();

                //var package = new ClosurePackage
                //{
                //    Id = Guid.NewGuid(),
                //    ProjectId = entity.ProjectId,
                //    CreateTime = DateTime.Now,
                //    CreateUserAccount = ClientCookie.UserCode,
                //    IsHistory = false
                //};
                //package.Add();

                var projectContractInfo = ProjectContractInfo.GetContractWithHistory(entity.ProjectId).Current;
                projectContractInfo.Add();

                ProjectInfo.CreateSubProject(FlowCode.Closure_ExecutiveSummary, entity.ProjectId, entity.USCode, NodeCode.Start, assetActor.UserAccount);

                ProjectInfo.CreateSubProject(FlowCode.Closure_ClosurePackage, entity.ProjectId, entity.USCode, NodeCode.Start, assetActor.UserAccount);

                ProjectInfo.CreateSubProject(FlowCode.Closure_ConsInvtChecking, entity.ProjectId, entity.USCode, NodeCode.Start, entity.PMAccount);


                ProjectInfo.CreateSubProject(FlowCode.Closure_ContractInfo, entity.ProjectId, entity.USCode,
                                             NodeCode.Start, entity.CreateUserAccount);
                ProjectInfo.CreateSubProject(FlowCode.Closure_Memo, entity.ProjectId, entity.USCode,
                                             NodeCode.Start, entity.CreateUserAccount);
                ProjectNode.GenerateOnCreate(FlowCode.Closure, entity.ProjectId);
                try
                {
                    //bllActionLog.Add(new ActionLog
                    //{
                    //    Id = Guid.NewGuid(),
                    //    ProjectId = entity.ProjectId,
                    //    Action = ActionType.Submit,
                    //    CreateTime = DateTime.Now,
                    //    Operator = entity.CreateUserAccount,
                    //    OperatorENUS = entity.CreateUserNameENUS,
                    //    OperatorZHCN = entity.CreateUserNameZHCN,
                    //    Remark = "",
                    //    OperatorTitle = "创建流程"
                    //});
                    tranScope.Complete();
                    //bll.GetDb().SaveChanges();
                }
                catch (DbEntityValidationException dbEx)
                {
                    tranScope.Dispose();
                }


                return(Ok(entity));
            }
        }