protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6DR_DDBID_1653 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { //Leave UserCode region to enable user code saving #region UserCode var returnValue = new FR_Guid(); //Put your code here P_L6DR_DDBID_1653 param = new P_L6DR_DDBID_1653(); param.CMN_BPT_BusinessParticipantID = Parameter.CMN_BPT_BusinessParticipantID; var drivers = cls_Retrieve_Driver_Info_and_VerCode.Invoke(Connection, Transaction, securityTicket).Result; var driver = drivers.FirstOrDefault(x => x.CMN_BPT_BusinessParticipantID == param.CMN_BPT_BusinessParticipantID); if (driver != null) { ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo(); if (driver.CMN_PER_PersonInfoID != Guid.Empty) { var result = person.Load(Connection, Transaction, driver.CMN_PER_PersonInfoID); if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } person.IsDeleted = true; person.Save(Connection, Transaction); } ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant(); if (driver.CMN_BPT_BusinessParticipantID != Guid.Empty) { var result = bParticipant.Load(Connection, Transaction, driver.CMN_BPT_BusinessParticipantID); if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } bParticipant.IsDeleted = true; bParticipant.Save(Connection, Transaction); } if (driver.Contacts != null) { foreach (var parContact in driver.Contacts) { ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact(); if (parContact.CMN_PER_CommunicationContact_TypeID != Guid.Empty) { var result = contact.Load(Connection, Transaction, parContact.CMN_PER_CommunicationContact_TypeID); if (result.Status != FR_Status.Success || contact.CMN_PER_CommunicationContactID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } contact.IsDeleted = true; contact.Save(Connection, Transaction); } } } ORM_CMN_Address adress = new ORM_CMN_Address(); if (driver.CMN_AddressID != Guid.Empty) { var result = adress.Load(Connection, Transaction, driver.CMN_AddressID); if (result.Status != FR_Status.Success || adress.CMN_AddressID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } adress.IsDeleted = true; adress.Save(Connection, Transaction); } ORM_CMN_BPT_Supplier supplier = new ORM_CMN_BPT_Supplier(); if (driver.CMN_BPT_SupplierID != Guid.Empty) { var result = supplier.Load(Connection, Transaction, driver.CMN_BPT_SupplierID); if (result.Status != FR_Status.Success || supplier.CMN_BPT_SupplierID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } supplier.IsDeleted = true; supplier.Save(Connection, Transaction); } ORM_CMN_BPT_BusinessParticipant asossBParticipant = new ORM_CMN_BPT_BusinessParticipant(); if (driver.AssociatedBusinessParticipant_RefID != Guid.Empty) { var result = asossBParticipant.Load(Connection, Transaction, driver.AssociatedBusinessParticipant_RefID); if (result.Status != FR_Status.Success || asossBParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } asossBParticipant.IsDeleted = true; asossBParticipant.Save(Connection, Transaction); } ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant BusinessParticipant_AssociatedBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); if (driver.AssociatedBusinessParticipant_RefID != Guid.Empty) { var result = BusinessParticipant_AssociatedBusinessParticipant.Load(Connection, Transaction, driver.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID); if (result.Status != FR_Status.Success || BusinessParticipant_AssociatedBusinessParticipant.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } BusinessParticipant_AssociatedBusinessParticipant.IsDeleted = true; BusinessParticipant_AssociatedBusinessParticipant.Save(Connection, Transaction); } ORM_USR_Account account = new ORM_USR_Account(); if (driver.USR_AccountID != Guid.Empty) { var result = account.Load(Connection, Transaction, driver.USR_AccountID); if (result.Status != FR_Status.Success || account.USR_AccountID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } account.IsDeleted = true; account.Save(Connection, Transaction); } ORM_USR_Device_AccountCode_StatusHistory Device_AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory(); if (driver.USR_Device_AccountCode_UsageHistoryID != Guid.Empty) { var result = Device_AccountCode_StatusHistory.Load(Connection, Transaction, driver.USR_Device_AccountCode_UsageHistoryID); if (result.Status != FR_Status.Success || Device_AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } Device_AccountCode_StatusHistory.IsDeleted = true; Device_AccountCode_StatusHistory.Save(Connection, Transaction); } ORM_USR_Device_AccountCode accountCode = new ORM_USR_Device_AccountCode(); if (driver.USR_Device_AccountCodeID != Guid.Empty) { var result = accountCode.Load(Connection, Transaction, driver.USR_Device_AccountCodeID); if (result.Status != FR_Status.Success || accountCode.USR_Device_AccountCodeID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } accountCode.IsDeleted = true; accountCode.Save(Connection, Transaction); } var Device_AccountCode_UsageHistoryQuery = new ORM_USR_Device_AccountCode_UsageHistory.Query(); Device_AccountCode_UsageHistoryQuery.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID; Device_AccountCode_UsageHistoryQuery.IsDeleted = false; Device_AccountCode_UsageHistoryQuery.Tenant_RefID = securityTicket.TenantID; var historyArray = ORM_USR_Device_AccountCode_UsageHistory.Query.Search(Connection, Transaction, Device_AccountCode_UsageHistoryQuery); if (historyArray != null && historyArray.Count > 0) { foreach (var historyItem in historyArray) { historyItem.IsDeleted = true; historyItem.Save(Connection, Transaction); } } } return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_SFE_1524 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); ORM_CMN_Address address = new ORM_CMN_Address(); if (Parameter.CMN_AddressID != Guid.Empty) { var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID); if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } address.City_Name = Parameter.City_Name; address.Street_Name = Parameter.Street_Name; address.Street_Number = Parameter.Street_Number; address.Country_Name = Parameter.Country_Name; address.Province_Name = Parameter.Province_Name; address.Tenant_RefID = Parameter.TenantID; address.Save(Connection, Transaction); ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo(); if (Parameter.CMN_PER_PersonInfoID != Guid.Empty) { var result = person.Load(Connection, Transaction, Parameter.CMN_PER_PersonInfoID); if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } //person.AccountImage_URL = Parameter.ProfileImage_Document_RefID; person.FirstName = Parameter.FirstName; person.LastName = Parameter.LastName; person.PrimaryEmail = Parameter.PrimaryEmail; person.Tenant_RefID = Parameter.TenantID; person.Title = Parameter.Title; person.Address_RefID = address.CMN_AddressID; person.BirthDate = Parameter.BirthDate; person.Save(Connection, Transaction); ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant(); if (Parameter.CMN_BPT_BusinessParticipantID != Guid.Empty) { var result = bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID); if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } bParticipant.DisplayName = Parameter.DisplayName; bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID; bParticipant.IsNaturalPerson = true; bParticipant.Tenant_RefID = Parameter.TenantID; bParticipant.Save(Connection, Transaction); ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee(); CSV2Core.DlTrace.Trace("Parameter.CMN_BPT_EMP_EmployeeID " + Parameter.CMN_BPT_EMP_EmployeeID); if (Parameter.CMN_BPT_EMP_EmployeeID != Guid.Empty) { var result = employee.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EmployeeID); if (result.Status != FR_Status.Success || employee.CMN_BPT_EMP_EmployeeID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } employee.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; employee.Staff_Number = Parameter.Staff_Number; employee.StandardFunction = Parameter.StandardFunction; employee.Tenant_RefID = Parameter.TenantID; employee.Save(Connection, Transaction); CSV2Core.DlTrace.Trace("after save Parameter.CMN_BPT_EMP_EmployeeID " + Parameter.CMN_BPT_EMP_EmployeeID); CSV2Core.DlTrace.Trace("employee.Status_IsAlreadySaved " + employee.Status_IsAlreadySaved); ORM_CMN_BPT_EMP_EmploymentRelationship employeeRelationship = new ORM_CMN_BPT_EMP_EmploymentRelationship(); if (Parameter.CMN_BPT_EMP_Employee_WorkingContractID != Guid.Empty) { var result = employeeRelationship.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_Employee_WorkingContractID); if (result.Status != FR_Status.Success || employeeRelationship.CMN_BPT_EMP_EmploymentRelationshipID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } employeeRelationship.Work_StartDate = Parameter.Work_StartDate; employeeRelationship.Work_EndDate = Parameter.Work_EndDate; employeeRelationship.Tenant_RefID = Parameter.TenantID; employeeRelationship.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID; employeeRelationship.Save(Connection, Transaction); if (Parameter.USR_AccountID != null && Parameter.USR_AccountID != Guid.Empty) { ORM_USR_Account account = new ORM_USR_Account(); account.Load(Connection, Transaction, Parameter.USR_AccountID); account.USR_AccountID = Parameter.USR_AccountID; account.Username = Parameter.username; account.DefaultLanguage_RefID = Parameter.LanguageID; account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; account.Tenant_RefID = Parameter.TenantID; account.Save(Connection, Transaction); var personToAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query(); personToAccountQuery.Tenant_RefID = securityTicket.TenantID; personToAccountQuery.USR_Account_RefID = account.USR_AccountID; personToAccountQuery.IsDeleted = false; var personToAccounts = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personToAccountQuery); if (personToAccounts.Count != 0) { ORM_CMN_PER_PersonInfo_2_Account personToAccount = personToAccounts[0]; personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID; personToAccount.USR_Account_RefID = account.USR_AccountID; personToAccount.Tenant_RefID = securityTicket.TenantID; personToAccount.Save(Connection, Transaction); } else { ORM_CMN_PER_PersonInfo_2_Account personToAccount = new ORM_CMN_PER_PersonInfo_2_Account(); personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID; personToAccount.USR_Account_RefID = account.USR_AccountID; personToAccount.Tenant_RefID = securityTicket.TenantID; personToAccount.Save(Connection, Transaction); } if (Parameter.Rights != null) { foreach (var rightParam in Parameter.Rights) { var right = new ORM_USR_Account_FunctionLevelRight(); if (rightParam.RightID != Guid.Empty) { var result = right.Load(Connection, Transaction, rightParam.RightID); if (result.Status != FR_Status.Success || right.USR_Account_FunctionLevelRightID == Guid.Empty) { right.USR_Account_FunctionLevelRightID = rightParam.RightID; right.Tenant_RefID = Parameter.TenantID; right.RightName = rightParam.RightName; right.FunctionLevelRights_Group_RefID = Guid.Empty; right.Save(Connection, Transaction); } } var right2account = new ORM_USR_Account_2_FunctionLevelRight(); right2account.Account_RefID = account.USR_AccountID; right2account.FunctionLevelRight_RefID = rightParam.RightID; right2account.Tenant_RefID = Parameter.TenantID; right2account.Save(Connection, Transaction); } } } returnValue.Result = employee.CMN_BPT_EMP_EmployeeID; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6DR_SD_1537 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { //Leave UserCode region to enable user code saving #region UserCode var returnValue = new FR_Guid(); //Put your code here if (Parameter.CMN_BPT_BusinessParticipantID == Guid.Empty) { #region Create Mode #region BusinessParticipant ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant(); bParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = Guid.NewGuid(); bParticipant.IsNaturalPerson = true; bParticipant.Tenant_RefID = securityTicket.TenantID; bParticipant.Creation_Timestamp = DateTime.Now; bParticipant.Save(Connection, Transaction); #endregion #region Account ORM_USR_Account account = new ORM_USR_Account(); account.Username = Parameter.FirstName + "_" + Parameter.LastName; account.AccountType = 3; account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; account.Tenant_RefID = securityTicket.TenantID; account.Creation_Timestamp = DateTime.Now; account.Save(Connection, Transaction); P_L2DC_GUDCfT_1505 codeParam = new P_L2DC_GUDCfT_1505(); codeParam.codeLength = 8; var checkCodeValue = cls_GetUniqueDeviceCodeForTenant.Invoke(Connection, Transaction, codeParam, securityTicket).Result; ORM_USR_Device_AccountCode accountCode = new ORM_USR_Device_AccountCode(); accountCode.Account_RefID = account.USR_AccountID; accountCode.AccountCode_Value = checkCodeValue.CodeValue; accountCode.AccountCode_ValidFrom = DateTime.Now; accountCode.AccountCode_CurrentStatus_RefID = Guid.NewGuid(); accountCode.IsAccountCode_Expirable = false; accountCode.Tenant_RefID = securityTicket.TenantID; accountCode.Creation_Timestamp = DateTime.Now; accountCode.Save(Connection, Transaction); ORM_USR_Device_AccountCode_StatusHistory Device_AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory(); Device_AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID = accountCode.AccountCode_CurrentStatus_RefID; Device_AccountCode_StatusHistory.IsAccountCode_Active = true; Device_AccountCode_StatusHistory.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID; Device_AccountCode_StatusHistory.Tenant_RefID = securityTicket.TenantID; Device_AccountCode_StatusHistory.Creation_Timestamp = DateTime.Now; Device_AccountCode_StatusHistory.Save(Connection, Transaction); ORM_USR_Device_AccountCode_UsageHistory USR_Device_AccountCode_UsageHistory = new ORM_USR_Device_AccountCode_UsageHistory(); USR_Device_AccountCode_UsageHistory.USR_Device_AccountCode_UsageHistoryID = Guid.NewGuid(); USR_Device_AccountCode_UsageHistory.Tenant_RefID = securityTicket.TenantID; USR_Device_AccountCode_UsageHistory.Device_AccountCode_RefID = accountCode.USR_Device_AccountCodeID; USR_Device_AccountCode_UsageHistory.Creation_Timestamp = DateTime.Now; USR_Device_AccountCode_UsageHistory.Save(Connection, Transaction); #endregion #region PersonInfo and Adresses ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo(); personInfo.CMN_PER_PersonInfoID = bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; personInfo.Salutation_General = Parameter.Salutation_General; personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; personInfo.PrimaryEmail = Parameter.PrimaryMail; personInfo.Address_RefID = Guid.NewGuid(); personInfo.Tenant_RefID = securityTicket.TenantID; personInfo.Save(Connection, Transaction); ORM_CMN_PER_PersonInfo_2_Address personAdress = new ORM_CMN_PER_PersonInfo_2_Address(); personAdress.AssignmentID = Guid.NewGuid(); personAdress.CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; personAdress.CMN_Address_RefID = personInfo.Address_RefID; personAdress.IsPrimary = true; personAdress.Tenant_RefID = securityTicket.TenantID; personAdress.Save(Connection, Transaction); ORM_CMN_Address adress = new ORM_CMN_Address(); adress.CMN_AddressID = personInfo.Address_RefID; adress.City_Name = Parameter.City_Name; adress.Province_Name = Parameter.Province_Name; adress.Street_Name = Parameter.Street_Name; adress.Street_Number = Parameter.Street_Number; adress.City_PostalCode = Parameter.City_PostalCode; adress.Tenant_RefID = securityTicket.TenantID; adress.Save(Connection, Transaction); #endregion #region Contacts foreach (var parContact in Parameter.Contacts) { ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact(); contact.Content = parContact.Content; contact.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID; contact.Tenant_RefID = securityTicket.TenantID; contact.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; contact.Save(Connection, Transaction); } #endregion #region Driver To Employer ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant bpt_asBP = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); bpt_asBP.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid(); bpt_asBP.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; bpt_asBP.AssociatedParticipant_FunctionName = "Driver"; bpt_asBP.Tenant_RefID = securityTicket.TenantID; bpt_asBP.AssociatedBusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID_Of_Employer; bpt_asBP.Save(Connection, Transaction); #endregion #endregion } else { ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant(); bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID); var personInfo = new ORM_CMN_PER_PersonInfo(); personInfo.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID); personInfo.Salutation_General = Parameter.Salutation_General; personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; personInfo.PrimaryEmail = Parameter.PrimaryMail; personInfo.Save(Connection, Transaction); ORM_CMN_Address adress = new ORM_CMN_Address(); adress.Load(Connection, Transaction, personInfo.Address_RefID); adress.City_Name = Parameter.City_Name; adress.Province_Name = Parameter.Province_Name; adress.Street_Name = Parameter.Street_Name; adress.Street_Number = Parameter.Street_Number; adress.Save(Connection, Transaction); foreach (var parContact in Parameter.Contacts) { var query = new ORM_CMN_PER_CommunicationContact.Query(); query.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID; query.IsDeleted = false; query.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; var contact = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query).First(); contact.Content = parContact.Content; contact.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID; contact.Save(Connection, Transaction); } var associationQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query(); associationQuery.BusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID; associationQuery.IsDeleted = false; var bpt_asBP = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associationQuery).First(); bpt_asBP.AssociatedBusinessParticipant_RefID = Parameter.CMN_BPT_BusinessParticipantID_Of_Employer; bpt_asBP.Save(Connection, Transaction); } return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5EM_SE_1657 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); //Put your code here ORM_CMN_Address address = new ORM_CMN_Address(); if (Parameter.CMN_AddressID != Guid.Empty) { var result = address.Load(Connection, Transaction, Parameter.CMN_AddressID); if (result.Status != FR_Status.Success || address.CMN_AddressID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } address.City_Name = Parameter.City_Name; address.Street_Name = Parameter.Street_Name; address.Street_Number = Parameter.Street_Number; address.Country_Name = Parameter.Country_Name; address.Province_Name = Parameter.Province_Name; address.Tenant_RefID = securityTicket.TenantID; address.City_PostalCode = Parameter.City_PostalCode; address.Save(Connection, Transaction); CSV2Core.DlTrace.Trace("success address"); ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo(); if (Parameter.CMN_PER_PersonInfoID != Guid.Empty) { var result = person.Load(Connection, Transaction, Parameter.CMN_PER_PersonInfoID); if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } //person.AccountImage_URL = Parameter.ProfileImage_Document_RefID; person.FirstName = Parameter.FirstName; person.LastName = Parameter.LastName; person.PrimaryEmail = Parameter.PrimaryEmail; person.Tenant_RefID = securityTicket.TenantID; person.Title = Parameter.Title; person.Address_RefID = address.CMN_AddressID; person.ProfileImage_Document_RefID = Parameter.ImageID; person.BirthDate = Parameter.BirthDate; person.NumberOfChildren = Parameter.TaxInfoParameter != null ? Parameter.TaxInfoParameter.NumberOfChildren : 0; person.Save(Connection, Transaction); CSV2Core.DlTrace.Trace("success persopm"); var contactQuery = new ORM_CMN_PER_CommunicationContact.Query(); contactQuery.Tenant_RefID = securityTicket.TenantID; contactQuery.PersonInfo_RefID = person.CMN_PER_PersonInfoID; contactQuery.IsDeleted = false; var deleteContacts = ORM_CMN_PER_CommunicationContact.Query.SoftDelete(Connection, Transaction, contactQuery); foreach (var parContact in Parameter.Contacts) { ORM_CMN_PER_CommunicationContact contact = new ORM_CMN_PER_CommunicationContact(); if (parContact.CMN_PER_CommunicationContactID != Guid.Empty) { var result = contact.Load(Connection, Transaction, parContact.CMN_PER_CommunicationContactID); if (result.Status != FR_Status.Success || contact.CMN_PER_CommunicationContactID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } contact.Content = parContact.Content; contact.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID; contact.Tenant_RefID = securityTicket.TenantID; contact.PersonInfo_RefID = person.CMN_PER_PersonInfoID; contact.Save(Connection, Transaction); CSV2Core.DlTrace.Trace("success contact"); } ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant(); if (Parameter.CMN_BPT_BusinessParticipantID != Guid.Empty) { var result = bParticipant.Load(Connection, Transaction, Parameter.CMN_BPT_BusinessParticipantID); if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } bParticipant.DisplayName = Parameter.DisplayName; bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID; bParticipant.IsNaturalPerson = true; bParticipant.Tenant_RefID = securityTicket.TenantID; bParticipant.Save(Connection, Transaction); ORM_CMN_BPT_EMP_Employee employee = new ORM_CMN_BPT_EMP_Employee(); CSV2Core.DlTrace.Trace("success bpart"); if (Parameter.CMN_BPT_EMP_EmployeeID != Guid.Empty) { var result = employee.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_EmployeeID); if (result.Status != FR_Status.Success || employee.CMN_BPT_EMP_EmployeeID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } employee.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; employee.Staff_Number = Parameter.Staff_Number; employee.StandardFunction = Parameter.StandardFunction; employee.Tenant_RefID = securityTicket.TenantID; employee.Save(Connection, Transaction); CSV2Core.DlTrace.Trace("success employee"); ORM_CMN_BPT_EMP_EmploymentRelationship employmentRelationship = new ORM_CMN_BPT_EMP_EmploymentRelationship(); if (Parameter.CMN_BPT_EMP_Employee_EmploymentRelationshipID != Guid.Empty) { var result = employmentRelationship.Load(Connection, Transaction, Parameter.CMN_BPT_EMP_Employee_EmploymentRelationshipID); if (result.Status != FR_Status.Success || employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } employmentRelationship.Work_StartDate = Parameter.Work_StartDate; bool resignationDateChanged = false; if (employmentRelationship.Work_EndDate != Parameter.Work_EndDate) { resignationDateChanged = true; } employmentRelationship.Work_EndDate = Parameter.Work_EndDate; employmentRelationship.Tenant_RefID = securityTicket.TenantID; employmentRelationship.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID; employmentRelationship.Save(Connection, Transaction); CSV2Core.DlTrace.Trace("success employmentRelationship"); if (Parameter.Work_EndDate.Ticks != 0) { ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query empRelationShipToWorkingContractQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query(); empRelationShipToWorkingContractQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID; empRelationShipToWorkingContractQuery.Tenant_RefID = securityTicket.TenantID; empRelationShipToWorkingContractQuery.IsDeleted = false; List <ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract> workingContractAssignments = ORM_CMN_BPT_EMP_EmploymentRelationship_2_WorkingContract.Query.Search(Connection, Transaction, empRelationShipToWorkingContractQuery); foreach (var workingContractAssignment in workingContractAssignments) { ORM_CMN_BPT_EMP_WorkingContract workingContract = new ORM_CMN_BPT_EMP_WorkingContract(); if (workingContractAssignment.WorkingContract_RefID != Guid.Empty) { var result = workingContract.Load(Connection, Transaction, workingContractAssignment.WorkingContract_RefID); if (result.Status != FR_Status.Success || workingContract.CMN_BPT_EMP_WorkingContractID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } if (workingContract.Contract_EndDate.Ticks == 0 || workingContract.Contract_EndDate.Ticks > Parameter.Work_EndDate.Ticks) { workingContract.Contract_EndDate = Parameter.Work_EndDate; workingContract.IsContractEndDateDefined = true; workingContract.Save(Connection, Transaction); } } } var activeTimeFrame = cls_Get_Active_CalculationTimeFrame.Invoke(Connection, Transaction, securityTicket).Result; var timeframes = cls_Get_CalculationTimeFramesForTenant.Invoke(Connection, Transaction, securityTicket).Result.ToList(); var resultFrames = timeframes.Where(i => i.CalculationTimeframe_StartDate.Year == employmentRelationship.Work_StartDate.Year).ToList(); if (resultFrames.Count == 0) { var newFrame = new ORM_CMN_CAL_CalculationTimeframe(); int currentYear = Parameter.Work_StartDate.Year; while (currentYear < activeTimeFrame.CalculationTimeframe_StartDate.Year) { if (!timeframes.Any(i => i.CalculationTimeframe_StartDate.Year == currentYear)) { newFrame.CalculationTimeframe_StartDate = new DateTime(currentYear, 1, 1); newFrame.CalculationTimeframe_EstimatedEndDate = new DateTime(currentYear, 12, 31); newFrame.Tenant_RefID = securityTicket.TenantID; newFrame.Save(Connection, Transaction); newFrame = new ORM_CMN_CAL_CalculationTimeframe(); } currentYear++; ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe relationshipFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe(); relationshipFrame.CalculationTimeframe_RefID = newFrame.CMN_CAL_CalculationTimeframeID; relationshipFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID; relationshipFrame.Tenant_RefID = securityTicket.TenantID; relationshipFrame.Save(Connection, Transaction); } } else { timeframes = timeframes.Where(i => i.CalculationTimeframe_StartDate.Year < activeTimeFrame.CalculationTimeframe_StartDate.Year && i.CalculationTimeframe_StartDate.Year >= employmentRelationship.Work_StartDate.Year).ToList(); foreach (var timeframe in timeframes) { ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query relationshipFrameQuery = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query(); relationshipFrameQuery.CalculationTimeframe_RefID = timeframe.CMN_CAL_CalculationTimeframeID; relationshipFrameQuery.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID; relationshipFrameQuery.Tenant_RefID = securityTicket.TenantID; List <ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe> oldContractFrames = ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe.Query.Search(Connection, Transaction, relationshipFrameQuery); if (oldContractFrames.Count == 0) { ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe relationshipFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe(); relationshipFrame.CalculationTimeframe_RefID = timeframe.CMN_CAL_CalculationTimeframeID; relationshipFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID; relationshipFrame.Tenant_RefID = securityTicket.TenantID; relationshipFrame.Save(Connection, Transaction); } } } P_L5EM_GAERCTFFE_1405 timeFrameParam = new P_L5EM_GAERCTFFE_1405(); timeFrameParam.EmployeeID = employee.CMN_BPT_EMP_EmployeeID; L5EM_GAERCTFFE_1405 employeeTimeFrame = cls_Get_Active_EmployeeRelationshipTimeFrame_For_EmployeeID.Invoke(Connection, Transaction, timeFrameParam, securityTicket).Result; if (employeeTimeFrame == null) { ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe timeFrame = new ORM_CMN_BPT_EMP_EmploymentRelationship_Timeframe(); timeFrame.CalculationTimeframe_RefID = activeTimeFrame.CMN_CAL_CalculationTimeframeID; timeFrame.EmploymentRelationship_RefID = employmentRelationship.CMN_BPT_EMP_EmploymentRelationshipID; timeFrame.Tenant_RefID = securityTicket.TenantID; timeFrame.Save(Connection, Transaction); CSV2Core.DlTrace.Trace("success timeFrame"); } //save employee professions P_L5EM_SEP_1447 saveProfessionsPar = new P_L5EM_SEP_1447(); saveProfessionsPar.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID; saveProfessionsPar.FunctionHistories = Parameter.FunctionHistories; cls_Save_EmployeeFunctionHistory.Invoke(Connection, Transaction, saveProfessionsPar, securityTicket); CSV2Core.DlTrace.Trace("success employee function history"); //save workplace histories P_L5EM_SWPH_1625 saveWorkplaceHistoryPar = new P_L5EM_SWPH_1625(); saveWorkplaceHistoryPar.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID; saveWorkplaceHistoryPar.WorkplaceHistories = Parameter.WorkplaceHistories; cls_Save_WorkplaceHistories.Invoke(Connection, Transaction, saveWorkplaceHistoryPar, securityTicket); CSV2Core.DlTrace.Trace("success workplaceHistories"); P_L5EM_SUED_1648 saveDocuments = new P_L5EM_SUED_1648(); saveDocuments.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID; saveDocuments.Documents = Parameter.Documents; cls_Save_Uploaded_Employee_Document.Invoke(Connection, Transaction, saveDocuments, securityTicket); CSV2Core.DlTrace.Trace("success documents"); P_L5EM_SEQS_0959 saveSkillsPar = new P_L5EM_SEQS_0959(); saveSkillsPar.Employee_RefID = employee.CMN_BPT_EMP_EmployeeID; saveSkillsPar.Skills = Parameter.Skills; cls_Save_Employee_QualificationSkills.Invoke(Connection, Transaction, saveSkillsPar, securityTicket); CSV2Core.DlTrace.Trace("success skills"); CSV2Core.DlTrace.Trace("AccountID :" + Parameter.USR_AccountID); if (Parameter.USR_AccountID != null && Parameter.USR_AccountID != Guid.Empty) { CSV2Core.DlTrace.Trace("success param"); ORM_USR_Account account = new ORM_USR_Account(); if (Parameter.USR_AccountID != Guid.Empty) { var result = account.Load(Connection, Transaction, Parameter.USR_AccountID); if (account.USR_AccountID == Guid.Empty) { account.USR_AccountID = Guid.NewGuid(); account.AccountType = 2; } account.Username = Parameter.username; account.DefaultLanguage_RefID = Parameter.LanguageID; account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; account.Tenant_RefID = securityTicket.TenantID; account.Save(Connection, Transaction); var personToAccountQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query(); personToAccountQuery.Tenant_RefID = securityTicket.TenantID; personToAccountQuery.USR_Account_RefID = account.USR_AccountID; personToAccountQuery.IsDeleted = false; var personToAccounts = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, personToAccountQuery); if (personToAccounts.Count != 0) { ORM_CMN_PER_PersonInfo_2_Account personToAccount = personToAccounts[0]; personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID; personToAccount.USR_Account_RefID = account.USR_AccountID; personToAccount.Tenant_RefID = securityTicket.TenantID; personToAccount.Save(Connection, Transaction); } else { ORM_CMN_PER_PersonInfo_2_Account personToAccount = new ORM_CMN_PER_PersonInfo_2_Account(); personToAccount.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID; personToAccount.USR_Account_RefID = account.USR_AccountID; personToAccount.Tenant_RefID = securityTicket.TenantID; personToAccount.Save(Connection, Transaction); } } if (Parameter.Rights != null) { foreach (var rightsParam in Parameter.Rights) { if (rightsParam.RightAssinmentID == Guid.Empty && rightsParam.RightID != Guid.Empty) { var right2account = new ORM_USR_Account_2_FunctionLevelRight(); right2account.Account_RefID = Parameter.USR_AccountID; right2account.FunctionLevelRight_RefID = rightsParam.RightID; right2account.Tenant_RefID = securityTicket.TenantID; right2account.Save(Connection, Transaction); CSV2Core.DlTrace.Trace("success save right: " + right2account.FunctionLevelRight_RefID); } if (rightsParam.RightAssinmentID != Guid.Empty && rightsParam.RightID == Guid.Empty) { var right2account = new ORM_USR_Account_2_FunctionLevelRight(); if (rightsParam.RightAssinmentID != Guid.Empty) { var result = right2account.Load(Connection, Transaction, rightsParam.RightAssinmentID); if (result.Status != FR_Status.Success || right2account.AssignmentID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } right2account.IsDeleted = true; right2account.Save(Connection, Transaction); CSV2Core.DlTrace.Trace("success save right2Acc: " + right2account.FunctionLevelRight_RefID); } } } } CSV2Core.DlTrace.Trace("emp id wtf " + Parameter.CMN_BPT_EMP_EmployeeID); if (Parameter.CMN_BPT_EMP_EmployeeID == Guid.Empty || resignationDateChanged) { var enterpriseService = InfrastructureFactory.CreateEnterpriseService(); KeyPerformanceIndicator action = new KeyPerformanceIndicator(); action.PerformedByAccountID = securityTicket.AccountID; action.PerformedByApplicationID = Parameter.ApplicationID; action.PerformedOn = DateTime.Now; action.PerformedByTenantID = securityTicket.TenantID; action.KeyPerformanceIndicatorID = Guid.Parse("4dda967a-5399-4929-afae-7af64699895b"); action.Value = cls_Get_Employees_For_Tenant.Invoke(Connection, Transaction, securityTicket).Result.Where(i => i.Work_EndDate.Ticks == 0 || i.Work_EndDate.Ticks > DateTime.Now.Ticks).ToArray().Length; var result = enterpriseService.SendMessage(action.ToPayload(), KeyPerformanceIndicator.MESSAGE_TYPE, Parameter.ApplicationID, EMessageRecipient.CUSTOMER_MANAGEMENT_PLATFORM); // ServerLog.Instance.Info("Enterprise message sending " + (result.Code == 200 ? "successful" : "failed")); CSV2Core.DlTrace.Trace("success send kpi"); } Parameter.TaxInfoParameter.EmployeeID = employee.CMN_BPT_EMP_EmployeeID; Parameter.TaxInfoParameter.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID; cls_Save_Employee_TaxInformation.Invoke(Connection, Transaction, Parameter.TaxInfoParameter, securityTicket); cls_Save_Employee_BankAccount.Invoke(Connection, Transaction, Parameter.BankAccountParameter, securityTicket); Parameter.SocialSecurity.CMN_PER_PersonInfoID = person.CMN_PER_PersonInfoID; Parameter.SocialSecurity.CMN_BPT_EMP_EmployeeID = employee.CMN_BPT_EMP_EmployeeID; Parameter.SocialSecurity.CMN_BPT_BusinessParticipantID = bParticipant.CMN_BPT_BusinessParticipantID; cls_Save_Employee_SocialSecurity.Invoke(Connection, Transaction, Parameter.SocialSecurity, securityTicket); returnValue.Result = employee.CMN_BPT_EMP_EmployeeID; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OD_SD_1130 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); Guid accounrRefID = Guid.Empty; var doctorQuery = new ORM_HEC_Doctor.Query(); ORM_HEC_Doctor doctor; if (Parameter.HEC_DoctorID != Guid.Empty) { doctorQuery.HEC_DoctorID = Parameter.HEC_DoctorID; doctor = ORM_HEC_Doctor.Query.Search(Connection, Transaction, doctorQuery).First(); accounrRefID = doctor.Account_RefID; } P_L3MD_SDBI_1349 sbdParam = new P_L3MD_SDBI_1349(); sbdParam.DoctorID = Parameter.HEC_DoctorID; sbdParam.Account_RefID = accounrRefID; sbdParam.FirstName = Parameter.FirstName; sbdParam.LastName = Parameter.LastName; sbdParam.isOphthalSave = true; sbdParam.ifOphthal_Salutation_General = Parameter.Salutation_General; sbdParam.ifOphthal_Salutation_Letter = Parameter.Salutation_Letter; sbdParam.Title = Parameter.Title; List <P_L3MD_SDBI_1349_Contacts> contactsParams = new List <P_L3MD_SDBI_1349_Contacts>(); if (Parameter.Contacts != null) { foreach (var item in Parameter.Contacts) { var c = new P_L3MD_SDBI_1349_Contacts(); c.CMN_PER_CommunicationContact_TypeID = item.CMN_PER_CommunicationContact_TypeID; c.Content = item.Content; contactsParams.Add(c); } } sbdParam.Contacts = contactsParams.ToArray(); List <P_L3MD_SDBI_1349_Practice> practicesParams = new List <P_L3MD_SDBI_1349_Practice>(); if (Parameter.Practices != null) { foreach (var item in Parameter.Practices) { var p = new P_L3MD_SDBI_1349_Practice(); p.PracticeID = item.PracticeID; p.isDeleted = item.isDeleted; p.AssociatedParticipant_FunctionName = item.AssociatedParticipant_FunctionName; practicesParams.Add(p); } } sbdParam.Practices = practicesParams.ToArray(); var docID = cls_Save_Doctor_BaseInfo.Invoke(Connection, Transaction, sbdParam, securityTicket).Result; doctorQuery = new ORM_HEC_Doctor.Query(); doctorQuery.HEC_DoctorID = docID; doctor = ORM_HEC_Doctor.Query.Search(Connection, Transaction, doctorQuery).First(); var bParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); bParticipantQuery.CMN_BPT_BusinessParticipantID = doctor.BusinessParticipant_RefID; var bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQuery).First(); ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative SalesRepresentative; var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query(); customerQuery.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; var customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).FirstOrDefault(); if (customer == null) { customer = new ORM_CMN_BPT_CTM_Customer(); customer.CMN_BPT_CTM_CustomerID = Guid.NewGuid(); customer.Tenant_RefID = securityTicket.TenantID; SalesRepresentative = new ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative(); SalesRepresentative.AssignmentID = Guid.NewGuid(); SalesRepresentative.Customer_RefID = customer.CMN_BPT_CTM_CustomerID; SalesRepresentative.Tenant_RefID = securityTicket.TenantID; customer.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; } else { customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).First(); var SalesRepresentativeQuery = new ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query(); SalesRepresentativeQuery.Customer_RefID = customer.CMN_BPT_CTM_CustomerID; SalesRepresentative = ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative.Query.Search(Connection, Transaction, SalesRepresentativeQuery).First(); } SalesRepresentative.SalesRepresentative_RefID = Parameter.CMN_BPT_SalesRepresentativeID; var sRepresentativeQuery = new ORM_CMN_BPT_SalesRepresentative.Query(); sRepresentativeQuery.CMN_BPT_SalesRepresentativeID = Parameter.CMN_BPT_SalesRepresentativeID; sRepresentativeQuery.IsDeleted = false; var sRepresentative = ORM_CMN_BPT_SalesRepresentative.Query.Search(Connection, Transaction, sRepresentativeQuery).FirstOrDefault(); if (sRepresentative == null) { sRepresentative = new ORM_CMN_BPT_SalesRepresentative(); sRepresentative.CMN_BPT_SalesRepresentativeID = Parameter.CMN_BPT_SalesRepresentativeID; sRepresentative.Save(Connection, Transaction); } customer.Save(Connection, Transaction); SalesRepresentative.Save(Connection, Transaction); ORM_USR_Account account; ORM_USR_Device_AccountCode code; ORM_USR_Device_AccountCode_StatusHistory codeStatus; var accountQuery = new ORM_USR_Account.Query(); accountQuery.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; accountQuery.AccountType = 3; var accountQueryRes = ORM_USR_Account.Query.Search(Connection, Transaction, accountQuery); if (accountQueryRes.Count == 0) { account = new ORM_USR_Account(); account.USR_AccountID = Guid.NewGuid(); account.Tenant_RefID = securityTicket.TenantID; account.AccountType = 3; account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; account.Save(Connection, Transaction); code = new ORM_USR_Device_AccountCode(); code.Tenant_RefID = securityTicket.TenantID; code.USR_Device_AccountCodeID = Guid.NewGuid(); code.Account_RefID = account.USR_AccountID; code.AccountCode_ValidFrom = DateTime.Now; codeStatus = new ORM_USR_Device_AccountCode_StatusHistory(); codeStatus.USR_Device_AccountCode_StatusHistoryID = Guid.NewGuid(); codeStatus.Device_AccountCode_RefID = code.USR_Device_AccountCodeID; codeStatus.Tenant_RefID = securityTicket.TenantID; codeStatus.IsAccountCode_Active = true; codeStatus.Save(Connection, Transaction); code.AccountCode_CurrentStatus_RefID = codeStatus.USR_Device_AccountCode_StatusHistoryID; L3DAC_GDACFTCV_1616 checkCodeValue; P_L3DAC_GDACFTCV_1616 codeParam = new P_L3DAC_GDACFTCV_1616(); string codeValue; do { codeValue = RandomString.Generate(8); codeParam.CodeValue = codeValue; checkCodeValue = cls_GetDeviceAccountCodeForTenantAndCodeValue.Invoke(Connection, Transaction, codeParam, securityTicket).Result; } while (checkCodeValue != null); code.AccountCode_Value = codeValue; code.Save(Connection, Transaction); } returnValue.Result = docID; return(returnValue); #endregion UserCode }
protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L5ZW_SDfNC_1707 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Bool(); returnValue.Result = false; //Put your code here #region get securityTicket and businessParticipantID by Paramter.AccountID and set defaultLanguageID Guid tenantID; Guid businessParticipantID; if (Parameter.AccountID == Guid.Empty) { return(returnValue); } ORM_USR_Account orm_account = new ORM_USR_Account(); var result = orm_account.Load(Connection, Transaction, Parameter.AccountID); if (result.Status != FR_Status.Success || orm_account.USR_AccountID == Guid.Empty) { return(returnValue); } tenantID = orm_account.Tenant_RefID; securityTicket = new CSV2Core.SessionSecurity.SessionSecurityTicket() { TenantID = tenantID }; ORM_CMN_BPT_BusinessParticipant.Query businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); businessParticipantQuery.IfTenant_Tenant_RefID = tenantID; businessParticipantQuery.IsDeleted = false; ORM_CMN_BPT_BusinessParticipant businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).FirstOrDefault(); if (businessParticipant == null) { return(returnValue); } businessParticipantID = businessParticipant.CMN_BPT_BusinessParticipantID; #endregion #region get languages for tenant and set parameter dict values P_L2LN_GALFTID_1530 languageParam = new P_L2LN_GALFTID_1530() { Tenant_RefID = tenantID }; L2LN_GALFTID_1530[] languages = cls_Get_All_Languages_ForTenantID.Invoke(Connection, Transaction, languageParam, securityTicket).Result; SetParameterDictValues(Parameter, languages); List <ISOLanguage> languagesISOs = new List <ISOLanguage>(); languagesISOs.AddRange(languages.Select(l => new ISOLanguage() { ISO = l.ISO_639_1, LanguageID = l.CMN_LanguageID }).ToList()); #endregion #region save defaultLanguage // We are setting language for bp and acc var defaultLanguage = languages.FirstOrDefault(i => i.ISO_639_1.ToLower().Contains(Parameter.DefaultLanguageCode.ToLower())); if (defaultLanguage != null) { businessParticipant.DefaultLanguage_RefID = defaultLanguage.CMN_LanguageID; businessParticipant.Save(Connection, Transaction); orm_account.DefaultLanguage_RefID = defaultLanguage.CMN_LanguageID; orm_account.Save(Connection, Transaction); } #endregion #region save default country if (Parameter.DefaultCountry != null) { ORM_CMN_Country country = new ORM_CMN_Country(); country.CMN_CountryID = Guid.NewGuid(); country.Country_ISOCode_Alpha3 = Parameter.DefaultCountry.Code; country.Country_Name = new Dict() { DictionaryID = Guid.NewGuid() }; country.Creation_Timestamp = DateTime.Now; country.Default_Currency_RefID = Guid.Empty; country.Default_Language_RefID = Guid.Empty; country.Tenant_RefID = tenantID; country.IsDeleted = false; country.IsDefault = true; foreach (var languageItem in languages) { country.Country_Name.UpdateEntry(languageItem.CMN_LanguageID, Parameter.DefaultCountry.Name); } country.Save(Connection, Transaction); } #endregion #region save default currency //asign currency if (Parameter.DefaultCurrency != null) { ORM_CMN_Currency currency = new ORM_CMN_Currency(); currency.CMN_CurrencyID = Guid.NewGuid(); currency.Creation_Timestamp = DateTime.Now; currency.IsDeleted = false; currency.ISO4127 = Parameter.DefaultCurrency.Code; currency.Name = new Dict() { DictionaryID = Guid.NewGuid() }; currency.Tenant_RefID = tenantID; foreach (var language in languages) { currency.Name.UpdateEntry(language.CMN_LanguageID, Parameter.DefaultCurrency.Name); } currency.Save(Connection, Transaction); //set default currency ORM_CMN_BPT_BusinessParticipant businessPart = new ORM_CMN_BPT_BusinessParticipant(); businessPart.Load(Connection, Transaction, businessParticipantID); businessPart.DefaultCurrency_RefID = currency.CMN_CurrencyID; businessPart.Save(Connection, Transaction); } #endregion #region save organisational units if (Parameter.OrganisationalUnitParameters.Length > 0) { foreach (var item in Parameter.OrganisationalUnitParameters) { cls_Save_Office.Invoke(Connection, Transaction, item, securityTicket); } } #endregion #region save cost centers if (Parameter.CostCenterParameters.Length > 0) { foreach (var item in Parameter.CostCenterParameters) { cls_Save_CostCenter.Invoke(Connection, Transaction, item, securityTicket); } } #endregion #region save warehouses if (Parameter.WarehousesParameters.Length > 0) { #region save warehouse group P_L2WH_SWHG_1327 warehouseGroupParam = new P_L2WH_SWHG_1327(); warehouseGroupParam.Parent_RefID = Guid.Empty; warehouseGroupParam.WarehouseGroup_Name = "Waregouse group"; warehouseGroupParam.WarehouseGroup_Description = new Dict() { DictionaryID = Guid.NewGuid() }; foreach (var language in languages) { warehouseGroupParam.WarehouseGroup_Description.UpdateEntry(language.CMN_LanguageID, String.Empty); } var warehouseGroupID = cls_Save_Warehouse_Group.Invoke(Connection, Transaction, warehouseGroupParam, securityTicket).Result; #endregion foreach (var item in Parameter.WarehousesParameters) { item.LOG_WRH_WarehouseGroupID = warehouseGroupID; cls_Save_Warehouse.Invoke(Connection, Transaction, item, securityTicket); } } #endregion #region create dimension templates string jsonTemplates = ReadFromFile.LoadContentFromFile(@"Dimensions.json"); List <Dimension> dimensionTemplates = JsonConvert.DeserializeObject <List <Dimension> >(jsonTemplates); int orderSequence = 1; ORM_CMN_PRO_Dimension orm_dimension; ORM_CMN_PRO_Dimension_Value orm_dimensionValue; foreach (var template in dimensionTemplates) { orderSequence = 1; #region save dimension orm_dimension = new ORM_CMN_PRO_Dimension(); orm_dimension.Product_RefID = Guid.Empty; orm_dimension.DimensionName = new Dict() { DictionaryID = Guid.NewGuid() }; orm_dimension.IsDimensionTemplate = true; orm_dimension.Tenant_RefID = tenantID; foreach (var language in languages) { orm_dimension.DimensionName.UpdateEntry(language.CMN_LanguageID, template.Name); } orm_dimension.Save(Connection, Transaction); #endregion #region save dimension values foreach (var templateValue in template.DimansionValues) { orm_dimensionValue = new ORM_CMN_PRO_Dimension_Value(); orm_dimensionValue.Dimensions_RefID = orm_dimension.CMN_PRO_DimensionID; orm_dimensionValue.DimensionValue_Text = new Dict() { DictionaryID = Guid.NewGuid() }; orm_dimensionValue.Tenant_RefID = tenantID; orm_dimensionValue.OrderSequence = orderSequence; foreach (var language in languages) { orm_dimensionValue.DimensionValue_Text.UpdateEntry(language.CMN_LanguageID, templateValue); } orm_dimensionValue.Save(Connection, Transaction); orderSequence++; } #endregion } #endregion #region create shipment types string shipmentTypesJson = ReadFromFile.LoadContentFromFile(@"ShipmentTypes.json"); List <ShipmentTypes> shipmentTypes = JsonConvert.DeserializeObject <List <ShipmentTypes> >(shipmentTypesJson); ORM_LOG_SHP_Shipment_Type orm_shipmentType; foreach (var type in shipmentTypes) { #region save LOG_SHP_Shipment_Type orm_shipmentType = new ORM_LOG_SHP_Shipment_Type(); orm_shipmentType.ShipmentType_Name = new Dict() { DictionaryID = Guid.NewGuid() }; orm_shipmentType.ShipmentType_Description = new Dict() { DictionaryID = Guid.NewGuid() }; orm_shipmentType.Tenant_RefID = tenantID; foreach (var language in languages) { orm_shipmentType.ShipmentType_Name.UpdateEntry(language.CMN_LanguageID, type.Name); orm_shipmentType.ShipmentType_Description.UpdateEntry(language.CMN_LanguageID, string.Empty); } orm_shipmentType.Save(Connection, Transaction); #endregion } #endregion #region create number ranges string numberRangesJson = ReadFromFile.LoadContentFromFile(@"NumberRanges.json"); NumberRange numberRanges = JsonConvert.DeserializeObject <NumberRange>(numberRangesJson); ORM_CMN_NumberRange_UsageArea numberRangeUsageArea; ORM_CMN_NumberRange orm_numberRanges; foreach (var item in numberRanges.NumberRanges) { if (Parameter.IsCustomerRegistration && item.Name == "Customer orders") { continue; } if (!Parameter.IsCustomerRegistration && item.Name == "Distribution orders") { continue; } if (!Parameter.IsCustomerRegistration && item.Name == "Procurement orders") { continue; } numberRangeUsageArea = new ORM_CMN_NumberRange_UsageArea(); numberRangeUsageArea.UsageArea_Name = new Dict() { DictionaryID = Guid.NewGuid() }; numberRangeUsageArea.UsageArea_Description = new Dict() { DictionaryID = Guid.NewGuid() }; foreach (var language in languages) { numberRangeUsageArea.UsageArea_Name.UpdateEntry(language.CMN_LanguageID, item.Name); numberRangeUsageArea.UsageArea_Description.UpdateEntry(language.CMN_LanguageID, string.Empty); } numberRangeUsageArea.Tenant_RefID = tenantID; numberRangeUsageArea.GlobalStaticMatchingID = item.GlobalStaticMatchingID; numberRangeUsageArea.Save(Connection, Transaction); orm_numberRanges = new ORM_CMN_NumberRange(); orm_numberRanges.NumberRange_Name = item.Name; orm_numberRanges.Tenant_RefID = tenantID; orm_numberRanges.NumberRange_UsageArea_RefID = numberRangeUsageArea.CMN_NumberRange_UsageAreaID; orm_numberRanges.FixedPrefix = item.FixedPrefix; orm_numberRanges.Formatting_LeadingFillCharacter = item.FillCharacter; orm_numberRanges.Formatting_NumberLength = item.Length; orm_numberRanges.Value_Current = item.CurrentValue; orm_numberRanges.Value_Start = item.StartValue; orm_numberRanges.Value_End = item.EndValue; orm_numberRanges.Save(Connection, Transaction); } #endregion #region create inventory change reasons string inventoryChangeReasonsJson = ReadFromFile.LoadContentFromFile(@"InventoryChangeReasons.json"); List <InventoryChangeReasons> inventoryChangeReasons = JsonConvert.DeserializeObject <List <InventoryChangeReasons> >(inventoryChangeReasonsJson); ORM_LOG_WRH_InventoryChangeReason orm_inventoryChangeReason; foreach (var reason in inventoryChangeReasons) { #region save inventory change reason orm_inventoryChangeReason = new ORM_LOG_WRH_InventoryChangeReason(); orm_inventoryChangeReason.GlobalPropertyMatchingID = InventoryChangeReasons.InventoryChangeReasonGlobalPropertyMatchingID + "-" + reason.Name; orm_inventoryChangeReason.InventoryChange_Name = new Dict() { DictionaryID = Guid.NewGuid() }; orm_inventoryChangeReason.InventoryChange_Description = new Dict() { DictionaryID = Guid.NewGuid() }; orm_inventoryChangeReason.Tenant_RefID = tenantID; foreach (var language in languages) { orm_inventoryChangeReason.InventoryChange_Name.UpdateEntry(language.CMN_LanguageID, reason.Name); orm_inventoryChangeReason.InventoryChange_Description.UpdateEntry(language.CMN_LanguageID, string.Empty); } orm_inventoryChangeReason.Save(Connection, Transaction); #endregion } #endregion #region create shipment statuses var shipmentStatuses = Enum.GetValues(typeof(EShipmentStatus)); var shipmentStatusDicts = EnumUtils.GetDictObjectsForStaticListData <EShipmentStatus>( ResourceFilePath.ShipmentStatus, ORM_LOG_SHP_Shipment_Status.TableName, languagesISOs); var statusCodeCount = 1; ORM_LOG_SHP_Shipment_Status shipmentStatus; foreach (EShipmentStatus status in shipmentStatuses) { shipmentStatus = new ORM_LOG_SHP_Shipment_Status(); shipmentStatus.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription((EShipmentStatus)status); shipmentStatus.Status_Code = statusCodeCount++; shipmentStatus.Status_Name = shipmentStatusDicts[EnumUtils.GetEnumDescription((EShipmentStatus)status)]; shipmentStatus.Tenant_RefID = tenantID; shipmentStatus.Save(Connection, Transaction); } #endregion if (Parameter.IsCustomerRegistration) { #region create procurement order statuses var procurementStatuses = Enum.GetValues(typeof(EProcurementStatus)); ORM_ORD_PRC_ProcurementOrder_Status procurementOrderStatus; foreach (EProcurementStatus status in procurementStatuses) { procurementOrderStatus = new ORM_ORD_PRC_ProcurementOrder_Status(); procurementOrderStatus.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(status); procurementOrderStatus.Tenant_RefID = tenantID; procurementOrderStatus.Save(Connection, Transaction); } #endregion } else { #region create customer order statuses var customerOrderStatuses = Enum.GetValues(typeof(ECustomerOrderStatus)); var customerOrderStatusesDicts = EnumUtils.GetDictObjectsForStaticListData <ECustomerOrderStatus>( ResourceFilePath.CustomerOrderStatus, ORM_ORD_CUO_CustomerOrder_Status.TableName, languagesISOs); var count = 1; ORM_ORD_CUO_CustomerOrder_Status customerOrderStatus; foreach (var status in customerOrderStatuses) { customerOrderStatus = new ORM_ORD_CUO_CustomerOrder_Status(); customerOrderStatus.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription((ECustomerOrderStatus)status); customerOrderStatus.Status_Code = count++; customerOrderStatus.Status_Name = customerOrderStatusesDicts[EnumUtils.GetEnumDescription((ECustomerOrderStatus)status)]; customerOrderStatus.Tenant_RefID = tenantID; customerOrderStatus.Save(Connection, Transaction); } #endregion } returnValue.Result = true; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6PA_SMSP_1548 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { //Leave UserCode region to enable user code saving #region UserCode var returnValue = new FR_Guid(); ORM_HEC_Patient patient = new ORM_HEC_Patient(); if (Parameter.HEC_PatientID != Guid.Empty) { var result = patient.Load(Connection, Transaction, Parameter.HEC_PatientID); if (result.Status != FR_Status.Success || patient.HEC_PatientID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } patient.IsPatientParticipationPolicyValidated = Parameter.HasFulfilledParticipationPolicyRequirements; patient.PatientComment = Parameter.Comment; patient.Tenant_RefID = securityTicket.TenantID; ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant(); if (patient.CMN_BPT_BusinessParticipant_RefID != Guid.Empty) { var result = bParticipant.Load(Connection, Transaction, patient.CMN_BPT_BusinessParticipant_RefID); if (result.Status != FR_Status.Success || bParticipant.CMN_BPT_BusinessParticipantID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } bParticipant.IsNaturalPerson = true; bParticipant.Tenant_RefID = securityTicket.TenantID; ORM_CMN_PER_PersonInfo person = new ORM_CMN_PER_PersonInfo(); if (bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID != Guid.Empty) { var result = person.Load(Connection, Transaction, bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID); if (result.Status != FR_Status.Success || person.CMN_PER_PersonInfoID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } } person.FirstName = Parameter.FirstName; person.LastName = Parameter.LastName; person.PrimaryEmail = Parameter.Mail; person.Tenant_RefID = securityTicket.TenantID; person.Salutation_General = Parameter.Salutation; person.Save(Connection, Transaction); bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID; bParticipant.Save(Connection, Transaction); patient.CMN_BPT_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; patient.Save(Connection, Transaction); ORM_CMN_PER_CommunicationContact.Query contactQuery = new ORM_CMN_PER_CommunicationContact.Query(); contactQuery.IsDeleted = false; contactQuery.Tenant_RefID = securityTicket.TenantID; contactQuery.PersonInfo_RefID = person.CMN_PER_PersonInfoID; var contactQueryRes = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, contactQuery); ORM_CMN_PER_CommunicationContact contactPhone = contactQueryRes.FirstOrDefault(c => c.Contact_Type == STLD_ContactTypes.Phone); ORM_CMN_PER_CommunicationContact contactFax = contactQueryRes.FirstOrDefault(c => c.Contact_Type == STLD_ContactTypes.Fax); if (contactPhone == null) { contactPhone = new ORM_CMN_PER_CommunicationContact(); contactPhone.Contact_Type = STLD_ContactTypes.Phone; contactPhone.Tenant_RefID = securityTicket.TenantID; contactPhone.PersonInfo_RefID = person.CMN_PER_PersonInfoID; } contactPhone.Content = Parameter.Phone; contactPhone.Save(Connection, Transaction); if (contactFax == null) { contactFax = new ORM_CMN_PER_CommunicationContact(); contactFax.Content = Parameter.Fax; contactFax.Contact_Type = STLD_ContactTypes.Fax; contactFax.Tenant_RefID = securityTicket.TenantID; contactFax.PersonInfo_RefID = person.CMN_PER_PersonInfoID; contactFax.Save(Connection, Transaction); } contactFax.Content = Parameter.Fax; contactFax.Save(Connection, Transaction); ORM_HEC_Patient_HealthInsurance.Query Patient_HealthInsuranceQuery = new ORM_HEC_Patient_HealthInsurance.Query(); Patient_HealthInsuranceQuery.Tenant_RefID = securityTicket.TenantID; Patient_HealthInsuranceQuery.IsDeleted = false; Patient_HealthInsuranceQuery.Patient_RefID = patient.HEC_PatientID; ORM_HEC_Patient_HealthInsurance Patient_HealthInsurance; var Patient_HealthInsuranceQueryRes = ORM_HEC_Patient_HealthInsurance.Query.Search(Connection, Transaction, Patient_HealthInsuranceQuery); if (Patient_HealthInsuranceQueryRes.Count == 1) { Patient_HealthInsurance = Patient_HealthInsuranceQueryRes[0]; } else { Patient_HealthInsurance = new ORM_HEC_Patient_HealthInsurance(); Patient_HealthInsurance.Patient_RefID = patient.HEC_PatientID; Patient_HealthInsurance.Tenant_RefID = securityTicket.TenantID; Patient_HealthInsurance.IsPrimary = true; } Patient_HealthInsurance.HealthInsurance_Number = Parameter.HealthcareNumber; Patient_HealthInsurance.Save(Connection, Transaction); ORM_HEC_STU_Study_ParticipatingPatient.Query Study_ParticipatingPatientsQuery = new ORM_HEC_STU_Study_ParticipatingPatient.Query(); Study_ParticipatingPatientsQuery.Tenant_RefID = securityTicket.TenantID; Study_ParticipatingPatientsQuery.IsDeleted = false; Study_ParticipatingPatientsQuery.Patient_RefID = patient.HEC_PatientID; ORM_HEC_STU_Study_ParticipatingPatient Study_ParticipatingPatients; var Study_ParticipatingPatientsQueryRes = ORM_HEC_STU_Study_ParticipatingPatient.Query.Search(Connection, Transaction, Study_ParticipatingPatientsQuery); if (Study_ParticipatingPatientsQueryRes.Count == 1) { Study_ParticipatingPatients = Study_ParticipatingPatientsQueryRes[0]; } else { Study_ParticipatingPatients = new ORM_HEC_STU_Study_ParticipatingPatient(); Study_ParticipatingPatients.Patient_RefID = patient.HEC_PatientID; Study_ParticipatingPatients.Tenant_RefID = securityTicket.TenantID; } Study_ParticipatingPatients.HasFulfilledParticipationPolicyRequirements = Parameter.HasFulfilledParticipationPolicyRequirements; Study_ParticipatingPatients.Save(Connection, Transaction); ORM_USR_Account account; ORM_USR_Account.Query ORM_USR_AccountQuery = new ORM_USR_Account.Query(); ORM_USR_AccountQuery.IsDeleted = false; ORM_USR_AccountQuery.Tenant_RefID = securityTicket.TenantID; ORM_USR_AccountQuery.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; var accountRes = ORM_USR_Account.Query.Search(Connection, Transaction, ORM_USR_AccountQuery); if (accountRes.Count == 1) { account = accountRes[0]; } else { account = new ORM_USR_Account(); account.Tenant_RefID = securityTicket.TenantID; account.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; account.AccountType = 3; account.Save(Connection, Transaction); } ORM_USR_Device_AccountCode.Query ORM_USR_Device_AccountCodeQuery = new ORM_USR_Device_AccountCode.Query(); ORM_USR_Device_AccountCodeQuery.IsDeleted = false; ORM_USR_Device_AccountCodeQuery.Tenant_RefID = securityTicket.TenantID; ORM_USR_Device_AccountCodeQuery.Account_RefID = account.USR_AccountID; var accountCodeRes = ORM_USR_Device_AccountCode.Query.Search(Connection, Transaction, ORM_USR_Device_AccountCodeQuery); if (accountCodeRes.Count == 0) { P_L2DC_GUDCfT_1505 codeParam = new P_L2DC_GUDCfT_1505(); codeParam.codeLength = 8; var checkCodeValue = cls_GetUniqueDeviceCodeForTenant.Invoke(Connection, Transaction, codeParam, securityTicket).Result; ORM_USR_Device_AccountCode_StatusHistory AccountCode_StatusHistory = new ORM_USR_Device_AccountCode_StatusHistory(); AccountCode_StatusHistory.Tenant_RefID = securityTicket.TenantID; AccountCode_StatusHistory.IsAccountCode_Active = true; AccountCode_StatusHistory.Save(Connection, Transaction); ORM_USR_Device_AccountCode devoceAccpimtCpde = new ORM_USR_Device_AccountCode(); devoceAccpimtCpde.Account_RefID = account.USR_AccountID; devoceAccpimtCpde.Tenant_RefID = securityTicket.TenantID; devoceAccpimtCpde.AccountCode_Value = checkCodeValue.CodeValue; devoceAccpimtCpde.IsAccountCode_Expirable = false; devoceAccpimtCpde.AccountCode_CurrentStatus_RefID = AccountCode_StatusHistory.USR_Device_AccountCode_StatusHistoryID; devoceAccpimtCpde.Save(Connection, Transaction); AccountCode_StatusHistory.Device_AccountCode_RefID = devoceAccpimtCpde.USR_Device_AccountCodeID; AccountCode_StatusHistory.Save(Connection, Transaction); } returnValue.Result = patient.HEC_PatientID; return(returnValue); #endregion UserCode }