Esempio n. 1
0
        public void Handle(EMP_ContractStage stage, bool result)
        {
            if (stage.EMP_Ref_StageStatus.Code != CodeConstManager.EmpContractStageStatus.InWork)
            {
                return;
            }

            var handler = new EmpContractStageHistoryHandler(_uow);

            if (result)
            {
                handler.SetStageApproved(stage);
                handler.AddHistoryApproved(stage.ContractId);

                var wasInAdjustment = stage.EMP_Contract.EMP_ContractHistory.Any(x =>
                                                                                 x.OBK_Ref_ContractHistoryStatus.Code == OBK_Ref_ContractHistoryStatus.Returned);
                if (wasInAdjustment)
                {
                    var cozStage = stage.EMP_Contract.EMP_ContractStage.First(x => x.EMP_Ref_Stage.Code == CodeConstManager.EmpContractStage.Coz);
                    cozStage.StageStatusId = _uow.GetQueryable <EMP_Ref_StageStatus>()
                                             .Where(x => x.Code == CodeConstManager.EmpContractStageStatus.ApprovalRequired).Select(x => x.Id)
                                             .FirstOrDefault();
                }
            }
            else
            {
                handler.SetStageRejected(stage);
                handler.AddHistoryRejected(stage.ContractId);
            }

            _uow.Save();
        }
        public void Handle(EMP_ContractStage stage, bool result)
        {
            if (stage.EMP_Ref_StageStatus.Code != CodeConstManager.EmpContractStageStatus.New)
            {
                return;
            }

            var handler = new EmpContractStageHistoryHandler(_uow);

            if (result)
            {
                handler.SetStageApproved(stage);
                handler.AddHistoryApproved(stage.ContractId);
            }
            else
            {
                handler.SetStageRejected(stage);
                handler.AddHistoryRejected(stage.ContractId);
                var legalStage = stage.EMP_Contract.EMP_ContractStage.FirstOrDefault(x =>
                                                                                     x.EMP_Ref_Stage.Code == CodeConstManager.EmpContractStage.LegalDepartmant);
                if (legalStage != null)
                {
                    handler.SetStageRejected(legalStage);
                }
            }

            var cozStage = stage.EMP_Contract.EMP_ContractStage.First(x => x.EMP_Ref_Stage.Code == CodeConstManager.EmpContractStage.Coz);

            cozStage.StageStatusId = _uow.GetQueryable <EMP_Ref_StageStatus>()
                                     .Where(x => x.Code == CodeConstManager.EmpContractStageStatus.ApprovalRequired).Select(x => x.Id)
                                     .FirstOrDefault();

            _uow.Save();
        }
        public void Handle(EMP_ContractStage stage, bool result)
        {
            var handler = new EmpContractStageHistoryHandler(_uow);

            if (stage.EMP_Ref_StageStatus.Code == CodeConstManager.EmpContractStageStatus.InWork)
            {
                stage.StageStatusId = _uow.GetQueryable <EMP_Ref_StageStatus>()
                                      .Where(x => x.Code == CodeConstManager.EmpContractStageStatus.ApprovalRequired).Select(x => x.Id)
                                      .FirstOrDefault();

                if (result)
                {
                    handler.AddHistoryApproved(stage.ContractId);
                }
                else
                {
                    handler.AddHistoryRejected(stage.ContractId);
                }

                _uow.Save();
                return;
            }

            if (stage.EMP_Ref_StageStatus.Code == CodeConstManager.EmpContractStageStatus.ApprovalRequired)
            {
                if (result)
                {
                    handler.SetStageApproved(stage);
                    handler.AddHistoryApproved(stage.ContractId);
                }
                else
                {
                    handler.SetStageRejected(stage);
                    handler.AddHistoryRejected(stage.ContractId);
                    var legalStage = stage.EMP_Contract.EMP_ContractStage.FirstOrDefault(x =>
                                                                                         x.EMP_Ref_Stage.Code == CodeConstManager.EmpContractStage.LegalDepartmant);
                    if (legalStage != null)
                    {
                        handler.SetStageRejected(legalStage);
                    }
                }

                var defStage = new EMP_ContractStage
                {
                    Id         = Guid.NewGuid(),
                    DateCreate = DateTime.Now,
                    ContractId = stage.ContractId,
                    StageId    = _uow.GetQueryable <EMP_Ref_Stage>()
                                 .Where(x => x.Code == CodeConstManager.EmpContractStage.Def).Select(x => x.Id)
                                 .FirstOrDefault(),
                    StageStatusId = _uow.GetQueryable <EMP_Ref_StageStatus>()
                                    .Where(x => x.Code == CodeConstManager.EmpContractStageStatus.New).Select(x => x.Id)
                                    .FirstOrDefault()
                };
                _uow.Insert(defStage);

                var defUnit = _uow.GetQueryable <Unit>().First(x => x.Code == "finance");
                _uow.Insert(new EMP_ContractStageExecutors
                {
                    Id = Guid.NewGuid(),
                    EMP_ContractStage = defStage,
                    ExecutorType      = CodeConstManager.OBK_CONTRACT_STAGE_EXECUTOR_TYPE_EXECUTOR,
                    ExecutorId        = Guid.Parse(defUnit.BossId)
                });

                _uow.Save();
                return;
            }
        }
Esempio n. 4
0
        public void Handle(EMP_ContractStage stage, bool result)
        {
            if (stage.EMP_Ref_StageStatus.Code != CodeConstManager.EmpContractStageStatus.ApprovalRequired)
            {
                return;
            }

            var handler = new EmpContractStageHistoryHandler(_uow);

            if (result)
            {
                handler.SetStageApproved(stage);
                handler.AddHistoryApproved(stage.ContractId);
            }
            else
            {
                handler.SetStageRejected(stage);
                handler.AddHistoryRejected(stage.ContractId);
            }

            var legalStage = stage.EMP_Contract.EMP_ContractStage.FirstOrDefault(x =>
                                                                                 x.EMP_Ref_Stage.Code == CodeConstManager.EmpContractStage.LegalDepartmant);

            if (!result || IsRejectedInOtherStages(stage.EMP_Contract))
            {
                if (legalStage != null)
                {
                    handler.SetStageRejected(legalStage);
                }
            }
            else
            {
                if (legalStage != null)
                {
                    legalStage.StageStatusId = _uow.GetQueryable <EMP_Ref_StageStatus>()
                                               .Where(x => x.Code == CodeConstManager.EmpContractStageStatus.Approved).Select(x => x.Id).FirstOrDefault();
                }

                var ceoStage = new EMP_ContractStage
                {
                    Id         = Guid.NewGuid(),
                    ContractId = stage.ContractId,
                    DateCreate = DateTime.Now,
                    StageId    = _uow.GetQueryable <EMP_Ref_Stage>()
                                 .Where(x => x.Code == CodeConstManager.EmpContractStage.Ceo).Select(x => x.Id)
                                 .FirstOrDefault(),
                    StageStatusId = _uow.GetQueryable <EMP_Ref_StageStatus>()
                                    .Where(x => x.Code == CodeConstManager.EmpContractStageStatus.ApprovalRequired)
                                    .Select(x => x.Id).FirstOrDefault()
                };
                _uow.Insert(ceoStage);

                var ceoExecutor = new EMP_ContractStageExecutors
                {
                    Id = Guid.NewGuid(),
                    EMP_ContractStage = ceoStage,
                    ExecutorType      = CodeConstManager.OBK_CONTRACT_STAGE_EXECUTOR_TYPE_SIGNER,
                    ExecutorId        = _uow.GetQueryable <Unit>()
                                        .Where(x => x.Code == "ncels_deputyceo" && x.EmployeeId != null)
                                        .Select(x => x.EmployeeId.Value).FirstOrDefault()
                };
                _uow.Insert(ceoExecutor);
            }

            _uow.Save();
        }