protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PH_SP_1226 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); ORM_HEC_Pharmacy item = new ORM_HEC_Pharmacy(); if (Parameter.PharmacyID != Guid.Empty) { var result = item.Load(Connection, Transaction, Parameter.PharmacyID); if (result.Status != FR_Status.Success) { var error = new FR_Guid(); error.ErrorMessage = "No Such ID"; error.Status = FR_Status.Error_Internal; return(error); } #region Delete if (Parameter.IsDeleted) { //Contact person data finding and deleting var query_BusinessParticipant_ContactPerson_del = new ORM_CMN_BPT_BusinessParticipant.Query(); query_BusinessParticipant_ContactPerson_del.CMN_BPT_BusinessParticipantID = item.ContactPerson_BusinessParticipant_RefID; query_BusinessParticipant_ContactPerson_del.Tenant_RefID = item.Tenant_RefID; ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_ContactPerson_del = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_ContactPerson_del).First(); found_BusinessParticipant_ContactPerson_del.IsDeleted = true; var query_PersonInfo_del = new ORM_CMN_PER_PersonInfo.Query(); query_PersonInfo_del.CMN_PER_PersonInfoID = found_BusinessParticipant_ContactPerson_del.IfNaturalPerson_CMN_PER_PersonInfo_RefID; ORM_CMN_PER_PersonInfo found_PersonInfo_del = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query_PersonInfo_del).First(); found_PersonInfo_del.IsDeleted = true; var query_CommunicationContact_del = new ORM_CMN_PER_CommunicationContact.Query(); query_CommunicationContact_del.PersonInfo_RefID = found_PersonInfo_del.CMN_PER_PersonInfoID; ORM_CMN_PER_CommunicationContact found_CommunicationContact_del = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query_CommunicationContact_del).First(); found_CommunicationContact_del.IsDeleted = true; found_BusinessParticipant_ContactPerson_del.Save(Connection, Transaction); found_CommunicationContact_del.Save(Connection, Transaction); found_PersonInfo_del.Save(Connection, Transaction); //Company (pharmacy) finding and deleting var query_CompanyInfo_del = new ORM_CMN_COM_CompanyInfo.Query(); query_CompanyInfo_del.CMN_COM_CompanyInfoID = item.Ext_CompanyInfo_RefID; ORM_CMN_COM_CompanyInfo found_CompanyInfo_del = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, query_CompanyInfo_del).First(); found_CompanyInfo_del.IsDeleted = true; var query_CompanyContactDetails_del = new ORM_CMN_UniversalContactDetail.Query(); query_CompanyContactDetails_del.CMN_UniversalContactDetailID = found_CompanyInfo_del.Contact_UCD_RefID; ORM_CMN_UniversalContactDetail found_CompanyContactDetails_del = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, query_CompanyContactDetails_del).First(); found_CompanyContactDetails_del.IsDeleted = true; var query_BusinessParticipant_Company_del = new ORM_CMN_BPT_BusinessParticipant.Query(); query_BusinessParticipant_Company_del.IfCompany_CMN_COM_CompanyInfo_RefID = found_CompanyInfo_del.CMN_COM_CompanyInfoID; ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_Company_del = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_Company_del).First(); found_BusinessParticipant_Company_del.IsDeleted = true; found_CompanyInfo_del.Save(Connection, Transaction); found_CompanyContactDetails_del.Save(Connection, Transaction); found_BusinessParticipant_Company_del.Save(Connection, Transaction); item.IsDeleted = true; return(new FR_Guid(item.Save(Connection, Transaction), item.HEC_PharmacyID)); } #endregion #region Edit //Contact person data finding and edit var query_BusinessParticipant_ContactPerson = new ORM_CMN_BPT_BusinessParticipant.Query(); query_BusinessParticipant_ContactPerson.CMN_BPT_BusinessParticipantID = item.ContactPerson_BusinessParticipant_RefID; query_BusinessParticipant_ContactPerson.Tenant_RefID = item.Tenant_RefID; ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_ContactPerson = new ORM_CMN_BPT_BusinessParticipant(); if (item.ContactPerson_BusinessParticipant_RefID != null && item.ContactPerson_BusinessParticipant_RefID != Guid.Empty) { found_BusinessParticipant_ContactPerson = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_ContactPerson).First(); } else { found_BusinessParticipant_ContactPerson = null; } if (found_BusinessParticipant_ContactPerson != null) { var query_PersonInfo = new ORM_CMN_PER_PersonInfo.Query(); query_PersonInfo.CMN_PER_PersonInfoID = found_BusinessParticipant_ContactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID; ORM_CMN_PER_PersonInfo found_PersonInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, query_PersonInfo).First(); found_PersonInfo.FirstName = Parameter.ContactFirstName; found_PersonInfo.LastName = Parameter.ContactLastName; found_PersonInfo.PrimaryEmail = Parameter.ContactEmail; var query_CommunicationContact = new ORM_CMN_PER_CommunicationContact.Query(); query_CommunicationContact.PersonInfo_RefID = found_PersonInfo.CMN_PER_PersonInfoID; ORM_CMN_PER_CommunicationContact found_CommunicationContact = ORM_CMN_PER_CommunicationContact.Query.Search(Connection, Transaction, query_CommunicationContact).First(); found_CommunicationContact.Content = Parameter.ContactPhoneNumber; found_CommunicationContact.Save(Connection, Transaction); found_PersonInfo.Save(Connection, Transaction); } else { ORM_CMN_BPT_BusinessParticipant contactPerson = new ORM_CMN_BPT_BusinessParticipant(); Guid businessParticipantID = Guid.NewGuid(); contactPerson.CMN_BPT_BusinessParticipantID = businessParticipantID; contactPerson.IsCompany = false; contactPerson.IsNaturalPerson = true; contactPerson.IsTenant = false; contactPerson.Creation_Timestamp = DateTime.Now; contactPerson.Tenant_RefID = securityTicket.TenantID; item.ContactPerson_BusinessParticipant_RefID = businessParticipantID; //person info ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo(); Guid personInfoID = Guid.NewGuid(); contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID; contactPerson.Save(Connection, Transaction); personInfo.CMN_PER_PersonInfoID = personInfoID; personInfo.FirstName = Parameter.ContactFirstName; personInfo.LastName = Parameter.ContactLastName; personInfo.PrimaryEmail = Parameter.ContactEmail; personInfo.Creation_Timestamp = DateTime.Now; personInfo.Tenant_RefID = securityTicket.TenantID; personInfo.Save(Connection, Transaction); //Communication Contact ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact(); communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContacts.PersonInfo_RefID = personInfoID; communicationContacts.Contact_Type = Parameter.ContactTypePhone; communicationContacts.Content = Parameter.ContactPhoneNumber; communicationContacts.Creation_Timestamp = DateTime.Now; communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Save(Connection, Transaction); item.ContactPerson_BusinessParticipant_RefID = businessParticipantID; item.Save(Connection, Transaction); } //Company (pharmacy) finding and edit var query_CompanyInfo = new ORM_CMN_COM_CompanyInfo.Query(); query_CompanyInfo.CMN_COM_CompanyInfoID = item.Ext_CompanyInfo_RefID; ORM_CMN_COM_CompanyInfo found_CompanyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, query_CompanyInfo).First(); var query_CompanyContactDetails = new ORM_CMN_UniversalContactDetail.Query(); query_CompanyContactDetails.CMN_UniversalContactDetailID = found_CompanyInfo.Contact_UCD_RefID; ORM_CMN_UniversalContactDetail found_CompanyContactDetails = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, query_CompanyContactDetails).FirstOrDefault(); if (found_CompanyContactDetails != null) { found_CompanyContactDetails.CompanyName_Line1 = Parameter.PharmacyName; found_CompanyContactDetails.Contact_Email = Parameter.MainEmail; found_CompanyContactDetails.Street_Name = Parameter.Street; found_CompanyContactDetails.Street_Number = Parameter.Number; found_CompanyContactDetails.Street_Name_Line2 = Parameter.Street2; found_CompanyContactDetails.Town = Parameter.Town; found_CompanyContactDetails.ZIP = Parameter.ZIP; found_CompanyContactDetails.Save(Connection, Transaction); } else { ORM_CMN_UniversalContactDetail universalContactDetails = new ORM_CMN_UniversalContactDetail(); universalContactDetails.CMN_UniversalContactDetailID = Guid.NewGuid(); universalContactDetails.IsCompany = true; universalContactDetails.CompanyName_Line1 = Parameter.PharmacyName; universalContactDetails.Street_Name = Parameter.Street; universalContactDetails.Street_Name_Line2 = Parameter.Street2; universalContactDetails.Street_Number = Parameter.Number; universalContactDetails.Contact_Email = Parameter.MainEmail; universalContactDetails.ZIP = Parameter.ZIP; universalContactDetails.Town = Parameter.Town; universalContactDetails.Tenant_RefID = securityTicket.TenantID; universalContactDetails.Save(Connection, Transaction); found_CompanyInfo.Contact_UCD_RefID = universalContactDetails.CMN_UniversalContactDetailID; found_CompanyInfo.Save(Connection, Transaction); } var query_BusinessParticipant_Company = new ORM_CMN_BPT_BusinessParticipant.Query(); query_BusinessParticipant_Company.IfCompany_CMN_COM_CompanyInfo_RefID = found_CompanyInfo.CMN_COM_CompanyInfoID; ORM_CMN_BPT_BusinessParticipant found_BusinessParticipant_Company = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, query_BusinessParticipant_Company).First(); found_BusinessParticipant_Company.DisplayName = Parameter.PharmacyName; found_BusinessParticipant_Company.Save(Connection, Transaction); #endregion } else { #region Save item.HEC_PharmacyID = Guid.NewGuid(); item.Creation_Timestamp = DateTime.Now; item.Tenant_RefID = securityTicket.TenantID; //business Participants ORM_CMN_BPT_BusinessParticipant contactPerson = new ORM_CMN_BPT_BusinessParticipant(); Guid businessParticipantID = Guid.NewGuid(); contactPerson.CMN_BPT_BusinessParticipantID = businessParticipantID; contactPerson.IsCompany = false; contactPerson.IsNaturalPerson = true; contactPerson.IsTenant = false; contactPerson.Creation_Timestamp = DateTime.Now; contactPerson.Tenant_RefID = securityTicket.TenantID; item.ContactPerson_BusinessParticipant_RefID = businessParticipantID; //person info ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo(); Guid personInfoID = Guid.NewGuid(); contactPerson.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoID; contactPerson.Save(Connection, Transaction); personInfo.CMN_PER_PersonInfoID = personInfoID; personInfo.FirstName = Parameter.ContactFirstName; personInfo.LastName = Parameter.ContactLastName; personInfo.PrimaryEmail = Parameter.ContactEmail; personInfo.Creation_Timestamp = DateTime.Now; personInfo.Tenant_RefID = securityTicket.TenantID; personInfo.Save(Connection, Transaction); //Communication Contact ORM_CMN_PER_CommunicationContact communicationContacts = new ORM_CMN_PER_CommunicationContact(); communicationContacts.CMN_PER_CommunicationContactID = Guid.NewGuid(); communicationContacts.PersonInfo_RefID = personInfoID; communicationContacts.Contact_Type = Parameter.ContactTypePhone; communicationContacts.Content = Parameter.ContactPhoneNumber; communicationContacts.Creation_Timestamp = DateTime.Now; communicationContacts.Tenant_RefID = securityTicket.TenantID; communicationContacts.Save(Connection, Transaction); //ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo(); //Guid companyInfoID = Guid.NewGuid(); ORM_CMN_COM_CompanyInfo extCompanyInfo = new ORM_CMN_COM_CompanyInfo(); Guid extCompanyInfoID = Guid.NewGuid(); extCompanyInfo.CMN_COM_CompanyInfoID = extCompanyInfoID; Guid contactUCDID = Guid.NewGuid(); extCompanyInfo.Contact_UCD_RefID = contactUCDID; extCompanyInfo.Creation_Timestamp = DateTime.Now; extCompanyInfo.Tenant_RefID = securityTicket.TenantID; item.Ext_CompanyInfo_RefID = extCompanyInfoID; ORM_CMN_UniversalContactDetail universalContactDetails = new ORM_CMN_UniversalContactDetail(); universalContactDetails.CMN_UniversalContactDetailID = contactUCDID; universalContactDetails.IsCompany = true; universalContactDetails.CompanyName_Line1 = Parameter.PharmacyName; universalContactDetails.Street_Name = Parameter.Street; universalContactDetails.Street_Name_Line2 = Parameter.Street2; universalContactDetails.Street_Number = Parameter.Number; universalContactDetails.Contact_Email = Parameter.MainEmail; universalContactDetails.ZIP = Parameter.ZIP; universalContactDetails.Town = Parameter.Town; universalContactDetails.Tenant_RefID = securityTicket.TenantID; ORM_CMN_BPT_BusinessParticipant extCompany = new ORM_CMN_BPT_BusinessParticipant(); extCompany.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); extCompany.Creation_Timestamp = DateTime.Now; extCompany.Tenant_RefID = securityTicket.TenantID; extCompany.DisplayName = Parameter.PharmacyName; extCompany.IsCompany = true; extCompany.IsNaturalPerson = false; extCompany.IsTenant = false; extCompany.IsDeleted = false; extCompany.IfCompany_CMN_COM_CompanyInfo_RefID = extCompanyInfoID; extCompany.Save(Connection, Transaction); extCompanyInfo.Save(Connection, Transaction); universalContactDetails.Save(Connection, Transaction); item.Save(Connection, Transaction); returnValue.Result = item.HEC_PharmacyID; #endregion } return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_PH_SP_1124 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 #region Pharmacy var pharmacy = ORM_HEC_Pharmacy.Query.Search(Connection, Transaction, new ORM_HEC_Pharmacy.Query { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, HEC_PharmacyID = Parameter.Pharmacy.PharmacyID }).SingleOrDefault(); if (pharmacy == null) { pharmacy = new ORM_HEC_Pharmacy(); pharmacy.Tenant_RefID = securityTicket.TenantID; } #endregion #region CompanyInfo var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo.Query { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, CMN_COM_CompanyInfoID = pharmacy.Ext_CompanyInfo_RefID }).SingleOrDefault(); if (companyInfo == null) { companyInfo = new ORM_CMN_COM_CompanyInfo(); companyInfo.Tenant_RefID = securityTicket.TenantID; pharmacy.Ext_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; } var contractUCD = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, new ORM_CMN_UniversalContactDetail.Query { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID }).SingleOrDefault(); if (contractUCD == null) { contractUCD = new ORM_CMN_UniversalContactDetail(); contractUCD.Tenant_RefID = securityTicket.TenantID; contractUCD.IsCompany = true; } contractUCD.CompanyName_Line1 = Parameter.Pharmacy.PharmacyName; contractUCD.First_Name = Parameter.Pharmacy.PharmacyName; contractUCD.Contact_Email = Parameter.Pharmacy.Email; contractUCD.Contact_Telephone = Parameter.Pharmacy.PhoneNumber; contractUCD.Contact_Fax = Parameter.Pharmacy.Fax; contractUCD.Street_Name = Parameter.Pharmacy.Street; contractUCD.Street_Number = Parameter.Pharmacy.StreetNumber; contractUCD.ZIP = Parameter.Pharmacy.ZipCode; contractUCD.Town = Parameter.Pharmacy.Town; contractUCD.Save(Connection, Transaction); companyInfo.Contact_UCD_RefID = contractUCD.CMN_UniversalContactDetailID; companyInfo.Save(Connection, Transaction); var ciBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID }).SingleOrDefault(); if (ciBusinessParticipant == null) { ciBusinessParticipant = new ORM_CMN_BPT_BusinessParticipant(); ciBusinessParticipant.Tenant_RefID = securityTicket.TenantID; ciBusinessParticipant.IsCompany = true; ciBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; } ciBusinessParticipant.Save(Connection, Transaction); var pharmacyType = EPharmacyType.Internal.Value(); if (Parameter.Pharmacy.IsExternalPharmacy) { pharmacyType = EPharmacyType.External.Value(); } var businessParticipantGroup = ORM_CMN_BPT_BusinessParticipant_Group.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_Group.Query { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, GlobalPropertyMatchingID = pharmacyType }).SingleOrDefault(); if (businessParticipantGroup == null) { businessParticipantGroup = new ORM_CMN_BPT_BusinessParticipant_Group(); businessParticipantGroup.Tenant_RefID = securityTicket.TenantID; businessParticipantGroup.GlobalPropertyMatchingID = pharmacyType; businessParticipantGroup.Save(Connection, Transaction); } var bpToBpGroup = ORM_CMN_BPT_BusinessParticipant_2_BusinessParticipantGroup.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_2_BusinessParticipantGroup.Query { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, CMN_BPT_BusinessParticipant_RefID = ciBusinessParticipant.CMN_BPT_BusinessParticipantID, CMN_BPT_BusinessParticipant_Group_RefID = businessParticipantGroup.CMN_BPT_BusinessParticipant_GroupID }).SingleOrDefault(); if (bpToBpGroup == null) { bpToBpGroup = new ORM_CMN_BPT_BusinessParticipant_2_BusinessParticipantGroup(); bpToBpGroup.Tenant_RefID = securityTicket.TenantID; bpToBpGroup.CMN_BPT_BusinessParticipant_Group_RefID = businessParticipantGroup.CMN_BPT_BusinessParticipant_GroupID; bpToBpGroup.CMN_BPT_BusinessParticipant_RefID = ciBusinessParticipant.CMN_BPT_BusinessParticipantID; bpToBpGroup.Save(Connection, Transaction); } #endregion #region ContactPersonInfo var contactInfo = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, CMN_BPT_BusinessParticipantID = pharmacy.ContactPerson_BusinessParticipant_RefID }).SingleOrDefault(); if (contactInfo == null) { contactInfo = new ORM_CMN_BPT_BusinessParticipant(); contactInfo.Tenant_RefID = securityTicket.TenantID; contactInfo.IsNaturalPerson = true; } var personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo.Query { Tenant_RefID = securityTicket.TenantID, IsDead = false, CMN_PER_PersonInfoID = contactInfo.IfNaturalPerson_CMN_PER_PersonInfo_RefID }).SingleOrDefault(); if (personInfo == null) { personInfo = new ORM_CMN_PER_PersonInfo(); personInfo.Tenant_RefID = securityTicket.TenantID; } var splitedName = Parameter.Pharmacy.ContactPersonName.Split(' '); var firstName = splitedName.Length > 1 ? string.Join(" ", splitedName.Take(splitedName.Length - 1)) : splitedName[0]; var lastName = splitedName.Length > 1 ? splitedName.Last() : ""; personInfo.FirstName = firstName; personInfo.LastName = lastName; personInfo.Save(Connection, Transaction); contactInfo.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; contactInfo.Save(Connection, Transaction); pharmacy.ContactPerson_BusinessParticipant_RefID = contactInfo.CMN_BPT_BusinessParticipantID; #endregion pharmacy.Save(Connection, Transaction); returnValue.Result = pharmacy.HEC_PharmacyID; return(returnValue); #endregion UserCode }