protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3MD_SDBI_1349 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); var doctor = new ORM_HEC_Doctor(); if (Parameter.DoctorID != Guid.Empty) { var result = doctor.Load(Connection, Transaction, Parameter.DoctorID); if (result.Status != FR_Status.Success || doctor.HEC_DoctorID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } #region Edit bool bopAccIsChenged = (doctor.Account_RefID == Parameter.Account_RefID) ? false : true; doctor.Account_RefID = Parameter.Account_RefID; if (Parameter.isLucentisSave) { doctor.DoctorIDNumber = Parameter.ifLucentis_LANR; } doctor.Save(Connection, Transaction); //bussinessParticipant var query1 = new ORM_CMN_BPT_BusinessParticipant.Query(); query1.CMN_BPT_BusinessParticipantID = doctor.BusinessParticipant_RefID; var bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query1).First(); if (!bopAccIsChenged) { //personInfo var query2 = new ORM_CMN_PER_PersonInfo.Query(); query2.CMN_PER_PersonInfoID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First(); personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; personInfo.Title = Parameter.Title; if (Parameter.isOphthalSave) { personInfo.Salutation_General = Parameter.ifOphthal_Salutation_General; personInfo.Salutation_Letter = Parameter.ifOphthal_Salutation_Letter; } if (Parameter.isLucentisSave) { personInfo.PrimaryEmail = Parameter.ifLucentis_LoginEmail; } personInfo.Save(Connection, Transaction); var query4 = new ORM_CMN_PER_CommunicationContact.Query(); query4.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; var communicationContactsList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query4).ToList(); if (Parameter.Contacts != null) { foreach (var parContact in Parameter.Contacts) { ORM_CMN_PER_CommunicationContact communicationContacts = communicationContactsList.FirstOrDefault(c => c.Contact_Type == parContact.CMN_PER_CommunicationContact_TypeID); if (communicationContacts != null) { communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Content = parContact.Content; communicationContacts.Save(Connection, Transaction); } else { communicationContacts = new ORM_CMN_PER_CommunicationContact(); communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContacts.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; communicationContacts.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID; communicationContacts.Content = parContact.Content; communicationContacts.Creation_Timestamp = DateTime.Now; communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Save(Connection, Transaction); } } } } else { var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query(); account2personInfoQuery.USR_Account_RefID = Parameter.Account_RefID; account2personInfoQuery.Tenant_RefID = securityTicket.TenantID; account2personInfoQuery.IsDeleted = false; var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).First(); var query2 = new ORM_CMN_PER_PersonInfo.Query(); query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID; var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First(); personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; personInfo.Title = Parameter.Title; personInfo.Save(Connection, Transaction); var query4 = new ORM_CMN_PER_CommunicationContact.Query(); query4.PersonInfo_RefID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; var communicationContactsList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query4).ToList(); if (communicationContactsList != null) { foreach (var c in communicationContactsList) { c.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; c.Save(Connection, Transaction); } } if (Parameter.Contacts != null) { foreach (var parContact in Parameter.Contacts) { ORM_CMN_PER_CommunicationContact communicationContacts = communicationContactsList.FirstOrDefault(c => c.Contact_Type == parContact.CMN_PER_CommunicationContact_TypeID); if (communicationContacts != null) { communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Content = parContact.Content; communicationContacts.Save(Connection, Transaction); } else { communicationContacts = new ORM_CMN_PER_CommunicationContact(); communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContacts.PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; communicationContacts.Contact_Type = parContact.CMN_PER_CommunicationContact_TypeID; communicationContacts.Content = parContact.Content; communicationContacts.Creation_Timestamp = DateTime.Now; communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Save(Connection, Transaction); } } } bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; bussinessParticipant.Save(Connection, Transaction); } if (Parameter.isLucentisSave) { foreach (var practice in Parameter.Practices) { //if (practice.PracticeID != Guid.Empty) { var medPract = new ORM_HEC_MedicalPractis.Query(); medPract.HEC_MedicalPractiseID = practice.PracticeID; var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First(); var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query(); queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID; var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First(); var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First(); var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query(); query3.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; query3.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID; query3.IsDeleted = false; var associatedbusinessparticipantsOriginal = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3).FirstOrDefault(); if (associatedbusinessparticipantsOriginal != null) { associatedbusinessparticipantsOriginal.IsDeleted = practice.isDeleted; associatedbusinessparticipantsOriginal.Save(Connection, Transaction); } else { var associatedbusinessparticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); associatedbusinessparticipants.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; associatedbusinessparticipants.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID; associatedbusinessparticipants.AssociatedParticipant_FunctionName = practice.AssociatedParticipant_FunctionName; associatedbusinessparticipants.Creation_Timestamp = DateTime.Now; associatedbusinessparticipants.Tenant_RefID = securityTicket.TenantID; associatedbusinessparticipants.Save(Connection, Transaction); // } } } } if (Parameter.isOphthalSave && Parameter.Practices.Length == 1) { var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query(); query3.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; query3.IsDeleted = false; var associatedbusinessparticipantsRes = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3); ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant firstPractice; var medPract = new ORM_HEC_MedicalPractis.Query(); medPract.HEC_MedicalPractiseID = Parameter.Practices[0].PracticeID; var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First(); var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query(); queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID; var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First(); var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First(); if (associatedbusinessparticipantsRes.Count > 0) { associatedbusinessparticipantsRes = associatedbusinessparticipantsRes.OrderBy(a => a.Creation_Timestamp).ToList(); firstPractice = associatedbusinessparticipantsRes.First(); foreach (var item in associatedbusinessparticipantsRes) { if (item != firstPractice && item.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID == practiceBPT.CMN_BPT_BusinessParticipantID) { item.IsDeleted = true; item.Save(Connection, Transaction); } } } else { firstPractice = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); firstPractice.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid(); firstPractice.Tenant_RefID = securityTicket.TenantID; firstPractice.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; } firstPractice.AssociatedParticipant_FunctionName = Parameter.Practices[0].AssociatedParticipant_FunctionName; firstPractice.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID; firstPractice.Save(Connection, Transaction); } #endregion } else { #region Save //personInfo Guid personInfoID; if (Parameter.Account_RefID == Guid.Empty) { var personInfo = new ORM_CMN_PER_PersonInfo(); personInfo.CMN_PER_PersonInfoID = Guid.NewGuid(); personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; if (Parameter.isLucentisSave) { personInfo.PrimaryEmail = Parameter.ifLucentis_LoginEmail; } personInfo.Title = Parameter.Title; personInfo.Creation_Timestamp = DateTime.Now; personInfo.Tenant_RefID = securityTicket.TenantID; if (Parameter.isOphthalSave) { personInfo.Salutation_Letter = Parameter.ifOphthal_Salutation_Letter; personInfo.Salutation_General = Parameter.ifOphthal_Salutation_General; } personInfo.Save(Connection, Transaction); personInfoID = personInfo.CMN_PER_PersonInfoID; } else { var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query(); account2personInfoQuery.USR_Account_RefID = Parameter.Account_RefID; account2personInfoQuery.Tenant_RefID = securityTicket.TenantID; account2personInfoQuery.IsDeleted = false; var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).First(); var query2 = new ORM_CMN_PER_PersonInfo.Query(); query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID; var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First(); personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; personInfo.Title = Parameter.Title; personInfo.Save(Connection, Transaction); personInfoID = personInfo.CMN_PER_PersonInfoID; } //bussinessParticipants var bussinessParticipantTable = new ORM_CMN_BPT_BusinessParticipant(); bussinessParticipantTable.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); bussinessParticipantTable.IsNaturalPerson = true; bussinessParticipantTable.IsTenant = false; bussinessParticipantTable.IsCompany = false; bussinessParticipantTable.IsDeleted = false; bussinessParticipantTable.Creation_Timestamp = DateTime.Now; bussinessParticipantTable.Tenant_RefID = securityTicket.TenantID; bussinessParticipantTable.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID; bussinessParticipantTable.Save(Connection, Transaction); doctor.HEC_DoctorID = Guid.NewGuid(); if (Parameter.isLucentisSave) { doctor.DoctorIDNumber = Parameter.ifLucentis_LANR; } doctor.Creation_Timestamp = DateTime.Now; doctor.Tenant_RefID = securityTicket.TenantID; doctor.BusinessParticipant_RefID = bussinessParticipantTable.CMN_BPT_BusinessParticipantID; doctor.Account_RefID = Parameter.Account_RefID; doctor.Save(Connection, Transaction); if (Parameter.Contacts != null) { foreach (var contact in Parameter.Contacts) { ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact(); communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContacts.PersonInfo_RefID = personInfoID; communicationContacts.Contact_Type = contact.CMN_PER_CommunicationContact_TypeID; communicationContacts.Content = contact.Content; communicationContacts.Creation_Timestamp = DateTime.Now; communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Save(Connection, Transaction); } } foreach (var practice in Parameter.Practices) { if (practice.isDeleted == true) { continue; } var medPract = new ORM_HEC_MedicalPractis.Query(); medPract.HEC_MedicalPractiseID = practice.PracticeID; var medicalPractice = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, medPract).First(); var queryCompanyInfo = new ORM_CMN_COM_CompanyInfo.Query(); queryCompanyInfo.CMN_COM_CompanyInfoID = medicalPractice.Ext_CompanyInfo_RefID; var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, queryCompanyInfo).First(); var practiceQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); practiceQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; var practiceBPT = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, practiceQuery).First(); //associatedbusinessparticipants var associatedbusinessparticipants = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); associatedbusinessparticipants.BusinessParticipant_RefID = bussinessParticipantTable.CMN_BPT_BusinessParticipantID; associatedbusinessparticipants.AssociatedBusinessParticipant_RefID = practiceBPT.CMN_BPT_BusinessParticipantID; associatedbusinessparticipants.AssociatedParticipant_FunctionName = practice.AssociatedParticipant_FunctionName; associatedbusinessparticipants.Creation_Timestamp = DateTime.Now; associatedbusinessparticipants.Tenant_RefID = securityTicket.TenantID; associatedbusinessparticipants.Save(Connection, Transaction); } #endregion } returnValue.Result = doctor.HEC_DoctorID; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3MD_DDbID_1031 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { //Leave UserCode region to enable user code saving #region UserCode var returnValue = new FR_Guid(); var doctor = new ORM_HEC_Doctor(); if (Parameter.DoctorID != Guid.Empty) { var result = doctor.Load(Connection, Transaction, Parameter.DoctorID); if (result.Status != FR_Status.Success || doctor.HEC_DoctorID == Guid.Empty) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } doctor.IsDeleted = true; doctor.Save(Connection, Transaction); //bussinessParticipant var query1 = new ORM_CMN_BPT_BusinessParticipant.Query(); query1.CMN_BPT_BusinessParticipantID = doctor.BusinessParticipant_RefID; var bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query1).First(); bussinessParticipant.IsDeleted = true; bussinessParticipant.Save(Connection, Transaction); if (doctor.Account_RefID != Guid.Empty) { var account2personInfoQuery = new ORM_CMN_PER_PersonInfo_2_Account.Query(); account2personInfoQuery.USR_Account_RefID = doctor.Account_RefID; account2personInfoQuery.Tenant_RefID = securityTicket.TenantID; var account2personInfo = ORM_CMN_PER_PersonInfo_2_Account.Query.Search(Connection, Transaction, account2personInfoQuery).FirstOrDefault(); if (account2personInfo != null) { account2personInfo.IsDeleted = true; account2personInfo.Save(Connection, Transaction); var query2 = new ORM_CMN_PER_PersonInfo.Query(); query2.CMN_PER_PersonInfoID = account2personInfo.CMN_PER_PersonInfo_RefID; var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query2).First(); personInfo.IsDeleted = true; personInfo.Save(Connection, Transaction); } var query4 = new ORM_CMN_PER_CommunicationContact.Query(); query4.PersonInfo_RefID = bussinessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; var communicationContactsList = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query4).ToList(); foreach (var contact in communicationContactsList) { contact.IsDeleted = true; contact.Save(Connection, Transaction); } } var query3 = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query(); query3.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; query3.IsDeleted = false; var abpRes = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, query3); foreach (ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant assigned in abpRes) { assigned.IsDeleted = true; assigned.Save(Connection, Transaction); } #endregion ORM_CMN_BPT_CTM_Customer customer; ORM_CMN_BPT_CTM_Customer_2_SalesRepresentative SalesRepresentative; var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query(); customerQuery.Ext_BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; var customerRes = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery); if (customerRes.Count != 0) { 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(); customer.IsDeleted = true; customer.Save(Connection, Transaction); SalesRepresentative.IsDeleted = true; SalesRepresentative.Save(Connection, Transaction); } var accountQuery = new ORM_USR_Account.Query(); accountQuery.BusinessParticipant_RefID = bussinessParticipant.CMN_BPT_BusinessParticipantID; accountQuery.AccountType = 3; var accountQueryRes = ORM_USR_Account.Query.Search(Connection, Transaction, accountQuery); if (accountQueryRes.Count != 0) { var account = accountQueryRes.First(); account.IsDeleted = true; account.Save(Connection, Transaction); var codeQuery = new ORM_USR_Device_AccountCode.Query(); codeQuery.Account_RefID = account.USR_AccountID; var code = ORM_USR_Device_AccountCode.Query.Search(Connection, Transaction, codeQuery).First(); code.IsDeleted = true; code.Save(Connection, Transaction); var codeStatusQuery = new ORM_USR_Device_AccountCode_StatusHistory.Query(); codeStatusQuery.Device_AccountCode_RefID = code.USR_Device_AccountCodeID; var codeStatus = ORM_USR_Device_AccountCode_StatusHistory.Query.Search(Connection, Transaction, codeStatusQuery).First(); codeStatus.IsDeleted = true; codeStatus.Save(Connection, Transaction); } } returnValue.Result = doctor.HEC_DoctorID; return(returnValue); }