protected static FR_L6BL_GADfBSBR_1010 Execute(DbConnection Connection, DbTransaction Transaction, P_L6BL_GADfBSBR_1010 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L6BL_GADfBSBR_1010(); //Put your code here #region Retrieving bill header. ORM_BIL_BillHeader billHeader = new ORM_BIL_BillHeader(); FR_Base billHeaderLoad = billHeader.Load(Connection, Transaction, Parameter.BillHeaderID); if (billHeaderLoad.Status != FR_Status.Success) { Exception ex = new Exception(billHeaderLoad.ErrorMessage); return(new FR_L6BL_GADfBSBR_1010(ex)); } #endregion #region Retrieving universal contact details. ORM_CMN_UniversalContactDetail universalContactDetails = new ORM_CMN_UniversalContactDetail(); FR_Base universalContactDetailsLoad = universalContactDetails.Load(Connection, Transaction, billHeader.BillingAddress_UCD_RefID); if (universalContactDetailsLoad.Status != FR_Status.Success) { Exception ex = new Exception(universalContactDetailsLoad.ErrorMessage); return(new FR_L6BL_GADfBSBR_1010(ex)); } #endregion #region Retrieving business participants details. ORM_CMN_BPT_BusinessParticipant businessParticipant = new ORM_CMN_BPT_BusinessParticipant(); FR_Base businessParticipantLoad = businessParticipant.Load(Connection, Transaction, billHeader.BillRecipient_BuisnessParticipant_RefID); if (businessParticipantLoad.Status != FR_Status.Success) { Exception ex = new Exception(businessParticipantLoad.ErrorMessage); return(new FR_L6BL_GADfBSBR_1010(ex)); } #endregion #region Retrieving customer details. ORM_CMN_BPT_CTM_Customer customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query { Ext_BusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID }).FirstOrDefault(); if (customer == null) { Exception ex = new Exception("Retrieving ORM_CMN_BPT_CTM_Customer details failed."); return(new FR_L6BL_GADfBSBR_1010(ex)); } #endregion #region Retriving method of payments (taking first one) ORM_BIL_BillHeader_MethodOfPayment methodOfPayment = ORM_BIL_BillHeader_MethodOfPayment.Query.Search(Connection, Transaction, new ORM_BIL_BillHeader_MethodOfPayment.Query { BIL_BillHeader_RefID = billHeader.BIL_BillHeaderID }).FirstOrDefault(); #endregion #region Retrieving payment type ORM_ACC_PAY_Type type = null; if (methodOfPayment != null) { type = ORM_ACC_PAY_Type.Query.Search(Connection, Transaction, new ORM_ACC_PAY_Type.Query { ACC_PAY_TypeID = methodOfPayment.ACC_PAY_Type_RefID }).Single(); } #endregion #region Retrieving payment condition ORM_ACC_PAY_Condition condition = ORM_ACC_PAY_Condition.Query.Search(Connection, Transaction, new ORM_ACC_PAY_Condition.Query { ACC_PAY_ConditionID = billHeader.BillHeader_PaymentCondition_RefID }).FirstOrDefault(); #endregion #region Retrieving bill positions var allBillPositions = cls_Get_AllPositions_with_Articles_for_BillHeader.Invoke(Connection, Transaction, new P_L5BL_GAPwAfBH_1118 { BillHeaderID = billHeader.BIL_BillHeaderID }, securityTicket).Result; #endregion returnValue.Result = new L6BL_GADfBSBR_1010(); returnValue.Result.BillShipmentBasedReportHeaderDetails = new L6BL_GADfBSBR_1010a(); returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderComment = billHeader.BillComment; returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderDate = billHeader.DateOnBill; returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderNumber = billHeader.BillNumber; returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderTotalValue_BeforeTax = billHeader.TotalValue_BeforeTax; returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderTotalValue_IncludingTax = billHeader.TotalValue_IncludingTax; if (condition != null) { returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderPaymentDeadline = billHeader.DateOnBill.AddDays(condition.MaximumPaymentTreshold_InDays); } if (type != null) { returnValue.Result.BillShipmentBasedReportHeaderDetails.BillHeaderPaymentType = type.PaymentType_Name; } if (businessParticipant != null) { returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantDisplayName = businessParticipant.DisplayName; } if (customer != null) { returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantNumber = customer.InternalCustomerNumber; } if (universalContactDetails != null) { returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantStreetName = universalContactDetails.Street_Name; returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantStreetNumber = universalContactDetails.Street_Number; returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantCity = universalContactDetails.Town; returnValue.Result.BillShipmentBasedReportHeaderDetails.RecepientBusinessParticipantZipCode = universalContactDetails.ZIP; } #region bill positions returnValue.Result.BillPositions = null; List <L6BL_GADfBSBR_1010bp> unsortedBillPositionsTemp = new List <L6BL_GADfBSBR_1010bp>(); if (allBillPositions.ShipmentBillPositions != null) { var unsortedBillPositions = allBillPositions.ShipmentBillPositions.Where(x => x.BillPosition.CMN_BPT_CTM_OrganizationalUnitID == Guid.Empty).ToList(); foreach (L5BL_GBPwAfBH_1848 unsortedBillPosition in unsortedBillPositions) { L6BL_GADfBSBR_1010bp tempBillPosition = new L6BL_GADfBSBR_1010bp(); tempBillPosition.BIL_BillPositionID = unsortedBillPosition.BillPosition.BIL_BillPositionID; tempBillPosition.BillPosition_ValuePerUnit_BeforeTax = (double)unsortedBillPosition.BillPosition.PositionPricePerUnitValue_BeforeTax; tempBillPosition.BillPosition_ValuePerUnit_AfterTax = (double)unsortedBillPosition.BillPosition.PositionPricePerUnitValue_IncludingTax; tempBillPosition.ACC_TAX_TaxeID = unsortedBillPosition.Article.Taxes.First().ACC_TAX_TaxeID; tempBillPosition.TaxRate = unsortedBillPosition.Article.Taxes.First().TaxRate; tempBillPosition.TaxName_DictID = unsortedBillPosition.Article.Taxes.First().TaxName_DictID; tempBillPosition.HeaderID = unsortedBillPosition.BillPosition.LOG_SHP_Shipment_HeaderID; tempBillPosition.Header_Number = unsortedBillPosition.BillPosition.ShipmentHeader_Number; tempBillPosition.Creation_Timestamp = unsortedBillPosition.BillPosition.LOG_SHP_ShipmentHeader_Creation_Timestamp; tempBillPosition.IsShipmentPosition = true; tempBillPosition.Quantity = unsortedBillPosition.BillPosition.Quantity; unsortedBillPositionsTemp.Add(tempBillPosition); } } // now for customer orders return if (allBillPositions.OrderReturnBillPosition != null) { var unsortedCustomerOrderReturnPositions = allBillPositions.OrderReturnBillPosition.Where(x => x.OrderReturnBillPosition.CMN_BPT_CTM_OrganizationalUnitID == Guid.Empty).OrderBy(x => x.OrderReturnBillPosition.DateOfCustomerReturn).ToList(); foreach (L5OR_GCORPwAfBH_1051 unsortedBillPosition in unsortedCustomerOrderReturnPositions) { L6BL_GADfBSBR_1010bp tempBillPosition = new L6BL_GADfBSBR_1010bp(); tempBillPosition.BIL_BillPositionID = unsortedBillPosition.OrderReturnBillPosition.BIL_BillPositionID; tempBillPosition.BillPosition_ValuePerUnit_BeforeTax = (double)unsortedBillPosition.OrderReturnBillPosition.PositionPricePerUnitValue_BeforeTax; tempBillPosition.BillPosition_ValuePerUnit_AfterTax = (double)unsortedBillPosition.OrderReturnBillPosition.PositionPricePerUnitValue_IncludingTax; tempBillPosition.ACC_TAX_TaxeID = unsortedBillPosition.Article.Taxes.First().ACC_TAX_TaxeID; tempBillPosition.TaxRate = unsortedBillPosition.Article.Taxes.First().TaxRate; tempBillPosition.TaxName_DictID = unsortedBillPosition.Article.Taxes.First().TaxName_DictID; tempBillPosition.HeaderID = unsortedBillPosition.OrderReturnBillPosition.ORD_CUO_CustomerOrderReturn_HeaderID; tempBillPosition.Header_Number = unsortedBillPosition.OrderReturnBillPosition.CustomerOrderReturnNumber; tempBillPosition.Creation_Timestamp = unsortedBillPosition.OrderReturnBillPosition.Creation_Timestamp; tempBillPosition.IsShipmentPosition = false; tempBillPosition.Quantity = unsortedBillPosition.OrderReturnBillPosition.Quantity; unsortedBillPositionsTemp.Add(tempBillPosition); } } returnValue.Result.BillPositions = unsortedBillPositionsTemp.ToArray(); #region bill position organisation unit returnValue.Result.OrganizationalUnits = null; List <L6BL_GADfBSBR_1010bo> organizationalUnitsTemp = new List <L6BL_GADfBSBR_1010bo>(); if (allBillPositions.ShipmentBillPositions != null) { List <L5BL_GBPwAfBH_1848> sortedBillPositions = allBillPositions.ShipmentBillPositions.Where(x => x.BillPosition.CMN_BPT_CTM_OrganizationalUnitID != Guid.Empty).ToList(); foreach (L5BL_GBPwAfBH_1848 sortedBillPosition in sortedBillPositions) { L6BL_GADfBSBR_1010bo tempOrganizationalUnit = organizationalUnitsTemp.FirstOrDefault(organizationalUnitTemp => organizationalUnitTemp.CMN_BPT_CTM_OrganizationalUnitID == sortedBillPosition.BillPosition.CMN_BPT_CTM_OrganizationalUnitID); if (tempOrganizationalUnit == null) { tempOrganizationalUnit = new L6BL_GADfBSBR_1010bo(); tempOrganizationalUnit.BillPositions = new L6BL_GADfBSBR_1010bp[0]; tempOrganizationalUnit.CMN_BPT_CTM_OrganizationalUnitID = sortedBillPosition.BillPosition.CMN_BPT_CTM_OrganizationalUnitID; tempOrganizationalUnit.OrganizationalUnit_SimpleName = sortedBillPosition.BillPosition.OrganizationalUnit_SimpleName; tempOrganizationalUnit.OrganizationalUnit_Name = sortedBillPosition.BillPosition.OrganizationalUnit_Name_DictID; tempOrganizationalUnit.OrganizationalUnit_Description = sortedBillPosition.BillPosition.OrganizationalUnit_Name_DictID; tempOrganizationalUnit.InternalOrganizationalUnitNumber = sortedBillPosition.BillPosition.InternalOrganizationalUnitNumber; tempOrganizationalUnit.InternalOrganizationalUnitSimpleName = sortedBillPosition.BillPosition.InternalOrganizationalUnitSimpleName; tempOrganizationalUnit.ExternalOrganizationalUnitNumber = sortedBillPosition.BillPosition.ExternalOrganizationalUnitNumber; organizationalUnitsTemp.Add(tempOrganizationalUnit); } L6BL_GADfBSBR_1010bp tempBillPosition = new L6BL_GADfBSBR_1010bp(); tempBillPosition.BIL_BillPositionID = sortedBillPosition.BillPosition.BIL_BillPositionID; tempBillPosition.BillPosition_ValuePerUnit_BeforeTax = (double)sortedBillPosition.BillPosition.PositionPricePerUnitValue_BeforeTax; tempBillPosition.BillPosition_ValuePerUnit_AfterTax = (double)sortedBillPosition.BillPosition.PositionPricePerUnitValue_IncludingTax; tempBillPosition.ACC_TAX_TaxeID = sortedBillPosition.Article.Taxes.First().ACC_TAX_TaxeID; tempBillPosition.TaxRate = sortedBillPosition.Article.Taxes.First().TaxRate; tempBillPosition.TaxName_DictID = sortedBillPosition.Article.Taxes.First().TaxName_DictID; tempBillPosition.HeaderID = sortedBillPosition.BillPosition.LOG_SHP_Shipment_HeaderID; tempBillPosition.Header_Number = sortedBillPosition.BillPosition.ShipmentHeader_Number; tempBillPosition.Creation_Timestamp = sortedBillPosition.BillPosition.LOG_SHP_ShipmentHeader_Creation_Timestamp; tempBillPosition.IsShipmentPosition = true; tempBillPosition.Quantity = sortedBillPosition.BillPosition.Quantity; //hate this List <L6BL_GADfBSBR_1010bp> currentBillPositions = tempOrganizationalUnit.BillPositions.ToList(); currentBillPositions.Add(tempBillPosition); tempOrganizationalUnit.BillPositions = currentBillPositions.ToArray(); } } // now for organization unit in customer order return if (allBillPositions.OrderReturnBillPosition != null) { List <L5OR_GCORPwAfBH_1051> sortedBillPositionsforCustomerOrderReturn = allBillPositions.OrderReturnBillPosition.Where(x => x.OrderReturnBillPosition.CMN_BPT_CTM_OrganizationalUnitID != Guid.Empty).OrderBy(x => x.OrderReturnBillPosition.DateOfCustomerReturn).ToList(); foreach (L5OR_GCORPwAfBH_1051 sortedBillPosition in sortedBillPositionsforCustomerOrderReturn) { L6BL_GADfBSBR_1010bo tempOrganizationalUnit = organizationalUnitsTemp.FirstOrDefault(organizationalUnitTemp => organizationalUnitTemp.CMN_BPT_CTM_OrganizationalUnitID == sortedBillPosition.OrderReturnBillPosition.CMN_BPT_CTM_OrganizationalUnitID); if (tempOrganizationalUnit == null) { tempOrganizationalUnit = new L6BL_GADfBSBR_1010bo(); tempOrganizationalUnit.BillPositions = new L6BL_GADfBSBR_1010bp[0]; tempOrganizationalUnit.CMN_BPT_CTM_OrganizationalUnitID = sortedBillPosition.OrderReturnBillPosition.CMN_BPT_CTM_OrganizationalUnitID; tempOrganizationalUnit.OrganizationalUnit_SimpleName = sortedBillPosition.OrderReturnBillPosition.OrganizationalUnit_SimpleName; tempOrganizationalUnit.OrganizationalUnit_Name = sortedBillPosition.OrderReturnBillPosition.OrganizationalUnit_Name_DictID; tempOrganizationalUnit.OrganizationalUnit_Description = sortedBillPosition.OrderReturnBillPosition.OrganizationalUnit_Name_DictID; tempOrganizationalUnit.InternalOrganizationalUnitNumber = sortedBillPosition.OrderReturnBillPosition.InternalOrganizationalUnitNumber; tempOrganizationalUnit.InternalOrganizationalUnitSimpleName = sortedBillPosition.OrderReturnBillPosition.InternalOrganizationalUnitSimpleName; tempOrganizationalUnit.ExternalOrganizationalUnitNumber = sortedBillPosition.OrderReturnBillPosition.ExternalOrganizationalUnitNumber; organizationalUnitsTemp.Add(tempOrganizationalUnit); } L6BL_GADfBSBR_1010bp tempBillPosition = new L6BL_GADfBSBR_1010bp(); tempBillPosition.BIL_BillPositionID = sortedBillPosition.OrderReturnBillPosition.BIL_BillPositionID; tempBillPosition.BillPosition_ValuePerUnit_BeforeTax = (double)sortedBillPosition.OrderReturnBillPosition.PositionPricePerUnitValue_BeforeTax; tempBillPosition.BillPosition_ValuePerUnit_AfterTax = (double)sortedBillPosition.OrderReturnBillPosition.PositionPricePerUnitValue_IncludingTax; tempBillPosition.ACC_TAX_TaxeID = sortedBillPosition.Article.Taxes.First().ACC_TAX_TaxeID; tempBillPosition.TaxRate = sortedBillPosition.Article.Taxes.First().TaxRate; tempBillPosition.TaxName_DictID = sortedBillPosition.Article.Taxes.First().TaxName_DictID; tempBillPosition.HeaderID = sortedBillPosition.OrderReturnBillPosition.ORD_CUO_CustomerOrderReturn_HeaderID; tempBillPosition.Header_Number = sortedBillPosition.OrderReturnBillPosition.CustomerOrderReturnNumber; tempBillPosition.Creation_Timestamp = sortedBillPosition.OrderReturnBillPosition.Creation_Timestamp; tempBillPosition.IsShipmentPosition = false; tempBillPosition.Quantity = sortedBillPosition.OrderReturnBillPosition.Quantity; //hate this List <L6BL_GADfBSBR_1010bp> currentBillPositions = tempOrganizationalUnit.BillPositions.ToList(); currentBillPositions.Add(tempBillPosition); tempOrganizationalUnit.BillPositions = currentBillPositions.ToArray(); } } returnValue.Result.OrganizationalUnits = organizationalUnitsTemp.ToArray(); #endregion #endregion return(returnValue); #endregion UserCode }
protected static FR_L3CU_CCaMR_1308 Execute(DbConnection Connection, DbTransaction Transaction, P_L3CU_CCaMR_1308 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_L3CU_CCaMR_1308(); returnValue.Status = FR_Status.Error_Internal; returnValue.Result = new L3CU_CCaMR_1308(); #region Load or Create Customer Tenant Initial Table Structure var customerTenantStructure = cls_Create_Tenant_Initial_Table_Structure.Invoke( Connection, Transaction, new P_L3TE_CTITS_1108() { TenantITL = Parameter.Customer_TenantITL, BusinessParticipantITL = Parameter.Customer_BusinessParticipantITL, TenantUniversalContactDetailITL = Parameter.Customer_TenantUniversalContactDetailITL, CompanyInfoUniversalContactDetailITL = Parameter.Customer_CompanyInfoUniversalContactDetailITL, CompanyName = Parameter.Customer_CompanyName, ContactEmail = Parameter.Customer_ContactEmail }, securityTicket); #endregion if (customerTenantStructure.Status != FR_Status.Success) { return(returnValue); } #region Load or Create Customer var cust = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query() { Ext_BusinessParticipant_RefID = customerTenantStructure.Result.BusinessParticipantID, Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).SingleOrDefault(); if (cust == default(ORM_CMN_BPT_CTM_Customer)) { cust = new ORM_CMN_BPT_CTM_Customer(); cust.CMN_BPT_CTM_CustomerID = Guid.NewGuid(); cust.Ext_BusinessParticipant_RefID = customerTenantStructure.Result.BusinessParticipantID; cust.Tenant_RefID = securityTicket.TenantID; cust.Creation_Timestamp = DateTime.Now; cust.Save(Connection, Transaction); } #endregion #region Create booking account var fiscalYear = cls_Get_Current_FiscalYear.Invoke(Connection, Transaction, securityTicket).Result; var bookingAccountParam = new P_L3BA_CCAfBP_1655() { BusinessParticipantIDs = new Guid[1] { customerTenantStructure.Result.BusinessParticipantID }, FiscalYearID = fiscalYear.ACC_FiscalYearID }; var result = cls_Create_Customer_Account_for_BusinessParticipants.Invoke(Connection, Transaction, bookingAccountParam, securityTicket).Result; #endregion #region create defaultPerson for customer var businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); businessParticipantQuery.CMN_BPT_BusinessParticipantID = cust.Ext_BusinessParticipant_RefID; businessParticipantQuery.IsDeleted = false; var businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).Single(); if (businessParticipant.IsNaturalPerson) { if (businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID == null || businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID == Guid.Empty) { var personInfo = new ORM_CMN_PER_PersonInfo(); personInfo.CMN_PER_PersonInfoID = Guid.NewGuid(); personInfo.Tenant_RefID = securityTicket.TenantID; personInfo.IsDeleted = false; personInfo.FirstName = businessParticipant.DisplayName; personInfo.LastName = businessParticipant.DisplayName; personInfo.Creation_Timestamp = DateTime.Now; personInfo.Save(Connection, Transaction); businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; } } else if (businessParticipant.IsCompany) { Boolean needDefaultPerson = true; var associatedBPQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query(); associatedBPQuery.AssociatedBusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID; associatedBPQuery.Tenant_RefID = securityTicket.TenantID; associatedBPQuery.IsDeleted = false; List <ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant> associations = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associatedBPQuery); if (associations.Count > 0) { foreach (var assotiation in associations) { if (assotiation.BusinessParticipant_RefID != Guid.Empty) { ORM_CMN_BPT_BusinessParticipant.Query businessParticipantPersonQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); businessParticipantPersonQuery.CMN_BPT_BusinessParticipantID = assotiation.BusinessParticipant_RefID; businessParticipantPersonQuery.IsDeleted = false; businessParticipantPersonQuery.IsNaturalPerson = true; List <ORM_CMN_BPT_BusinessParticipant> businessParticipantsPerson = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantPersonQuery); foreach (var person in businessParticipantsPerson) { if (person.IfNaturalPerson_CMN_PER_PersonInfo_RefID == Guid.Empty) { ORM_CMN_PER_PersonInfo personInfoNew = new ORM_CMN_PER_PersonInfo(); personInfoNew.CMN_PER_PersonInfoID = Guid.NewGuid(); personInfoNew.Tenant_RefID = securityTicket.TenantID; personInfoNew.IsDeleted = false; personInfoNew.FirstName = person.DisplayName; personInfoNew.LastName = person.DisplayName; personInfoNew.Creation_Timestamp = DateTime.Now; personInfoNew.Save(Connection, Transaction); person.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfoNew.CMN_PER_PersonInfoID; } needDefaultPerson = false; break; } } } } if (needDefaultPerson) { #region create personalInfo ORM_CMN_PER_PersonInfo personInfo = new ORM_CMN_PER_PersonInfo(); personInfo.CMN_PER_PersonInfoID = Guid.NewGuid(); personInfo.Tenant_RefID = securityTicket.TenantID; personInfo.IsDeleted = false; personInfo.FirstName = businessParticipant.DisplayName; personInfo.LastName = businessParticipant.DisplayName; personInfo.Creation_Timestamp = DateTime.Now; personInfo.Save(Connection, Transaction); #endregion #region create new businessParticipiant ORM_CMN_BPT_BusinessParticipant bParticipant = new ORM_CMN_BPT_BusinessParticipant(); bParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); bParticipant.Tenant_RefID = securityTicket.TenantID; bParticipant.IsNaturalPerson = true; bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; bParticipant.DisplayName = businessParticipant.DisplayName; bParticipant.Creation_Timestamp = DateTime.Now; bParticipant.Save(Connection, Transaction); #endregion #region create associated businessParticipant table ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant associatedBP = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); associatedBP.CMN_BPT_BusinessParticipant_AssociatedBusinessParticipantID = Guid.NewGuid(); associatedBP.IsDeleted = false; associatedBP.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; associatedBP.AssociatedBusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID; associatedBP.Creation_Timestamp = DateTime.Now; associatedBP.Tenant_RefID = securityTicket.TenantID; associatedBP.Save(Connection, Transaction); #endregion } } #endregion returnValue.Result.Customer_TenantID = customerTenantStructure.Result.TenantID; returnValue.Result.Customer_BusinessParticipantID = customerTenantStructure.Result.BusinessParticipantID; returnValue.Result.Customer_CompanyInfo_UniversalContactDetailID = customerTenantStructure.Result.CompanyInfoUniversalContactDetailID; returnValue.Result.Customer_Tenant_UniversalContactDetailID = customerTenantStructure.Result.TenantUniversalContactDetailID; returnValue.Result.Customer_CustomerID = cust.CMN_BPT_CTM_CustomerID; returnValue.Result.Customer_CompanyInfoID = customerTenantStructure.Result.CompanyInfoID; returnValue.Result.IsCustomerOrderAutomaticallyApprovedOnReceipt = cust.IsCustomerOrderAutomaticallyApprovedOnReceipt; returnValue.Status = FR_Status.Success; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_CL5CO_SC_1724 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); //Put your code here Guid personInfoID = Guid.Empty; ORM_CMN_BPT_CTM_Customer.Query customerQuery = new ORM_CMN_BPT_CTM_Customer.Query(); customerQuery.CMN_BPT_CTM_CustomerID = Parameter.CustomerID; customerQuery.IsDeleted = false; ORM_CMN_BPT_CTM_Customer customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).Single(); ORM_CMN_BPT_BusinessParticipant.Query businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); businessParticipantQuery.CMN_BPT_BusinessParticipantID = customer.Ext_BusinessParticipant_RefID; businessParticipantQuery.IsDeleted = false; ORM_CMN_BPT_BusinessParticipant businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).Single(); if (businessParticipant.IsNaturalPerson) { personInfoID = businessParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; } else { ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query associationQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query(); associationQuery.AssociatedBusinessParticipant_RefID = businessParticipant.CMN_BPT_BusinessParticipantID; associationQuery.IsDeleted = false; List <ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant> associations = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, associationQuery); foreach (var association in associations) { ORM_CMN_BPT_BusinessParticipant.Query bpQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); bpQuery.CMN_BPT_BusinessParticipantID = association.BusinessParticipant_RefID; bpQuery.IsDeleted = false; bpQuery.IsNaturalPerson = true; ORM_CMN_BPT_BusinessParticipant bp = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bpQuery).First(); if (bp != null) { personInfoID = bp.IfNaturalPerson_CMN_PER_PersonInfo_RefID; break; } } } if (personInfoID != Guid.Empty) { if (Parameter.Correspondences.Any(x => x.IsDefaultCorrespondence) && !Parameter.Correspondences.Any(x => x.IsDeleted)) { var findDefaultCorrespondenceQuery = ORM_CMN_PER_PersonInfo_Correspondence.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo_Correspondence.Query { CMN_PER_PersonInfo_RefID = personInfoID, IsDefaultCorrespondence = true, IsDeleted = false, Tenant_RefID = customer.Tenant_RefID }); if (findDefaultCorrespondenceQuery != null && findDefaultCorrespondenceQuery.Any()) { foreach (var item in findDefaultCorrespondenceQuery) { item.IsDefaultCorrespondence = false; item.Save(Connection, Transaction); } } } foreach (var item in Parameter.Correspondences) { ORM_CMN_PER_PersonInfo_Correspondence.Query correspondenceQuery = new ORM_CMN_PER_PersonInfo_Correspondence.Query(); correspondenceQuery.IsDeleted = false; correspondenceQuery.CMN_PER_PersonInfo_CorrespondenceID = item.CorrespondenceID; List <ORM_CMN_PER_PersonInfo_Correspondence> correspondences = ORM_CMN_PER_PersonInfo_Correspondence.Query.Search(Connection, Transaction, correspondenceQuery); if (item.IsDeleted && correspondences.Count > 0) { correspondences.First().IsDeleted = true; correspondences.First().Save(Connection, Transaction); } else if (!item.IsDeleted) { if (correspondences.Count > 0) { correspondences.First().CorrespondenceText = item.CorrespondenceText; correspondences.First().IsDefaultCorrespondence = item.IsDefaultCorrespondence; correspondences.First().CorrespondenceType_RefID = item.CorrespondenceTypeRefId; correspondences.First().Save(Connection, Transaction); // save name in correspodencetype //var correspodenceTypeQuery = ORM_CMN_PER_PersonInfo_CorrespondenceType.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo_CorrespondenceType.Query{ // CMN_PER_PersonInfo_CorrespondenceTypeID = correspondences.First().CorrespondenceType_RefID, // Tenant_RefID = customer.Tenant_RefID //}).SingleOrDefault() //if (correspodenceTypeQuery != null) //{ // correspodenceTypeQuery.DisplayName = item.CorrespondenceName; // correspodenceTypeQuery.Save(Connection, Transaction); //} } else { ORM_CMN_PER_PersonInfo.Query personQuery = new ORM_CMN_PER_PersonInfo.Query(); personQuery.CMN_PER_PersonInfoID = personInfoID; personQuery.IsDeleted = false; ORM_CMN_PER_PersonInfo person = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personQuery).First(); ORM_CMN_PER_PersonInfo_Correspondence newCorrespondance = new ORM_CMN_PER_PersonInfo_Correspondence(); newCorrespondance.CorrespondenceText = item.CorrespondenceText; newCorrespondance.IsDefaultCorrespondence = item.IsDefaultCorrespondence; newCorrespondance.CorrespondenceType_RefID = item.CorrespondenceTypeRefId; newCorrespondance.IsDeleted = false; newCorrespondance.Creation_Timestamp = DateTime.Now; newCorrespondance.CMN_PER_PersonInfo_CorrespondenceID = Guid.NewGuid(); newCorrespondance.CMN_PER_PersonInfo_RefID = person.CMN_PER_PersonInfoID; newCorrespondance.Tenant_RefID = customer.Tenant_RefID; newCorrespondance.Save(Connection, Transaction); // We will need some of this code later //var correspodenceTypeQuery = ORM_CMN_PER_PersonInfo_CorrespondenceType.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo_CorrespondenceType.Query{ // CMN_PER_PersonInfo_CorrespondenceTypeID = newCorrespondance.CorrespondenceType_RefID, // Tenant_RefID = customer.Tenant_RefID //}).SingleOrDefault() //if (correspodenceTypeQuery != null) //{ // correspodenceTypeQuery.DisplayName = item.CorrespondenceName; // correspodenceTypeQuery.Save(Connection,Transaction); //} //else //{ // ORM_CMN_PER_PersonInfo_CorrespondenceType newCorrespodenceType = new ORM_CMN_PER_PersonInfo_CorrespondenceType(); // newCorrespodenceType.Tenant_RefID = customer.Tenant_RefID; // newCorrespodenceType.CMN_PER_PersonInfo_CorrespondenceTypeID = newCorrespondance.CorrespondenceType_RefID; // newCorrespodenceType.DisplayName = item.CorrespondenceName; //} } } } } return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5ACACU_SCC_1051 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); if (Parameter.IsDelete && (Parameter.CMN_BPT_CTM_CustomerID == Guid.Empty)) { return(returnValue); } ORM_CMN_BPT_CTM_Customer customer; if (Parameter.CMN_BPT_CTM_CustomerID != Guid.Empty) { var customerQ = new ORM_CMN_BPT_CTM_Customer.Query(); customerQ.Tenant_RefID = securityTicket.TenantID; customerQ.IsDeleted = false; customerQ.CMN_BPT_CTM_CustomerID = Parameter.CMN_BPT_CTM_CustomerID; customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQ).First(); customer.InternalCustomerNumber = Parameter.Number; customer.IsCustomerOrderAutomaticallyApprovedOnReceipt = Parameter.IsCustomerOrderAutomaticallyApprovedOnReceipt; } else { customer = new ORM_CMN_BPT_CTM_Customer(); customer.Tenant_RefID = securityTicket.TenantID; customer.CMN_BPT_CTM_CustomerID = Guid.NewGuid(); customer.InternalCustomerNumber = Parameter.Number; customer.IsCustomerOrderAutomaticallyApprovedOnReceipt = Parameter.IsCustomerOrderAutomaticallyApprovedOnReceipt; } ORM_CMN_BPT_CTM_AvailablePaymentType customer2PaymentType; var customer2PaymentTypeQ = new ORM_CMN_BPT_CTM_AvailablePaymentType.Query(); customer2PaymentTypeQ.Tenant_RefID = securityTicket.TenantID; customer2PaymentTypeQ.IsDeleted = false; customer2PaymentTypeQ.Customer_RefID = customer.CMN_BPT_CTM_CustomerID; customer2PaymentType = ORM_CMN_BPT_CTM_AvailablePaymentType.Query.Search(Connection, Transaction, customer2PaymentTypeQ).FirstOrDefault(); if (customer2PaymentType == null) { customer2PaymentType = new ORM_CMN_BPT_CTM_AvailablePaymentType(); customer2PaymentType.ACC_PAY_Type_RefID = Guid.NewGuid(); customer2PaymentType.Tenant_RefID = securityTicket.TenantID; customer2PaymentType.Customer_RefID = customer.CMN_BPT_CTM_CustomerID; } customer2PaymentType.ACC_PAY_Type_RefID = Parameter.PaymentTypeID; customer2PaymentType.Save(Connection, Transaction); #region payment condition ORM_CMN_BPT_CTM_AvailablePaymentCondition customer2PaymentCondition; var customer2PaymentConditionQ = new ORM_CMN_BPT_CTM_AvailablePaymentCondition.Query(); customer2PaymentConditionQ.Tenant_RefID = securityTicket.TenantID; customer2PaymentConditionQ.IsDeleted = false; customer2PaymentConditionQ.Customer_RefID = customer.CMN_BPT_CTM_CustomerID; customer2PaymentCondition = ORM_CMN_BPT_CTM_AvailablePaymentCondition.Query.Search(Connection, Transaction, customer2PaymentConditionQ).FirstOrDefault(); if (customer2PaymentCondition == null) { customer2PaymentCondition = new ORM_CMN_BPT_CTM_AvailablePaymentCondition(); customer2PaymentCondition.ACC_PAY_Condition_RefID = Guid.NewGuid(); customer2PaymentCondition.Tenant_RefID = securityTicket.TenantID; customer2PaymentCondition.Customer_RefID = customer.CMN_BPT_CTM_CustomerID; } customer2PaymentCondition.ACC_PAY_Condition_RefID = Parameter.PaymentConditionID; customer2PaymentCondition.Save(Connection, Transaction); #endregion ORM_CMN_BPT_BusinessParticipant bParticipant; if (customer.Ext_BusinessParticipant_RefID != Guid.Empty) { var bParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query(); bParticipantQ.Tenant_RefID = securityTicket.TenantID; bParticipantQ.IsDeleted = false; bParticipantQ.CMN_BPT_BusinessParticipantID = customer.Ext_BusinessParticipant_RefID; bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQ).First(); } else { bParticipant = new ORM_CMN_BPT_BusinessParticipant(); bParticipant.Tenant_RefID = securityTicket.TenantID; bParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); bParticipant.IsCompany = true; customer.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; } bParticipant.DisplayName = Parameter.FirmName; ORM_CMN_COM_CompanyInfo company; if (bParticipant.IfCompany_CMN_COM_CompanyInfo_RefID != Guid.Empty) { var companyQ = new ORM_CMN_COM_CompanyInfo.Query(); companyQ.Tenant_RefID = securityTicket.TenantID; companyQ.IsDeleted = false; companyQ.CMN_COM_CompanyInfoID = bParticipant.IfCompany_CMN_COM_CompanyInfo_RefID; company = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyQ).First(); } else { company = new ORM_CMN_COM_CompanyInfo(); company.Tenant_RefID = securityTicket.TenantID; company.CMN_COM_CompanyInfoID = Guid.NewGuid(); bParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = company.CMN_COM_CompanyInfoID; } ORM_CMN_UniversalContactDetail ucd; if (company.Contact_UCD_RefID != Guid.Empty) { var ucdQ = new ORM_CMN_UniversalContactDetail.Query(); ucdQ.Tenant_RefID = securityTicket.TenantID; ucdQ.IsDeleted = false; ucdQ.CMN_UniversalContactDetailID = company.Contact_UCD_RefID; ucd = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, ucdQ).First(); } else { ucd = new ORM_CMN_UniversalContactDetail(); ucd.Tenant_RefID = securityTicket.TenantID; ucd.CMN_UniversalContactDetailID = Guid.NewGuid(); ucd.IsCompany = true; company.Contact_UCD_RefID = ucd.CMN_UniversalContactDetailID; } ucd.CompanyName_Line1 = Parameter.FirmName; ucd.CompanyName_Line2 = Parameter.Additional; ucd.IsDeleted = Parameter.IsDelete; company.IsDeleted = Parameter.IsDelete; bParticipant.IsDeleted = Parameter.IsDelete; customer.IsDeleted = Parameter.IsDelete; ucd.Save(Connection, Transaction); company.Save(Connection, Transaction); bParticipant.Save(Connection, Transaction); customer.Save(Connection, Transaction); returnValue.Result = customer.CMN_BPT_CTM_CustomerID; 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_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5OP_SP_1602 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); P_L2LN_GALFTID_1530 langParam = new P_L2LN_GALFTID_1530(); langParam.Tenant_RefID = securityTicket.TenantID; var languages = cls_Get_All_Languages_ForTenantID.Invoke(Connection, Transaction, langParam, securityTicket).Result; P_L3MP_SPBI_1602 basePracticeParam = new P_L3MP_SPBI_1602(); basePracticeParam.HEC_MedicalPractiseID = Parameter.HEC_MedicalPractiseID; basePracticeParam.Contact_EmergencyPhoneNumber = Parameter.PhoneNumber; basePracticeParam.Contact_Website_URL = Parameter.HomepageURL; basePracticeParam.PracticeEmail = Parameter.ContactEmail; basePracticeParam.PracticeName = Parameter.DisplyName; basePracticeParam.Region_Name = Parameter.AddressRegion; basePracticeParam.Street_Name = Parameter.AddressStreetName; basePracticeParam.Street_Number = Parameter.AddressStreetNumber; basePracticeParam.Town = Parameter.AddressCity; basePracticeParam.ZIP = Parameter.AddressZipCode; var practiceID = cls_Save_Practice_BaseInfo.Invoke(Connection, Transaction, basePracticeParam, securityTicket).Result; var practicesQuery = new ORM_HEC_MedicalPractis.Query(); practicesQuery.HEC_MedicalPractiseID = practiceID; var practices = ORM_HEC_MedicalPractis.Query.Search(Connection, Transaction, practicesQuery).First(); var companyInfoQuery = new ORM_CMN_COM_CompanyInfo.Query(); companyInfoQuery.CMN_COM_CompanyInfoID = practices.Ext_CompanyInfo_RefID; var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfoQuery).First(); var bParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); bParticipantQuery.IfCompany_CMN_COM_CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; var bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQuery).First(); ORM_CMN_BPT_BusinessParticipant bpContctPerson; if (practices.ContactPerson_RefID != Guid.Empty) { var bpContctPersonQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); bpContctPersonQuery.CMN_BPT_BusinessParticipantID = practices.ContactPerson_RefID; bpContctPerson = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bpContctPersonQuery).First(); } else { bpContctPerson = new ORM_CMN_BPT_BusinessParticipant(); bpContctPerson.Tenant_RefID = securityTicket.TenantID; bpContctPerson.IsNaturalPerson = true; } bpContctPerson.DisplayName = Parameter.ContactPerson_Name; bpContctPerson.Save(Connection, Transaction); practices.ContactPerson_RefID = bpContctPerson.CMN_BPT_BusinessParticipantID; ORM_CMN_CAL_WeeklyOfficeHours_Template officeHours; ORM_CMN_CAL_WeeklyOfficeHours_Template consultingHours; if (practices.WeeklyOfficeHours_Template_RefID != Guid.Empty && practices.WeeklySurgeryHours_Template_RefID != Guid.Empty) { var officeHoursQuery = new ORM_CMN_CAL_WeeklyOfficeHours_Template.Query(); officeHoursQuery.CMN_CAL_WeeklyOfficeHours_TemplateID = practices.WeeklyOfficeHours_Template_RefID; officeHours = ORM_CMN_CAL_WeeklyOfficeHours_Template.Query.Search(Connection, Transaction, officeHoursQuery).First(); officeHoursQuery.CMN_CAL_WeeklyOfficeHours_TemplateID = practices.WeeklySurgeryHours_Template_RefID; consultingHours = ORM_CMN_CAL_WeeklyOfficeHours_Template.Query.Search(Connection, Transaction, officeHoursQuery).First(); } else { officeHours = new ORM_CMN_CAL_WeeklyOfficeHours_Template(); officeHours.CMN_CAL_WeeklyOfficeHours_TemplateID = Guid.NewGuid(); consultingHours = new ORM_CMN_CAL_WeeklyOfficeHours_Template(); consultingHours.CMN_CAL_WeeklyOfficeHours_TemplateID = Guid.NewGuid(); practices.WeeklyOfficeHours_Template_RefID = officeHours.CMN_CAL_WeeklyOfficeHours_TemplateID; practices.WeeklySurgeryHours_Template_RefID = consultingHours.CMN_CAL_WeeklyOfficeHours_TemplateID; } consultingHours.Tenant_RefID = securityTicket.TenantID; officeHours.Tenant_RefID = securityTicket.TenantID; consultingHours.FormattedOfficeHours = Parameter.Consultation_FormattedOfficeHours; officeHours.FormattedOfficeHours = Parameter.Working_FormattedOfficeHours; consultingHours.Save(Connection, Transaction); officeHours.Save(Connection, Transaction); ORM_CMN_COM_CompanyInfo_Type companyType; var companyTypeQuery = new ORM_CMN_COM_CompanyInfo_Type.Query(); companyTypeQuery.IsDeleted = false; companyTypeQuery.CMN_COM_CompanyInfo_TypeID = Parameter.PracticeType_RefID; companyType = ORM_CMN_COM_CompanyInfo_Type.Query.Search(Connection, Transaction, companyTypeQuery).FirstOrDefault(); if (companyType == null) { companyType = new ORM_CMN_COM_CompanyInfo_Type(); companyType.CMN_COM_CompanyInfo_TypeID = Parameter.PracticeType_RefID; companyType.CompanyType_Name = new Dict(); companyType.CompanyType_Name.DictionaryID = Guid.NewGuid(); if (languages != null) { foreach (var item in languages) { companyType.CompanyType_Name.AddEntry(item.CMN_LanguageID, STLD_PracticeType.typesItems.First(t => t.Value == Parameter.PracticeType_RefID).Text); } } } companyInfo.CompanyType_RefID = Parameter.PracticeType_RefID; ORM_HEC_PublicHealthcare_PhysitianAssociation pHealthcare; var pHealthcareQuery = new ORM_HEC_PublicHealthcare_PhysitianAssociation.Query(); pHealthcareQuery.HEC_PublicHealthcare_PhysitianAssociationID = Parameter.HealthAssociation_RefID; pHealthcare = ORM_HEC_PublicHealthcare_PhysitianAssociation.Query.Search(Connection, Transaction, pHealthcareQuery).FirstOrDefault(); if (pHealthcare == null) { pHealthcare = new ORM_HEC_PublicHealthcare_PhysitianAssociation(); pHealthcare.HEC_PublicHealthcare_PhysitianAssociationID = Parameter.HealthAssociation_RefID; pHealthcare.HealthAssociation_Name = STLD_MedicalAssociation.associationItems.First(t => t.Value == Parameter.HealthAssociation_RefID).Text; pHealthcare.Save(Connection, Transaction); } practices.AssociatedWith_PhysitianAssociation_RefID = Parameter.HealthAssociation_RefID; ORM_CMN_BPT_CTM_Customer customer; var customerQuery = new ORM_CMN_BPT_CTM_Customer.Query(); customerQuery.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; var customerRes = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery); if (customerRes.Count == 0) { customer = new ORM_CMN_BPT_CTM_Customer(); customer.CMN_BPT_CTM_CustomerID = Guid.NewGuid(); customer.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; } else { customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQuery).First(); } var affinityStatusQuery = new ORM_CMN_BPT_CTM_AffinityStatus.Query(); affinityStatusQuery.CMN_BPT_CTM_AffinityStatusID = Parameter.AffinityStatus_RefID; var affinityStatus = ORM_CMN_BPT_CTM_AffinityStatus.Query.Search(Connection, Transaction, affinityStatusQuery).FirstOrDefault(); if (affinityStatus == null) { affinityStatus = new ORM_CMN_BPT_CTM_AffinityStatus(); affinityStatus.CMN_BPT_CTM_AffinityStatusID = Parameter.AffinityStatus_RefID; affinityStatus.AffinityStatus_Name = new Dict(); affinityStatus.AffinityStatus_Name.DictionaryID = Guid.NewGuid(); if (languages != null) { foreach (var item in languages) { affinityStatus.AffinityStatus_Name.AddEntry(item.CMN_LanguageID, STLD_AffinityStatus.affinityItems.First(t => t.Value == Parameter.AffinityStatus_RefID).Text); } } affinityStatus.Save(Connection, Transaction); } customer.CustomerAffinityStatus_RefID = Parameter.AffinityStatus_RefID; customer.Tenant_RefID = securityTicket.TenantID; customer.Save(Connection, Transaction); ORM_CMN_COM_CompanyInfo_Address compAddress; ORM_CMN_UniversalContactDetail address; var compAddressQuery = new ORM_CMN_COM_CompanyInfo_Address.Query(); compAddressQuery.Tenant_RefID = securityTicket.TenantID; compAddressQuery.CompanyInfo_RefID = practices.Ext_CompanyInfo_RefID; var compAddressRes = ORM_CMN_COM_CompanyInfo_Address.Query.Search(Connection, Transaction, compAddressQuery); if (compAddressRes.Count > 0) { compAddress = compAddressRes.First(); var addressQuery = new ORM_CMN_UniversalContactDetail.Query(); addressQuery.CMN_UniversalContactDetailID = compAddress.Address_UCD_RefID; address = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, addressQuery).First(); } else { compAddress = new ORM_CMN_COM_CompanyInfo_Address(); compAddress.CMN_COM_CompanyInfo_AddressID = Guid.NewGuid(); compAddress.IsShipping = true; compAddress.CompanyInfo_RefID = companyInfo.CMN_COM_CompanyInfoID; address = new ORM_CMN_UniversalContactDetail(); address.CMN_UniversalContactDetailID = Guid.NewGuid(); compAddress.Address_UCD_RefID = address.CMN_UniversalContactDetailID; } address.Town = Parameter.ShippingAddressCity; address.Street_Number = Parameter.ShippingAddressStreetNumber; address.Street_Name = Parameter.ShippingAddressStreetName; address.ZIP = Parameter.ShippingAddressZipCode; address.Region_Name = Parameter.ShippingAddressRegion; address.Tenant_RefID = securityTicket.TenantID; address.Save(Connection, Transaction); compAddress.Tenant_RefID = securityTicket.TenantID; compAddress.Save(Connection, Transaction); ORM_CMN_BPT_BusinessParticipant contactPBP; if (practices.ContactPerson_RefID != Guid.Empty) { var contactPBPQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); contactPBPQuery.CMN_BPT_BusinessParticipantID = practices.ContactPerson_RefID; contactPBP = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, contactPBPQuery).First(); } else { contactPBP = new ORM_CMN_BPT_BusinessParticipant(); contactPBP.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); contactPBP.IsCompany = true; practices.ContactPerson_RefID = contactPBP.CMN_BPT_BusinessParticipantID; } contactPBP.DisplayName = Parameter.ContactPerson_Name; contactPBP.Tenant_RefID = securityTicket.TenantID; contactPBP.Save(Connection, Transaction); companyInfo.Save(Connection, Transaction); practices.Save(Connection, Transaction); returnValue.Result = practices.HEC_MedicalPractiseID; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5ACACU_SPC_1047 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); if (Parameter.IsDelete && (Parameter.CMN_BPT_CTM_CustomerID == Guid.Empty)) { return(returnValue); } ORM_CMN_BPT_CTM_Customer customer; if (Parameter.CMN_BPT_CTM_CustomerID != Guid.Empty) { var customerQ = new ORM_CMN_BPT_CTM_Customer.Query(); customerQ.Tenant_RefID = securityTicket.TenantID; customerQ.IsDeleted = false; customerQ.CMN_BPT_CTM_CustomerID = Parameter.CMN_BPT_CTM_CustomerID; customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, customerQ).First(); customer.IsCustomerOrderAutomaticallyApprovedOnReceipt = Parameter.IsCustomerOrderAutomaticallyApprovedOnReceipt; } else { customer = new ORM_CMN_BPT_CTM_Customer(); customer.Tenant_RefID = securityTicket.TenantID; customer.CMN_BPT_CTM_CustomerID = Guid.NewGuid(); customer.InternalCustomerNumber = Parameter.Number; customer.IsCustomerOrderAutomaticallyApprovedOnReceipt = Parameter.IsCustomerOrderAutomaticallyApprovedOnReceipt; } ORM_CMN_BPT_CTM_AvailablePaymentType customer2PaymentType; var customer2PaymentTypeQ = new ORM_CMN_BPT_CTM_AvailablePaymentType.Query(); customer2PaymentTypeQ.Tenant_RefID = securityTicket.TenantID; customer2PaymentTypeQ.IsDeleted = false; customer2PaymentTypeQ.Customer_RefID = customer.CMN_BPT_CTM_CustomerID; customer2PaymentType = ORM_CMN_BPT_CTM_AvailablePaymentType.Query.Search(Connection, Transaction, customer2PaymentTypeQ).FirstOrDefault(); if (customer2PaymentType == null) { customer2PaymentType = new ORM_CMN_BPT_CTM_AvailablePaymentType(); customer2PaymentType.ACC_PAY_Type_RefID = Guid.NewGuid(); customer2PaymentType.Tenant_RefID = securityTicket.TenantID; customer2PaymentType.Customer_RefID = customer.CMN_BPT_CTM_CustomerID; } customer2PaymentType.ACC_PAY_Type_RefID = Parameter.PaymentTypeID; customer2PaymentType.Save(Connection, Transaction); #region payment condition ORM_CMN_BPT_CTM_AvailablePaymentCondition customer2PaymentCondition; var customer2PaymentConditionQ = new ORM_CMN_BPT_CTM_AvailablePaymentCondition.Query(); customer2PaymentConditionQ.Tenant_RefID = securityTicket.TenantID; customer2PaymentConditionQ.IsDeleted = false; customer2PaymentConditionQ.Customer_RefID = customer.CMN_BPT_CTM_CustomerID; customer2PaymentCondition = ORM_CMN_BPT_CTM_AvailablePaymentCondition.Query.Search(Connection, Transaction, customer2PaymentConditionQ).FirstOrDefault(); if (customer2PaymentCondition == null) { customer2PaymentCondition = new ORM_CMN_BPT_CTM_AvailablePaymentCondition(); customer2PaymentCondition.ACC_PAY_Condition_RefID = Guid.NewGuid(); customer2PaymentCondition.Tenant_RefID = securityTicket.TenantID; customer2PaymentCondition.Customer_RefID = customer.CMN_BPT_CTM_CustomerID; } customer2PaymentCondition.ACC_PAY_Condition_RefID = Parameter.PaymentConditionID; customer2PaymentCondition.Save(Connection, Transaction); #endregion ORM_CMN_BPT_BusinessParticipant bParticipant; if (customer.Ext_BusinessParticipant_RefID != Guid.Empty) { var bParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query(); bParticipantQ.Tenant_RefID = securityTicket.TenantID; bParticipantQ.IsDeleted = false; bParticipantQ.CMN_BPT_BusinessParticipantID = customer.Ext_BusinessParticipant_RefID; bParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, bParticipantQ).First(); } else { bParticipant = new ORM_CMN_BPT_BusinessParticipant(); bParticipant.Tenant_RefID = securityTicket.TenantID; bParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid(); bParticipant.IsNaturalPerson = true; customer.Ext_BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; } bParticipant.DisplayName = Parameter.FirstName + " " + Parameter.LastName; ORM_CMN_PER_PersonInfo personInfo; if (bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID != Guid.Empty) { var personInfoQ = new ORM_CMN_PER_PersonInfo.Query(); personInfoQ.Tenant_RefID = securityTicket.TenantID; personInfoQ.IsDeleted = false; personInfoQ.CMN_PER_PersonInfoID = bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID; personInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, personInfoQ).First(); } else { personInfo = new ORM_CMN_PER_PersonInfo(); personInfo.Tenant_RefID = securityTicket.TenantID; personInfo.CMN_PER_PersonInfoID = Guid.NewGuid(); bParticipant.IfNaturalPerson_CMN_PER_PersonInfo_RefID = personInfo.CMN_PER_PersonInfoID; } #region connection with legal guardian //checking is there allready legal guardian associated with this business participant ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query LGCheckQuery = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query(); LGCheckQuery.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; LGCheckQuery.IsDeleted = false; Boolean oldLegalGuardianConnectionExist = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Exists(Connection, Transaction, LGCheckQuery); if (Parameter.IsRepresentedByLegalGuardian) { if (oldLegalGuardianConnectionExist) { ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant oldLegalGuardianConnection = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, LGCheckQuery).First(); ORM_CMN_BPT_BusinessParticipant.Query oldLegalGuardianQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); oldLegalGuardianQuery.CMN_BPT_BusinessParticipantID = oldLegalGuardianConnection.AssociatedBusinessParticipant_RefID; oldLegalGuardianQuery.IsDeleted = false; ORM_CMN_BPT_BusinessParticipant oldLegalGuardian = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, oldLegalGuardianQuery).First(); oldLegalGuardian.DisplayName = Parameter.LegalGuardianName; oldLegalGuardian.Save(Connection, Transaction); } else { // creating a new legal guardian ORM_CMN_BPT_BusinessParticipant newLegalGuardian = new ORM_CMN_BPT_BusinessParticipant(); ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant legalGuardianLink = new ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant(); newLegalGuardian.DisplayName = Parameter.LegalGuardianName; legalGuardianLink.AssociatedBusinessParticipant_RefID = newLegalGuardian.CMN_BPT_BusinessParticipantID; legalGuardianLink.BusinessParticipant_RefID = bParticipant.CMN_BPT_BusinessParticipantID; newLegalGuardian.Save(Connection, Transaction); legalGuardianLink.Save(Connection, Transaction); } } else { //delete old legal guardian if there is an old legal guardian if (oldLegalGuardianConnectionExist) { ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant oldLegalGuardianConnection = ORM_CMN_BPT_BusinessParticipant_AssociatedBusinessParticipant.Query.Search(Connection, Transaction, LGCheckQuery).First(); ORM_CMN_BPT_BusinessParticipant.Query oldLegalGuardianQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); oldLegalGuardianQuery.CMN_BPT_BusinessParticipantID = oldLegalGuardianConnection.AssociatedBusinessParticipant_RefID; oldLegalGuardianQuery.IsDeleted = false; //deleting old legal guardian from business participant table if (ORM_CMN_BPT_BusinessParticipant.Query.Exists(Connection, Transaction, oldLegalGuardianQuery)) { ORM_CMN_BPT_BusinessParticipant oldLegalGuardian = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, oldLegalGuardianQuery).First(); oldLegalGuardian.IsDeleted = true; oldLegalGuardian.Save(Connection, Transaction); } // deleting connenction beetwen customer and legal guardian oldLegalGuardianConnection.IsDeleted = true; oldLegalGuardianConnection.Save(Connection, Transaction); } } #endregion personInfo.FirstName = Parameter.FirstName; personInfo.LastName = Parameter.LastName; personInfo.BirthDate = Parameter.BirthDate; personInfo.IsRepresentedByLegalGuardian = Parameter.IsRepresentedByLegalGuardian; personInfo.IsDeleted = Parameter.IsDelete; bParticipant.IsDeleted = Parameter.IsDelete; customer.IsDeleted = Parameter.IsDelete; personInfo.Save(Connection, Transaction); bParticipant.Save(Connection, Transaction); customer.Save(Connection, Transaction); returnValue.Result = customer.CMN_BPT_CTM_CustomerID; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L6MB_CUMBE_2302 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); var statusUploaded = ORM_MRS_RUN_MeasurementRun_Status.Query.Search(Connection, Transaction, new ORM_MRS_RUN_MeasurementRun_Status.Query() { GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(MeasurementRunStatus.Uploaded), Tenant_RefID = securityTicket.TenantID, IsDeleted = false }).Single(); var run = new ORM_MRS_RUN_MeasurementRun() { Tenant_RefID = securityTicket.TenantID, MRS_RUN_MeasurementRunID = Guid.NewGuid(), DateFrom = DateTime.Now, DateThrough = DateTime.MaxValue, CurrentStatus_RefID = statusUploaded.MRS_RUN_MeasurementRun_StatusID }; returnValue.Result = run.MRS_RUN_MeasurementRunID; var account = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query() { Tenant_RefID = securityTicket.TenantID, USR_AccountID = securityTicket.AccountID }).Single(); var runHistory = new ORM_MRS_RUN_MeasurementRun_StatusHistory() { Tenant_RefID = securityTicket.TenantID, MRS_RUN_MeasurementRun_StatusHistoryID = Guid.NewGuid(), MeasurementRun_Status_RefID = statusUploaded.MRS_RUN_MeasurementRun_StatusID, TriggeredBy_BusinessParticipant_RefID = account.BusinessParticipant_RefID, MeasurementRun_RefID = run.MRS_RUN_MeasurementRunID, Comment = string.Empty }; run.Save(Connection, Transaction); runHistory.Save(Connection, Transaction); foreach (var row in Parameter.Positions) { #region reader var readerPersonInfo = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, PrimaryEmail = row.ReaderEmail }).SingleOrDefault(); if (readerPersonInfo == null) { readerPersonInfo = new ORM_CMN_PER_PersonInfo() { Tenant_RefID = securityTicket.TenantID, PrimaryEmail = row.ReaderEmail, CMN_PER_PersonInfoID = Guid.NewGuid() }; } readerPersonInfo.FirstName = row.ReaderFirstName; readerPersonInfo.LastName = row.ReaderLastName; readerPersonInfo.Save(Connection, Transaction); var readerBP = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, IsNaturalPerson = true, IfNaturalPerson_CMN_PER_PersonInfo_RefID = readerPersonInfo.CMN_PER_PersonInfoID }).SingleOrDefault(); if (readerBP == null) { readerBP = new ORM_CMN_BPT_BusinessParticipant() { CMN_BPT_BusinessParticipantID = Guid.NewGuid(), Tenant_RefID = securityTicket.TenantID, IsNaturalPerson = true, IfNaturalPerson_CMN_PER_PersonInfo_RefID = readerPersonInfo.CMN_PER_PersonInfoID, }; readerBP.Save(Connection, Transaction); } var bpCode = ORM_CMN_BPT_BusinessParticipant_AccessCode.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant_AccessCode.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, BusinessParticipant_RefID = readerBP.CMN_BPT_BusinessParticipantID, IsValid = true, IsDeviceAccessCode = true }).SingleOrDefault(); if (bpCode == null) { bpCode = new ORM_CMN_BPT_BusinessParticipant_AccessCode() { CMN_BPT_BusinessParticipant_AccessCodeID = Guid.NewGuid(), Tenant_RefID = securityTicket.TenantID, BusinessParticipant_RefID = readerBP.CMN_BPT_BusinessParticipantID, IsValid = true, IsDeviceAccessCode = true, ValidFrom = DateTime.Now, ValidThrough = DateTime.MaxValue, Code = StringUtils.CodeGen(8).ToLower() }; bpCode.Save(Connection, Transaction); } #endregion #region meter var meter = ORM_MRS_MPT_Meter.Query.Search(Connection, Transaction, new ORM_MRS_MPT_Meter.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, SerialNumber = row.MeterSerialNumber }).SingleOrDefault(); if (meter == null) { meter = new ORM_MRS_MPT_Meter() { MRS_MPT_MeterID = Guid.NewGuid(), SerialNumber = row.MeterSerialNumber, Tenant_RefID = securityTicket.TenantID, }; meter.Save(Connection, Transaction); } var meterBinding = ORM_MRS_MPT_MeasuringPoint_MeterBinding.Query.Search(Connection, Transaction, new ORM_MRS_MPT_MeasuringPoint_MeterBinding.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, Meter_RefID = meter.MRS_MPT_MeterID }).SingleOrDefault(); if (meterBinding == null) { meterBinding = new ORM_MRS_MPT_MeasuringPoint_MeterBinding() { Tenant_RefID = securityTicket.TenantID, ActiveFrom = DateTime.Now, Meter_RefID = meter.MRS_MPT_MeterID, MRS_MPT_MeasuringPoint_MeterBindingID = Guid.NewGuid() }; meterBinding.Save(Connection, Transaction); } var measurentPoint = ORM_MRS_MPT_MeasuringPoint.Query.Search(Connection, Transaction, new ORM_MRS_MPT_MeasuringPoint.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, MRS_MPT_MeasuringPointID = meterBinding.MeasuringPoint_RefID }).SingleOrDefault(); if (measurentPoint == null) { measurentPoint = new ORM_MRS_MPT_MeasuringPoint() { Tenant_RefID = securityTicket.TenantID, MRS_MPT_MeasuringPointID = Guid.NewGuid() }; meterBinding.MeasuringPoint_RefID = measurentPoint.MRS_MPT_MeasuringPointID; meterBinding.Save(Connection, Transaction); measurentPoint.Save(Connection, Transaction); } #endregion #region customer var customerOwnership = ORM_MRS_MPT_CustomerOwnership.Query.Search(Connection, Transaction, new ORM_MRS_MPT_CustomerOwnership.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, ContractNumber = row.ContractNumber }).SingleOrDefault(); if (customerOwnership == null) { var customerPersonInfo = new ORM_CMN_PER_PersonInfo() { Tenant_RefID = securityTicket.TenantID, FirstName = row.ContractOwnerFirstName, LastName = row.ContractOwnerLastName, CMN_PER_PersonInfoID = Guid.NewGuid() }; customerPersonInfo.Save(Connection, Transaction); var customerBP = new ORM_CMN_BPT_BusinessParticipant() { CMN_BPT_BusinessParticipantID = Guid.NewGuid(), Tenant_RefID = securityTicket.TenantID, IsNaturalPerson = true, IfNaturalPerson_CMN_PER_PersonInfo_RefID = customerPersonInfo.CMN_PER_PersonInfoID, }; customerBP.Save(Connection, Transaction); var customer = new ORM_CMN_BPT_CTM_Customer() { Tenant_RefID = securityTicket.TenantID, CMN_BPT_CTM_CustomerID = Guid.NewGuid(), Ext_BusinessParticipant_RefID = customerBP.CMN_BPT_BusinessParticipantID }; customer.Save(Connection, Transaction); customerOwnership = new ORM_MRS_MPT_CustomerOwnership() { Tenant_RefID = securityTicket.TenantID, MRS_MPT_CustomerOwnershipID = Guid.NewGuid(), ContractNumber = row.ContractNumber, ValidFrom = DateTime.Now, Customer_RefID = customer.CMN_BPT_CTM_CustomerID, MeasuringPoint_RefID = measurentPoint.MRS_MPT_MeasuringPointID }; customerOwnership.Save(Connection, Transaction); } else { var customer = ORM_CMN_BPT_CTM_Customer.Query.Search(Connection, Transaction, new ORM_CMN_BPT_CTM_Customer.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, CMN_BPT_CTM_CustomerID = customerOwnership.Customer_RefID }).Single(); var customerBP = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, CMN_BPT_BusinessParticipantID = customer.Ext_BusinessParticipant_RefID }).Single(); var customerPI = ORM_CMN_PER_PersonInfo.Query.Search(Connection, Transaction, new ORM_CMN_PER_PersonInfo.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, CMN_PER_PersonInfoID = customerBP.IfNaturalPerson_CMN_PER_PersonInfo_RefID }).Single(); customerPI.FirstName = row.ContractOwnerFirstName; customerPI.LastName = row.ContractOwnerLastName; customerPI.Save(Connection, Transaction); } customerOwnership.MeasuringPoint_RefID = measurentPoint.MRS_MPT_MeasuringPointID; customerOwnership.Save(Connection, Transaction); #region address var address = ORM_CMN_Address.Query.Search(Connection, Transaction, new ORM_CMN_Address.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, City_Name = row.City, Street_Name = row.AddressName, Street_Number = row.AddressNumber, City_PostalCode = row.ZipCode }).SingleOrDefault(); if (address == null) { address = new ORM_CMN_Address() { Tenant_RefID = securityTicket.TenantID, City_Name = row.City, Street_Name = row.AddressName, Street_Number = row.AddressNumber, City_PostalCode = row.ZipCode, CMN_AddressID = Guid.NewGuid() }; address.Save(Connection, Transaction); } measurentPoint.CurrentAddress_RefID = address.CMN_AddressID; measurentPoint.Save(Connection, Transaction); #endregion #endregion #region route var route = ORM_MRS_RUT_Route.Query.Search(Connection, Transaction, new ORM_MRS_RUT_Route.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, DisplayName = row.RouteName }).SingleOrDefault(); if (route == null) { route = new ORM_MRS_RUT_Route() { Tenant_RefID = securityTicket.TenantID, MRS_RUT_RouteID = Guid.NewGuid(), DisplayName = row.RouteName, //Default_RouteReaderAccount_RefID = readerBP.CMN_BPT_BusinessParticipantID }; route.Save(Connection, Transaction); } var routeMeasuringPoint = ORM_MRS_RUT_Route_MeasuringPoint.Query.Search(Connection, Transaction, new ORM_MRS_RUT_Route_MeasuringPoint.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, Route_RefID = route.MRS_RUT_RouteID, MeasuringPoint_RefID = measurentPoint.MRS_MPT_MeasuringPointID }).SingleOrDefault(); if (routeMeasuringPoint == null) { routeMeasuringPoint = new ORM_MRS_RUT_Route_MeasuringPoint() { Tenant_RefID = securityTicket.TenantID, MRS_RUT_Route_MeasuringPointID = Guid.NewGuid(), Route_RefID = route.MRS_RUT_RouteID, MeasuringPoint_RefID = measurentPoint.MRS_MPT_MeasuringPointID }; } routeMeasuringPoint.OrderSequence = row.SequenceInRoute; routeMeasuringPoint.Save(Connection, Transaction); #endregion #region measurement var measurement = new ORM_MRS_RUN_Measurement() { Tenant_RefID = securityTicket.TenantID, MRS_RUN_MeasurementID = Guid.NewGuid(), MeasurementRun_RefID = run.MRS_RUN_MeasurementRunID, MeasuringPoint_RefID = routeMeasuringPoint.MRS_RUT_Route_MeasuringPointID }; measurement.Save(Connection, Transaction); var run2route = ORM_MRS_RUN_MeasurementRun_Route.Query.Search(Connection, Transaction, new ORM_MRS_RUN_MeasurementRun_Route.Query() { Tenant_RefID = securityTicket.TenantID, IsDeleted = false, Route_RefID = route.MRS_RUT_RouteID, MeasurementRun_RefID = run.MRS_RUN_MeasurementRunID }).SingleOrDefault(); if (run2route == null) { run2route = new ORM_MRS_RUN_MeasurementRun_Route() { MRS_RUN_MeasurementRun_RouteID = Guid.NewGuid(), Tenant_RefID = securityTicket.TenantID, Route_RefID = route.MRS_RUT_RouteID, MeasurementRun_RefID = run.MRS_RUN_MeasurementRunID } } ; run2route.BoundTo_Account_RefID = readerBP.CMN_BPT_BusinessParticipantID; run2route.Save(Connection, Transaction); #endregion } return(returnValue); #endregion UserCode }
public static void Save_practices_to_DB(Practice_Model_from_xlsx Parameter, string connectionString, SessionSecurityTicket securityTicket) { DbConnection Connection = null; DbTransaction Transaction = null; bool cleanupConnection = Connection == null; bool cleanupTransaction = Transaction == null; if (cleanupConnection == true) { Connection = CSV2Core_MySQL.Support.DBSQLSupport.CreateConnection(connectionString); Connection.Open(); } if (cleanupTransaction == true) { Transaction = Connection.BeginTransaction(); } try { Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("de-DE"); var returnValue = new FR_Guid(); Guid companyInfoID = Guid.NewGuid(); Guid BusinessParticipantID = Guid.NewGuid(); Guid PracticeAddressID = Guid.NewGuid(); Guid practice_id = Guid.NewGuid(); if (!String.IsNullOrEmpty(Parameter.LoginEmail)) //uncomment this if you've created account // if(false) { string[] stringUser = Parameter.LoginEmail.Split('@'); string usernameStr = stringUser[0]; try { var practiceAccountInfo = ORM_USR_Account.Query.Search(Connection, Transaction, new ORM_USR_Account.Query() { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, AccountSignInEmailAddress = Parameter.LoginEmail, }).Single(); var accountGroupQuery = new ORM_USR_Account_FunctionLevelRights_Group.Query(); accountGroupQuery.Tenant_RefID = securityTicket.TenantID; accountGroupQuery.IsDeleted = false; accountGroupQuery.GlobalPropertyMatchingID = "mm.docconect.doc.app.group"; var accountGroup = ORM_USR_Account_FunctionLevelRights_Group.Query.Search(Connection, Transaction, accountGroupQuery).SingleOrDefault(); if (accountGroup == null) { accountGroup = new ORM_USR_Account_FunctionLevelRights_Group(); accountGroup.Tenant_RefID = securityTicket.TenantID; accountGroup.Label = "mm.docconect.doc.app.group"; accountGroup.GlobalPropertyMatchingID = "mm.docconect.doc.app.group"; accountGroup.Creation_Timestamp = DateTime.Now; accountGroup.USR_Account_FunctionLevelRights_GroupID = Guid.NewGuid(); accountGroup.Save(Connection, Transaction); } var functionLevelRightQ = new ORM_USR_Account_FunctionLevelRight.Query(); functionLevelRightQ.Tenant_RefID = securityTicket.TenantID; functionLevelRightQ.IsDeleted = false; functionLevelRightQ.GlobalPropertyMatchingID = Parameter.IsSurgeryPractice ? "mm.docconect.doc.app.op.practice" : "mm.docconect.doc.app.ac.practice"; var existingunctionLevelRight = ORM_USR_Account_FunctionLevelRight.Query.Search(Connection, Transaction, functionLevelRightQ).SingleOrDefault(); Guid tempFunctionLevelRightID = Guid.Empty; if (existingunctionLevelRight == null) { ORM_USR_Account_FunctionLevelRight functionLevelRight = new ORM_USR_Account_FunctionLevelRight(); functionLevelRight.USR_Account_FunctionLevelRightID = Guid.NewGuid(); functionLevelRight.FunctionLevelRights_Group_RefID = accountGroup.USR_Account_FunctionLevelRights_GroupID; functionLevelRight.Tenant_RefID = securityTicket.TenantID; functionLevelRight.Creation_Timestamp = DateTime.Now; functionLevelRight.RightName = Parameter.IsSurgeryPractice ? "mm.docconect.doc.app.op.practice" : "mm.docconect.doc.app.ac.practice"; functionLevelRight.GlobalPropertyMatchingID = Parameter.IsSurgeryPractice ? "mm.docconect.doc.app.op.practice" : "mm.docconect.doc.app.ac.practice"; functionLevelRight.Save(Connection, Transaction); tempFunctionLevelRightID = functionLevelRight.USR_Account_FunctionLevelRightID; } else { tempFunctionLevelRightID = existingunctionLevelRight.USR_Account_FunctionLevelRightID; } var accountToFunctionLevelRight = new ORM_USR_Account_2_FunctionLevelRight(); accountToFunctionLevelRight.Tenant_RefID = securityTicket.TenantID; accountToFunctionLevelRight.Creation_Timestamp = DateTime.Now; accountToFunctionLevelRight.AssignmentID = Guid.NewGuid(); accountToFunctionLevelRight.Account_RefID = practiceAccountInfo.USR_AccountID; accountToFunctionLevelRight.FunctionLevelRight_RefID = tempFunctionLevelRightID; // USR_Account_FunctionLevelRightID accountToFunctionLevelRight.Save(Connection, Transaction); var businessParticipantQ = new ORM_CMN_BPT_BusinessParticipant.Query(); businessParticipantQ.IsDeleted = false; businessParticipantQ.Tenant_RefID = securityTicket.TenantID; businessParticipantQ.CMN_BPT_BusinessParticipantID = practiceAccountInfo.BusinessParticipant_RefID; BusinessParticipantID = practiceAccountInfo.BusinessParticipant_RefID; var practiceinfoinBusinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQ).Single(); practiceinfoinBusinessParticipant.DisplayName = Parameter.PracticeName; practiceinfoinBusinessParticipant.IsCompany = true; practiceinfoinBusinessParticipant.Modification_Timestamp = DateTime.Now; practiceinfoinBusinessParticipant.Save(Connection, Transaction); companyInfoID = practiceinfoinBusinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID; var companyInfo = new ORM_CMN_COM_CompanyInfo.Query(); companyInfo.IsDeleted = false; companyInfo.Tenant_RefID = securityTicket.TenantID; companyInfo.CMN_COM_CompanyInfoID = companyInfoID; var companyInfoPractice = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfo).Single(); companyInfoPractice.CompanyInfo_EstablishmentNumber = Parameter.BSNR; companyInfoPractice.Save(Connection, Transaction); var companyInfoAddressPractice = new ORM_CMN_COM_CompanyInfo_Address(); companyInfoAddressPractice.CompanyInfo_RefID = companyInfoID; companyInfoAddressPractice.IsDefault = true; companyInfoAddressPractice.IsShipping = true; companyInfoAddressPractice.IsBilling = true; companyInfoAddressPractice.Tenant_RefID = securityTicket.TenantID; companyInfoAddressPractice.Address_UCD_RefID = Guid.NewGuid(); companyInfoAddressPractice.Address_Description = "Standard address for billing, shipping"; companyInfoAddressPractice.Save(Connection, Transaction); PracticeAddressID = companyInfoAddressPractice.Address_UCD_RefID; var universlContactPractice = new ORM_CMN_UniversalContactDetail(); universlContactPractice.IsDeleted = false; universlContactPractice.Tenant_RefID = securityTicket.TenantID; universlContactPractice.CMN_UniversalContactDetailID = PracticeAddressID; universlContactPractice.CompanyName_Line1 = Parameter.PracticeName; universlContactPractice.IsCompany = true; universlContactPractice.Street_Name = Parameter.Street; universlContactPractice.Street_Number = Parameter.No; universlContactPractice.ZIP = Parameter.Zip; universlContactPractice.Town = Parameter.City; universlContactPractice.Contact_Email = Parameter.MainEmail; universlContactPractice.Contact_Telephone = Parameter.MainPhone; universlContactPractice.Contact_Fax = Parameter.Fax; universlContactPractice.Creation_Timestamp = DateTime.Now; universlContactPractice.Modification_Timestamp = DateTime.Now; universlContactPractice.Save(Connection, Transaction); } catch (Exception ex) { throw new Exception("Exception occured durng data retrieval in method cls_Save_Practice", ex); //Log the error (uncomment dex variable name and add a line here to write a log. } } // else{ var companyInfoAddress2 = new ORM_CMN_COM_CompanyInfo_Address(); companyInfoAddress2.IsDeleted = false; companyInfoAddress2.Tenant_RefID = securityTicket.TenantID; companyInfoAddress2.CompanyInfo_RefID = companyInfoID; companyInfoAddress2.IsDefault = true; companyInfoAddress2.IsContact = true; companyInfoAddress2.Address_UCD_RefID = Guid.NewGuid(); companyInfoAddress2.Address_Description = "Standard contact person data"; companyInfoAddress2.Creation_Timestamp = DateTime.Now; companyInfoAddress2.Save(Connection, Transaction); string personInfo = Parameter.ContactPerson; string PersonFirstName = ""; string PersonLastName = ""; int i = personInfo.IndexOf(' '); if (i > 1) { PersonFirstName = personInfo.Substring(0, i); PersonLastName = personInfo.Substring(i + 1); } else { PersonFirstName = Parameter.ContactPerson; PersonLastName = " "; } var universlContactPractice2 = new ORM_CMN_UniversalContactDetail(); universlContactPractice2.CMN_UniversalContactDetailID = companyInfoAddress2.Address_UCD_RefID; universlContactPractice2.IsDeleted = false; universlContactPractice2.Tenant_RefID = securityTicket.TenantID; universlContactPractice2.IsCompany = false; universlContactPractice2.First_Name = PersonFirstName; universlContactPractice2.Last_Name = PersonLastName; universlContactPractice2.Contact_Email = Parameter.Email; universlContactPractice2.Contact_Telephone = Parameter.Phone; universlContactPractice2.Creation_Timestamp = DateTime.Now; universlContactPractice2.Modification_Timestamp = DateTime.Now; universlContactPractice2.Save(Connection, Transaction); var business2bankAccount = new ORM_CMN_BPT_BusinessParticipant_2_BankAccount(); business2bankAccount.IsDeleted = false; business2bankAccount.Tenant_RefID = securityTicket.TenantID; business2bankAccount.CMN_BPT_BusinessParticipant_RefID = BusinessParticipantID; business2bankAccount.ACC_BNK_BankAccount_RefID = Guid.NewGuid(); business2bankAccount.Creation_Timestamp = DateTime.Now; business2bankAccount.Save(Connection, Transaction); var bankAccountPractice = new ORM_ACC_BNK_BankAccount(); bankAccountPractice.IsDeleted = false; bankAccountPractice.Tenant_RefID = securityTicket.TenantID; bankAccountPractice.ACC_BNK_BankAccountID = business2bankAccount.ACC_BNK_BankAccount_RefID; bankAccountPractice.OwnerText = Parameter.AccountHolder; bankAccountPractice.IBAN = Parameter.IBAN; bankAccountPractice.Bank_RefID = Guid.NewGuid(); bankAccountPractice.Creation_Timestamp = DateTime.Now; bankAccountPractice.Save(Connection, Transaction); var bank = new ORM_ACC_BNK_Bank(); bank.IsDeleted = false; bank.Tenant_RefID = securityTicket.TenantID; bank.ACC_BNK_BankID = bankAccountPractice.Bank_RefID; bank.BICCode = Parameter.Bic; bank.BankName = Parameter.Bank; bank.Creation_Timestamp = DateTime.Now; bank.Save(Connection, Transaction); var customer = new ORM_CMN_BPT_CTM_Customer(); customer.IsDeleted = false; customer.Tenant_RefID = securityTicket.TenantID; customer.Ext_BusinessParticipant_RefID = BusinessParticipantID; customer.CMN_BPT_CTM_CustomerID = Guid.NewGuid(); customer.Creation_Timestamp = DateTime.Now; customer.Save(Connection, Transaction); var organizationalUnit = new ORM_CMN_BPT_CTM_OrganizationalUnit(); organizationalUnit.IsDeleted = false; organizationalUnit.Tenant_RefID = securityTicket.TenantID; organizationalUnit.Customer_RefID = customer.CMN_BPT_CTM_CustomerID; organizationalUnit.IsMedicalPractice = true; organizationalUnit.IfMedicalPractise_HEC_MedicalPractice_RefID = Guid.NewGuid(); organizationalUnit.Creation_Timestamp = DateTime.Now; organizationalUnit.Modification_Timestamp = DateTime.Now; organizationalUnit.Save(Connection, Transaction); var medicalPractice = new ORM_HEC_MedicalPractis(); medicalPractice.IsDeleted = false; medicalPractice.Tenant_RefID = securityTicket.TenantID; medicalPractice.HEC_MedicalPractiseID = organizationalUnit.IfMedicalPractise_HEC_MedicalPractice_RefID; medicalPractice.Creation_Timestamp = DateTime.Now; medicalPractice.Modification_Timestamp = DateTime.Now; medicalPractice.Save(Connection, Transaction); practice_id = medicalPractice.HEC_MedicalPractiseID; var medicalPRactice2Universal = new ORM_HEC_MedicalPractice_2_UniversalProperty(); medicalPRactice2Universal.IsDeleted = false; medicalPRactice2Universal.Tenant_RefID = securityTicket.TenantID; medicalPRactice2Universal.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID; medicalPRactice2Universal.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid(); medicalPRactice2Universal.Value_Boolean = Parameter.IsSurgeryPractice; medicalPRactice2Universal.Creation_Timestamp = DateTime.Now; medicalPRactice2Universal.Modification_Timestamp = DateTime.Now; medicalPRactice2Universal.Save(Connection, Transaction); var practiceUniversal = new ORM_HEC_MedicalPractice_UniversalProperty(); practiceUniversal.IsDeleted = false; practiceUniversal.Tenant_RefID = securityTicket.TenantID; practiceUniversal.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal.HEC_MedicalPractice_UniversalProperty_RefID; practiceUniversal.PropertyName = "Surgery Practice"; practiceUniversal.IsValue_Boolean = true; practiceUniversal.Creation_Timestamp = DateTime.Now; practiceUniversal.Modification_Timestamp = DateTime.Now; practiceUniversal.Save(Connection, Transaction); var medicalPRactice2Universal2 = new ORM_HEC_MedicalPractice_2_UniversalProperty(); medicalPRactice2Universal2.Tenant_RefID = securityTicket.TenantID; medicalPRactice2Universal2.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID; medicalPRactice2Universal2.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid(); medicalPRactice2Universal2.Value_Boolean = Parameter.IsOrderDrugs; medicalPRactice2Universal2.Creation_Timestamp = DateTime.Now; medicalPRactice2Universal2.Modification_Timestamp = DateTime.Now; medicalPRactice2Universal2.Save(Connection, Transaction); var practiceUniversal2 = new ORM_HEC_MedicalPractice_UniversalProperty(); practiceUniversal2.IsDeleted = false; practiceUniversal2.Tenant_RefID = securityTicket.TenantID; practiceUniversal2.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal2.HEC_MedicalPractice_UniversalProperty_RefID; practiceUniversal2.PropertyName = "Order Drugs"; practiceUniversal2.IsValue_Boolean = true; practiceUniversal2.Creation_Timestamp = DateTime.Now; practiceUniversal2.Modification_Timestamp = DateTime.Now; practiceUniversal2.Save(Connection, Transaction); // default shipping date offset var medicalPRactice2Universal3 = new ORM_HEC_MedicalPractice_2_UniversalProperty(); medicalPRactice2Universal3.Tenant_RefID = securityTicket.TenantID; medicalPRactice2Universal3.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID; medicalPRactice2Universal3.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid(); medicalPRactice2Universal3.Value_Number = double.Parse(Parameter.DefaultShippingDateOffset); medicalPRactice2Universal3.Creation_Timestamp = DateTime.Now; medicalPRactice2Universal3.Modification_Timestamp = DateTime.Now; medicalPRactice2Universal3.Save(Connection, Transaction); var practiceUniversal3 = new ORM_HEC_MedicalPractice_UniversalProperty(); practiceUniversal3.IsDeleted = false; practiceUniversal3.Tenant_RefID = securityTicket.TenantID; practiceUniversal3.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal3.HEC_MedicalPractice_UniversalProperty_RefID; practiceUniversal3.PropertyName = "Default Shipping Date Offset"; practiceUniversal3.IsValue_Number = true; practiceUniversal3.Creation_Timestamp = DateTime.Now; practiceUniversal3.Modification_Timestamp = DateTime.Now; practiceUniversal3.Save(Connection, Transaction); var medicalPRactice2Universal4 = new ORM_HEC_MedicalPractice_2_UniversalProperty(); medicalPRactice2Universal4.Tenant_RefID = securityTicket.TenantID; medicalPRactice2Universal4.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID; medicalPRactice2Universal4.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid(); medicalPRactice2Universal4.Value_Boolean = Parameter.IsOnlyLabelRequired; medicalPRactice2Universal4.Creation_Timestamp = DateTime.Now; medicalPRactice2Universal4.Modification_Timestamp = DateTime.Now; medicalPRactice2Universal4.Save(Connection, Transaction); var practiceUniversal4 = new ORM_HEC_MedicalPractice_UniversalProperty(); practiceUniversal4.IsDeleted = false; practiceUniversal4.Tenant_RefID = securityTicket.TenantID; practiceUniversal4.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal4.HEC_MedicalPractice_UniversalProperty_RefID; practiceUniversal4.PropertyName = "Only Label Required"; practiceUniversal4.IsValue_Boolean = true; practiceUniversal4.Creation_Timestamp = DateTime.Now; practiceUniversal4.Modification_Timestamp = DateTime.Now; practiceUniversal4.Save(Connection, Transaction); var medicalPRactice2Universal5 = new ORM_HEC_MedicalPractice_2_UniversalProperty(); medicalPRactice2Universal5.Tenant_RefID = securityTicket.TenantID; medicalPRactice2Universal5.HEC_MedicalPractice_RefID = medicalPractice.HEC_MedicalPractiseID; medicalPRactice2Universal5.HEC_MedicalPractice_UniversalProperty_RefID = Guid.NewGuid(); medicalPRactice2Universal5.Value_Boolean = Parameter.isWaiveServiceFee; medicalPRactice2Universal5.Creation_Timestamp = DateTime.Now; medicalPRactice2Universal5.Modification_Timestamp = DateTime.Now; medicalPRactice2Universal5.Save(Connection, Transaction); var practiceUniversal5 = new ORM_HEC_MedicalPractice_UniversalProperty(); practiceUniversal5.IsDeleted = false; practiceUniversal5.Tenant_RefID = securityTicket.TenantID; practiceUniversal5.HEC_MedicalPractice_UniversalPropertyID = medicalPRactice2Universal5.HEC_MedicalPractice_UniversalProperty_RefID; practiceUniversal5.PropertyName = "Waive Service Fee"; practiceUniversal5.IsValue_Boolean = true; practiceUniversal5.Creation_Timestamp = DateTime.Now; practiceUniversal5.Modification_Timestamp = DateTime.Now; practiceUniversal5.Save(Connection, Transaction); // } Practice_Doctors_Model DPModel = new Practice_Doctors_Model(); DPModel.account_status = "aktiv"; DPModel.id = practice_id.ToString(); DPModel.name = Parameter.PracticeName; DPModel.name_untouched = Parameter.PracticeName; DPModel.salutation = ""; DPModel.type = "Practice"; DPModel.autocomplete_name = Parameter.PracticeName; DPModel.address = Parameter.Street + " " + Parameter.No; DPModel.zip = Parameter.Zip; DPModel.city = Parameter.City; DPModel.bank_untouched = Parameter.Bank != null ? Parameter.Bank : ""; DPModel.bank = Parameter.Bank != null ? Parameter.Bank : ""; if (Parameter.Email != null) { DPModel.email = Parameter.MainEmail; } DPModel.phone = Parameter.MainPhone; if (Parameter.IBAN != null) { DPModel.iban = Parameter.IBAN; } if (Parameter.Bic != null) { DPModel.bic = Parameter.Bic; } DPModel.bsnr_lanr = Parameter.BSNR; DPModel.aditional_info = ""; DPModel.contract = 0; DPModel.tenantid = securityTicket.TenantID.ToString(); DPModel.role = Parameter.IsSurgeryPractice ? "op" : "ac"; List <Practice_Doctors_Model> DPModelL = new List <Practice_Doctors_Model>(); DPModelL.Add(DPModel); Add_Practice_Doctors_to_Elastic.Import_Practice_Data_to_ElasticDB(DPModelL, securityTicket.TenantID.ToString()); //Commit the transaction if (cleanupTransaction == true) { Transaction.Commit(); } //Close the connection if (cleanupConnection == true) { Connection.Close(); } } catch (Exception ex) { try { if (cleanupTransaction == true && Transaction != null) { Transaction.Rollback(); } } catch { } try { if (cleanupConnection == true && Connection != null) { Connection.Close(); } } catch { } throw ex; } }