public void SendToWork(Guid stageId, Guid executorId) { var stage = _uow.GetQueryable <EMP_ContractStage>().First(x => x.Id == stageId); var executor = _uow.GetQueryable <Employee>().First(x => x.Id == executorId); var contract = _uow.GetQueryable <EMP_Contract>().First(x => x.Id == stage.ContractId); var stageStatus = _uow.GetQueryable <EMP_Ref_StageStatus>().First(x => x.Code == CodeConstManager.EmpContractStageStatus.InWork); if (stage.EMP_Ref_StageStatus.Code == CodeConstManager.EmpContractStageStatus.NotDistributed) { stage.StageStatusId = stageStatus.Id; } contract.ContractStatusId = _uow.GetQueryable <EMP_Ref_Status>() .Where(x => x.Code == CodeConstManager.EmpContractStatus.InWork).Select(x => x.Id).FirstOrDefault(); var stageExecutor = new EMP_ContractStageExecutors { Id = Guid.NewGuid(), ExecutorId = executor.Id, ExecutorType = CodeConstManager.OBK_CONTRACT_STAGE_EXECUTOR_TYPE_EXECUTOR }; if (stage.EMP_Ref_Stage.Code == CodeConstManager.EmpContractStage.Coz) { var validationGroupStage = contract.EMP_ContractStage.FirstOrDefault(x => x.EMP_Ref_Stage.Code == CodeConstManager.EmpContractStage.ValidationGroup); var defStage = contract.EMP_ContractStage.FirstOrDefault(x => x.EMP_Ref_Stage.Code == CodeConstManager.EmpContractStage.Def); var isRejected = validationGroupStage != null && validationGroupStage.EMP_Ref_StageStatus.Code == CodeConstManager.EmpContractStageStatus.NotApproved || defStage != null && defStage.EMP_Ref_StageStatus.Code == CodeConstManager.EmpContractStageStatus.NotApproved; var legalStage = new EMP_ContractStage { Id = Guid.NewGuid(), ContractId = contract.Id, DateCreate = DateTime.Now, StageStatusId = isRejected ? _uow.GetQueryable <EMP_Ref_StageStatus>() .Where(x => x.Code == CodeConstManager.EmpContractStageStatus.NotApproved) .Select(x => x.Id).FirstOrDefault() : stageStatus.Id, StageId = _uow.GetQueryable <EMP_Ref_Stage>() .Where(x => x.Code == CodeConstManager.EmpContractStage.LegalDepartmant).Select(x => x.Id) .FirstOrDefault() }; _uow.Insert(legalStage); stageExecutor.EMP_ContractStage = legalStage; } else { stageExecutor.EMP_ContractStage = stage; } _uow.Insert(stageExecutor); new EmpContractStageHistoryHandler(_uow).AddHistorySentToWork(contract.Id); _uow.Save(); SendNotificationToExecutorWork(executorId, contract); }
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(); }