Exemple #1
0
        protected static FR_L5PR_CFfC_1332 Execute(DbConnection Connection, DbTransaction Transaction, P_L5PR_CFfC_1332 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5PR_CFfC_1332();
            returnValue.Result = new L5PR_CFfC_1332();

            var tenantQuery = new ORM_CMN_Tenant.Query()
            {
                TenantITL    = Parameter.Pharmacy_TenantITL,
                Tenant_RefID = securityTicket.TenantID
            };

            var pharmacyTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();

            //Customer doesn't exist
            if (pharmacyTenant == default(ORM_CMN_Tenant))
            {
                pharmacyTenant = new ORM_CMN_Tenant();
                pharmacyTenant.CMN_TenantID       = Guid.NewGuid();
                pharmacyTenant.TenantITL          = Parameter.Pharmacy_TenantITL;
                pharmacyTenant.Tenant_RefID       = securityTicket.TenantID;
                pharmacyTenant.Creation_Timestamp = DateTime.Now;
                pharmacyTenant.Save(Connection, Transaction);
            }

            var bp = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
            {
                IsTenant = true,
                IfTenant_Tenant_RefID = pharmacyTenant.CMN_TenantID,
                Tenant_RefID          = securityTicket.TenantID,
                IsDeleted             = false
            }).SingleOrDefault();

            if (bp == default(ORM_CMN_BPT_BusinessParticipant))
            {
                bp = new ORM_CMN_BPT_BusinessParticipant();
                bp.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                bp.BusinessParticipantITL        = "";
                bp.DisplayName = Parameter.Pharmacy_CompanyName;
                bp.IsCompany   = true;
                bp.IfCompany_CMN_COM_CompanyInfo_RefID = Guid.NewGuid();
                bp.IsTenant = true;
                bp.IfTenant_Tenant_RefID = pharmacyTenant.CMN_TenantID;
                bp.Tenant_RefID          = securityTicket.TenantID;
                bp.Creation_Timestamp    = DateTime.Now;
                bp.Save(Connection, Transaction);
            }

            returnValue.Result.Pharmacy_TenantID = pharmacyTenant.CMN_TenantID;
            returnValue.Result.Pharmacy_BusinessParticipantID = bp.CMN_BPT_BusinessParticipantID;

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L5PL_GPWADfT_1720_Array Execute(DbConnection Connection, DbTransaction Transaction, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L5PL_GPWADfT_1720_Array();
            //Put your code here

            List <L5PL_GPWADfT_1720> finalList = new List <L5PL_GPWADfT_1720>();

            P_L2PL_GAPfToP_1723 paramPricelists = new P_L2PL_GAPfToP_1723();
            var pricelists = cls_Get_AllPricelists_For_TenantID_or_PricelistID.Invoke(Connection, paramPricelists, securityTicket).Result;

            Guid defaultPricelist = Guid.Empty;
            var  tenantQuery      = new ORM_CMN_Tenant.Query();
            tenantQuery.Tenant_RefID = securityTicket.TenantID;
            tenantQuery.CMN_TenantID = securityTicket.TenantID;
            var foundTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery);
            if (foundTenant != null)
            {
                defaultPricelist = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).Single().Customers_DefaultPricelist_RefID;
            }

            foreach (var pricelist in pricelists)
            {
                L5PL_GPWADfT_1720 temp = new L5PL_GPWADfT_1720();
                temp.PricelistDetails = pricelist;

                var releasesQuery = new ORM_CMN_SLS_Pricelist_Release.Query();
                releasesQuery.Tenant_RefID    = securityTicket.TenantID;
                releasesQuery.Pricelist_RefID = pricelist.CMN_SLS_PricelistID;
                var foundReleases = ORM_CMN_SLS_Pricelist_Release.Query.Search(Connection, Transaction, releasesQuery).ToList();

                P_L2PL_GARfToPID_1730 releasesParam = new P_L2PL_GARfToPID_1730();
                releasesParam.PricelistID = pricelist.CMN_SLS_PricelistID;
                L2PL_GARfToPID_1730[] releasesArray = cls_Get_AllReleases_for_TenantID_ID_or_PricelistID.Invoke(Connection, Transaction, releasesParam).Result;

                temp.Releases = new L2PL_GARfToPID_1730[releasesArray.Length];

                for (int i = 0; i < releasesArray.Length; i++)
                {
                    temp.Releases[i] = releasesArray[i];
                }

                temp.IsDefault = pricelist.CMN_SLS_PricelistID == defaultPricelist;

                finalList.Add(temp);
            }

            returnValue.Result = finalList.ToArray();

            return(returnValue);

            #endregion UserCode
        }
Exemple #3
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PL_SPWD_1432 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

            var savePricelistParam = new P_L2PL_SP_1407();
            savePricelistParam = Parameter.Save_CMN_SLS_Pricelist_Param;
            var savedPricelist = cls_Save_CMN_SLS_Pricelist.Invoke(Connection, Transaction, savePricelistParam, securityTicket).Result;

            var tenantQuery = new ORM_CMN_Tenant.Query();
            tenantQuery.Tenant_RefID = securityTicket.TenantID;
            tenantQuery.CMN_TenantID = securityTicket.TenantID;
            var foundTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).Single();

            if (foundTenant != null)
            {
                if (Parameter.IsDefault)
                {
                    if (savePricelistParam.CMN_SLS_PricelistID != Guid.Empty)
                    {
                        foundTenant.Customers_DefaultPricelist_RefID = savePricelistParam.CMN_SLS_PricelistID;
                    }
                    else
                    {
                        foundTenant.Customers_DefaultPricelist_RefID = savedPricelist;
                    }
                }
                else
                {
                    foundTenant.Customers_DefaultPricelist_RefID = Guid.Empty;
                }

                foundTenant.Save(Connection, Transaction);
            }


            returnValue.Result = savedPricelist;

            return(returnValue);

            #endregion UserCode
        }
Exemple #4
0
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PL_PDD_1242 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            //Leave UserCode region to enable user code saving
            #region UserCode
            var returnValue = new FR_Guid();
            //Put your code here

            P_L2PL_SP_1407 delPricelistParam = new P_L2PL_SP_1407();
            delPricelistParam = Parameter.Save_CMN_SLS_Pricelist_Param;

            var pricelistReleasesQuery = new ORM_CMN_SLS_Pricelist_Release.Query();
            pricelistReleasesQuery.Pricelist_RefID = delPricelistParam.CMN_SLS_PricelistID;
            pricelistReleasesQuery.Tenant_RefID    = securityTicket.TenantID;
            var foundReleases = ORM_CMN_SLS_Pricelist_Release.Query.Search(Connection, Transaction, pricelistReleasesQuery);

            //delete all found releases/versions for pricelistID
            foreach (var release in foundReleases)
            {
                release.IsDeleted = true;
                release.Save(Connection, Transaction);
            }

            //check if this is default pricelist
            var tenantQuery = new ORM_CMN_Tenant.Query();
            tenantQuery.CMN_TenantID = securityTicket.TenantID;
            tenantQuery.Tenant_RefID = securityTicket.TenantID;
            var foundTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();

            //if yes, then set default pricelist id to empty guid
            if (foundTenant != null && foundTenant.Customers_DefaultPricelist_RefID == delPricelistParam.CMN_SLS_PricelistID)
            {
                foundTenant.Customers_DefaultPricelist_RefID = Guid.Empty;
            }

            //finaly, delete pricelist
            var deletedPricelist = cls_Save_CMN_SLS_Pricelist.Invoke(Connection, Transaction, delPricelistParam, securityTicket).Result;
            returnValue.Result = deletedPricelist;

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3CA_CoUSfIC_1545 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_Guid();

            /*
             * @See if Supplier already exists in database
             * */
            ORM_CMN_BPT_Supplier supplier = new ORM_CMN_BPT_Supplier();

            var supplierQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
            supplierQuery.BusinessParticipantITL = Parameter.SupplierITL;
            supplierQuery.Tenant_RefID           = securityTicket.TenantID;
            supplierQuery.IsDeleted = false;

            var supplier_bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, supplierQuery).FirstOrDefault();

            #region if supplier does not exist

            if (supplier_bussinessParticipant == null)
            {
                /*
                 * @Make Supplier Data
                 * */

                var tenantQuery = new ORM_CMN_Tenant.Query()
                {
                    TenantITL    = Parameter.TenantITL,
                    Tenant_RefID = securityTicket.TenantID
                };

                var supplierTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();

                if (supplierTenant == default(ORM_CMN_Tenant))
                {
                    supplierTenant = new ORM_CMN_Tenant();
                    supplierTenant.CMN_TenantID       = Guid.NewGuid();
                    supplierTenant.TenantITL          = Parameter.TenantITL;
                    supplierTenant.Tenant_RefID       = securityTicket.TenantID;
                    supplierTenant.Creation_Timestamp = DateTime.Now;
                    supplierTenant.Save(Connection, Transaction);
                }

                supplier.CMN_BPT_SupplierID            = Guid.NewGuid();
                supplier.Ext_BusinessParticipant_RefID = Guid.NewGuid();//supplierBussinessParticipant.CMN_BPT_BusinessParticipantID
                supplier.Creation_Timestamp            = DateTime.Now;
                supplier.IsDeleted    = false;
                supplier.Tenant_RefID = securityTicket.TenantID;
                supplier.Save(Connection, Transaction);

                ORM_CMN_BPT_BusinessParticipant supplierBussinessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                supplierBussinessParticipant.CMN_BPT_BusinessParticipantID = supplier.Ext_BusinessParticipant_RefID;
                supplierBussinessParticipant.DisplayName            = Parameter.Supplier_Name;
                supplierBussinessParticipant.BusinessParticipantITL = Parameter.SupplierITL;
                supplierBussinessParticipant.Creation_Timestamp     = DateTime.Now;
                supplierBussinessParticipant.Tenant_RefID           = securityTicket.TenantID;
                supplierBussinessParticipant.IsCompany             = true;
                supplierBussinessParticipant.IsTenant              = true;
                supplierBussinessParticipant.IfTenant_Tenant_RefID = supplierTenant.CMN_TenantID;
                supplierBussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = Guid.NewGuid();//companyInfo.CMN_COM_CompanyInfoID
                supplierBussinessParticipant.Save(Connection, Transaction);

                ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.CMN_COM_CompanyInfoID = supplierBussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                companyInfo.Creation_Timestamp    = DateTime.Now;
                companyInfo.Tenant_RefID          = securityTicket.TenantID;
                companyInfo.Contact_UCD_RefID     = Guid.NewGuid();//universalContactDetail.CMN_UniversalContactDetailID
                companyInfo.Save(Connection, Transaction);

                ORM_CMN_UniversalContactDetail universalContactDetail = new ORM_CMN_UniversalContactDetail();
                universalContactDetail.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                universalContactDetail.IsCompany             = true;
                universalContactDetail.Country_639_1_ISOCode = Parameter.CountryISO;
                universalContactDetail.Street_Name           = Parameter.Supplier_Name;
                universalContactDetail.Street_Number         = Parameter.Street_Number;
                universalContactDetail.ZIP                = Parameter.ZIP;
                universalContactDetail.Town               = Parameter.Town;
                universalContactDetail.Region_Code        = Parameter.Region_Code;
                universalContactDetail.Tenant_RefID       = securityTicket.TenantID;
                universalContactDetail.Creation_Timestamp = DateTime.Now;
                universalContactDetail.Save(Connection, Transaction);
            }
            #endregion
            #region if supplier exists , check if its data is changed
            else
            {
                var tenantQuery = new ORM_CMN_Tenant.Query()
                {
                    TenantITL    = Parameter.TenantITL,
                    Tenant_RefID = securityTicket.TenantID,
                    IsDeleted    = false
                };

                ORM_CMN_Tenant supplierTenant;

                if (ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).Count > 1)
                {
                    supplierTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).First(); //QUICKFIX
                }
                else
                {
                    supplierTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();
                }

                if (supplierTenant == default(ORM_CMN_Tenant))
                {
                    supplierTenant = new ORM_CMN_Tenant();
                    supplierTenant.CMN_TenantID       = Guid.NewGuid();
                    supplierTenant.TenantITL          = Parameter.TenantITL;
                    supplierTenant.Tenant_RefID       = securityTicket.TenantID;
                    supplierTenant.Creation_Timestamp = DateTime.Now;
                    supplierTenant.Save(Connection, Transaction);

                    supplier_bussinessParticipant.IsTenant = true;
                    supplier_bussinessParticipant.IfTenant_Tenant_RefID = supplierTenant.CMN_TenantID;
                }

                supplier_bussinessParticipant.DisplayName = Parameter.Supplier_Name;
                supplier_bussinessParticipant.Save(Connection, Transaction);

                var query = new ORM_CMN_BPT_Supplier.Query();
                query.Ext_BusinessParticipant_RefID = supplier_bussinessParticipant.CMN_BPT_BusinessParticipantID;
                query.Tenant_RefID = securityTicket.TenantID;
                query.IsDeleted    = false;

                supplier = ORM_CMN_BPT_Supplier.Query.Search(Connection, Transaction, query).First();

                //edit universal contact details

                var companyInfoQuery = new ORM_CMN_COM_CompanyInfo.Query();
                companyInfoQuery.CMN_COM_CompanyInfoID = supplier_bussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                companyInfoQuery.Tenant_RefID          = securityTicket.TenantID;
                companyInfoQuery.IsDeleted             = false;

                var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfoQuery).First();

                var universalContactDetailQuery = new ORM_CMN_UniversalContactDetail.Query();
                universalContactDetailQuery.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                universalContactDetailQuery.Tenant_RefID = securityTicket.TenantID;
                universalContactDetailQuery.IsDeleted    = false;

                var universalContactDetail = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, universalContactDetailQuery).First();

                universalContactDetail.Country_639_1_ISOCode = Parameter.CountryISO;
                universalContactDetail.Street_Name           = Parameter.Supplier_Name;
                universalContactDetail.Street_Number         = Parameter.Street_Number;
                universalContactDetail.ZIP         = Parameter.ZIP;
                universalContactDetail.Town        = Parameter.Town;
                universalContactDetail.Region_Code = Parameter.Region_Code;
                universalContactDetail.Save(Connection, Transaction);
            }
            #endregion

            returnValue.Result = supplier.CMN_BPT_SupplierID;
            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L3TE_CTITS_1108 Execute(DbConnection Connection, DbTransaction Transaction, P_L3TE_CTITS_1108 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3TE_CTITS_1108();
            returnValue.Result = new L3TE_CTITS_1108();
            returnValue.Status = FR_Status.Error_Internal;

            #region Load or Create Tenant
            var tenantQuery = new ORM_CMN_Tenant.Query()
            {
                TenantITL    = Parameter.TenantITL,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            };

            var customerTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();

            if (customerTenant == default(ORM_CMN_Tenant))
            {
                customerTenant = new ORM_CMN_Tenant();
                customerTenant.CMN_TenantID                 = Guid.NewGuid();
                customerTenant.TenantITL                    = Parameter.TenantITL;
                customerTenant.Tenant_RefID                 = securityTicket.TenantID;
                customerTenant.Creation_Timestamp           = DateTime.Now;
                customerTenant.UniversalContactDetail_RefID = Guid.NewGuid();
                if (customerTenant.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }
            #endregion

            #region Load or Create BusinessParticipant
            var businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, new ORM_CMN_BPT_BusinessParticipant.Query()
            {
                IsTenant = true,
                IfTenant_Tenant_RefID = customerTenant.CMN_TenantID,
                Tenant_RefID          = securityTicket.TenantID,
                IsDeleted             = false
            }).SingleOrDefault();

            if (businessParticipant == default(ORM_CMN_BPT_BusinessParticipant))
            {
                businessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                businessParticipant.CMN_BPT_BusinessParticipantID = Guid.NewGuid();
                businessParticipant.BusinessParticipantITL        = Parameter.BusinessParticipantITL;
                businessParticipant.DisplayName = Parameter.CompanyName;
                businessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = Guid.NewGuid();
                businessParticipant.IfTenant_Tenant_RefID = customerTenant.CMN_TenantID;
                businessParticipant.IsCompany             = true;
                businessParticipant.IsTenant           = true;
                businessParticipant.Tenant_RefID       = securityTicket.TenantID;
                businessParticipant.Creation_Timestamp = DateTime.Now;
                if (businessParticipant.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }
            #endregion

            #region Load or Create CompanyInfo
            var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, new ORM_CMN_COM_CompanyInfo.Query()
            {
                CMN_COM_CompanyInfoID = businessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID,
                Tenant_RefID          = securityTicket.TenantID,
                IsDeleted             = false
            }).SingleOrDefault();

            if (companyInfo == default(ORM_CMN_COM_CompanyInfo))
            {
                companyInfo = new ORM_CMN_COM_CompanyInfo();
                companyInfo.CMN_COM_CompanyInfoID = businessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                companyInfo.Contact_UCD_RefID     = Guid.NewGuid();
                companyInfo.Tenant_RefID          = securityTicket.TenantID;
                companyInfo.Creation_Timestamp    = DateTime.Now;
                if (companyInfo.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }
            #endregion

            #region Load or Create UniversalContactDetails for Tenant and CompanyInfo
            var ucdTenant = ORM_CMN_UniversalContactDetail.Query.Search(
                Connection,
                Transaction,
                new ORM_CMN_UniversalContactDetail.Query()
            {
                CMN_UniversalContactDetailID = customerTenant.UniversalContactDetail_RefID,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            }).SingleOrDefault();

            if (ucdTenant == default(ORM_CMN_UniversalContactDetail))
            {
                ucdTenant = new ORM_CMN_UniversalContactDetail();
                ucdTenant.CMN_UniversalContactDetailID = customerTenant.UniversalContactDetail_RefID;
                ucdTenant.UniversalContactDetailsITL   = Parameter.TenantUniversalContactDetailITL;
                ucdTenant.IsCompany          = true;
                ucdTenant.CompanyName_Line1  = Parameter.CompanyName;
                ucdTenant.Contact_Email      = Parameter.ContactEmail;
                ucdTenant.Tenant_RefID       = securityTicket.TenantID;
                ucdTenant.Creation_Timestamp = DateTime.Now;
                if (ucdTenant.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }

            var ucdCompanyInfo = ORM_CMN_UniversalContactDetail.Query.Search(
                Connection,
                Transaction,
                new ORM_CMN_UniversalContactDetail.Query()
            {
                CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID,
                Tenant_RefID = securityTicket.TenantID,
                IsDeleted    = false
            }).SingleOrDefault();

            if (ucdCompanyInfo == default(ORM_CMN_UniversalContactDetail))
            {
                ucdCompanyInfo = new ORM_CMN_UniversalContactDetail();
                ucdCompanyInfo.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                ucdCompanyInfo.UniversalContactDetailsITL   = Parameter.CompanyInfoUniversalContactDetailITL;
                ucdCompanyInfo.IsCompany          = true;
                ucdCompanyInfo.CompanyName_Line1  = Parameter.CompanyName;
                ucdCompanyInfo.Contact_Email      = Parameter.ContactEmail;
                ucdCompanyInfo.Tenant_RefID       = securityTicket.TenantID;
                ucdCompanyInfo.Creation_Timestamp = DateTime.Now;
                if (ucdCompanyInfo.Save(Connection, Transaction).Status != FR_Status.Success)
                {
                    return(returnValue);
                }
            }
            #endregion

            returnValue.Result.TenantID = customerTenant.CMN_TenantID;
            returnValue.Result.BusinessParticipantID               = businessParticipant.CMN_BPT_BusinessParticipantID;
            returnValue.Result.TenantUniversalContactDetailID      = ucdTenant.CMN_UniversalContactDetailID;
            returnValue.Result.CompanyInfoUniversalContactDetailID = ucdCompanyInfo.CMN_UniversalContactDetailID;
            returnValue.Result.CompanyInfoID = companyInfo.CMN_COM_CompanyInfoID;
            returnValue.Status = FR_Status.Success;

            return(returnValue);

            #endregion UserCode
        }
        protected static FR_L3CCfTaIC_1526_Array Execute(DbConnection Connection, DbTransaction Transaction, P_L3CCfTaIC_1526 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null)
        {
            #region UserCode
            var returnValue = new FR_L3CCfTaIC_1526_Array();
            //Put your code here
            List <L3CCfTaIC_1526> ProductList = new List <L3CCfTaIC_1526>();
            returnValue.Result = ProductList.ToArray();
            var _service = CatalogServiceFactory.GetSubscriptionService();

            //make data to send to Architecture so that they will know which catalog to update
            var subscriptionRequest = new SubscriptionRequest();
            subscriptionRequest.CatalogCode = Parameter.CatalogCodeITL;
            Customer customer = new Customer();

            // for only Tenant specific cases add Business Participant ID
            if (Parameter.SubscribedBy_BusinessParticipant_RefID != Guid.Empty)
            {
                customer.BusinessParticipantITL = Parameter.SubscribedBy_BusinessParticipant_RefID.ToString();
            }
            else
            {
                customer.BusinessParticipantITL = securityTicket.TenantID.ToString();
            }
            customer.TenantITL = securityTicket.TenantID.ToString();
            customer.Name      = Parameter.ClientName;
            // customer.SourceRealm = BOp.Infrastructure.PropertyRepository.Instance.RealmID.ToString();

            subscriptionRequest.Customer = customer;

            /*
             * @see if catalog with the same ITL for that bussinessParticipant exists
             * */
            var subscribedCatalogQuery = new ORM_CMN_PRO_SubscribedCatalog.Query();
            subscribedCatalogQuery.Tenant_RefID   = securityTicket.TenantID;
            subscribedCatalogQuery.CatalogCodeITL = Parameter.CatalogCodeITL;
            if (Parameter.SubscribedBy_BusinessParticipant_RefID != Guid.Empty)
            {
                subscribedCatalogQuery.SubscribedBy_BusinessParticipant_RefID = Parameter.SubscribedBy_BusinessParticipant_RefID;
            }
            subscribedCatalogQuery.IsDeleted = false;

            var subscribedCatalog = ORM_CMN_PRO_SubscribedCatalog.Query.Search(Connection, Transaction, subscribedCatalogQuery).FirstOrDefault();

            #region Get VAT

            var defaultCountryISOCode = cls_Get_DefaultCountryISOCode_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result;

            var param = new P_L3TX_GTfCICaT_1359();
            param.CountryISOCode = "DE";



            var taxes = cls_Get_Taxes_for_CountryISOCode_and_TenantID.Invoke(Connection, Transaction, param, securityTicket).Result;
            //if there are no taxes for tenant
            Guid countryID = Guid.Empty;
            if (taxes.Length == 0)
            {
                var country = cls_Get_AllCountries_for_TenantID.Invoke(Connection, Transaction, securityTicket).Result.FirstOrDefault();

                if (country != null)
                {
                    countryID = country.CMN_CountryID;
                }
            }
            else
            {
                countryID = taxes.First().CMN_CountryID; // ti slucajni posmatracu ovog koda nemoj zameriti na ovakvom resenju.
            }

            #endregion

            #region save

            if (subscribedCatalog == null)
            {
                /*
                 * @save ORM_CMN_PRO_SubscribedCatalog
                 * */
                subscribedCatalog = new ORM_CMN_PRO_SubscribedCatalog();
                subscribedCatalog.CMN_PRO_SubscribedCatalogID = Guid.NewGuid();
                subscribedCatalog.CatalogCodeITL         = Parameter.CatalogCodeITL;
                subscribedCatalog.SubscribedCatalog_Name = Parameter.CatalogName;
                subscribedCatalog.SubscribedBy_BusinessParticipant_RefID = Parameter.SubscribedBy_BusinessParticipant_RefID;
                subscribedCatalog.Tenant_RefID = securityTicket.TenantID;
                subscribedCatalog.SubscribedCatalog_ValidFrom    = Parameter.ValidFrom_Date;
                subscribedCatalog.SubscribedCatalog_ValidThrough = Parameter.ValidTo_Date;
                subscribedCatalog.SubscribedCatalog_Description  = Parameter.CatalogDescription;
                subscribedCatalog.Creation_Timestamp             = DateTime.Now;
                subscribedCatalog.IsDeleted = false;
                subscribedCatalog.SubscribedCatalog_CurrentRevision = Parameter.CatalogVersion;
                subscribedCatalog.IsCatalogPublic = Parameter.IsCatalogPublic;

                // check if language with that ISO exists for Tenant (Lower, exmpl de)
                var languageQuery = new ORM_CMN_Language.Query();
                languageQuery.ISO_639_1    = Parameter.CatalogLanguage_ISO_639_1_codes.ToLower();
                languageQuery.Tenant_RefID = securityTicket.TenantID;
                languageQuery.IsDeleted    = false;

                var language = ORM_CMN_Language.Query.Search(Connection, Transaction, languageQuery).FirstOrDefault();

                // if language does not exist for that Tenant
                if (language == null)
                {
                    //check if language with that ISO exists for Tenant (Upper exmpl DE)
                    languageQuery              = new ORM_CMN_Language.Query();
                    languageQuery.ISO_639_1    = Parameter.CatalogLanguage_ISO_639_1_codes.ToUpper();
                    languageQuery.Tenant_RefID = securityTicket.TenantID;
                    languageQuery.IsDeleted    = false;

                    language = ORM_CMN_Language.Query.Search(Connection, Transaction, languageQuery).FirstOrDefault();

                    // if language does not exist for that Tenant
                    if (language == null)
                    {
                        ORM_CMN_Language newLanguage = new ORM_CMN_Language();
                        newLanguage.CMN_LanguageID     = Guid.NewGuid();
                        newLanguage.ISO_639_1          = Parameter.CatalogLanguage_ISO_639_1_codes;
                        newLanguage.Creation_Timestamp = DateTime.Now;
                        newLanguage.Tenant_RefID       = securityTicket.TenantID;
                        newLanguage.IsDeleted          = false;
                        newLanguage.Save(Connection, Transaction);

                        subscribedCatalog.SubscribedCatalog_Language_RefID = newLanguage.CMN_LanguageID;
                    }
                    else
                    {
                        subscribedCatalog.SubscribedCatalog_Language_RefID = language.CMN_LanguageID;
                    }
                }
                else
                {
                    subscribedCatalog.SubscribedCatalog_Language_RefID = language.CMN_LanguageID;
                }

                // check if currency with that ISO exists for Tenant

                var currencyQuery = new ORM_CMN_Currency.Query();
                currencyQuery.ISO4127      = Parameter.CatalogCurrency_ISO_4217;
                currencyQuery.Tenant_RefID = securityTicket.TenantID;
                currencyQuery.IsDeleted    = false;

                var currency = ORM_CMN_Currency.Query.Search(Connection, Transaction, currencyQuery).FirstOrDefault();

                if (currency == null)
                {
                    ORM_CMN_Currency newCurrency = new ORM_CMN_Currency();
                    newCurrency.CMN_CurrencyID     = Guid.NewGuid();
                    newCurrency.ISO4127            = Parameter.CatalogCurrency_ISO_4217;
                    newCurrency.Tenant_RefID       = securityTicket.TenantID;
                    newCurrency.Creation_Timestamp = DateTime.Now;
                    newCurrency.Save(Connection, Transaction);

                    subscribedCatalog.SubscribedCatalog_Currency_RefID = newCurrency.CMN_CurrencyID;
                }
                else
                {
                    subscribedCatalog.SubscribedCatalog_Currency_RefID = currency.CMN_CurrencyID;
                }

                #region product group

                /*
                 * @Search product group
                 * */
                ORM_CMN_PRO_ProductGroup productGroup = new ORM_CMN_PRO_ProductGroup();

                var productGroupQuery = new ORM_CMN_PRO_ProductGroup.Query();
                productGroupQuery.Tenant_RefID             = securityTicket.TenantID;
                productGroupQuery.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EProductGroup.Treatment);

                //if (Parameter.IsCatalogPublic == false)
                //{
                //    productGroupQuery.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EProductGroup.HauseList);
                //}
                //else
                //{
                //    productGroupQuery.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EProductGroup.ABDA);
                //}
                // for only Tenant specific cases add Business Participant ID
                if (Parameter.SubscribedBy_BusinessParticipant_RefID != Guid.Empty)
                {
                    productGroupQuery.GlobalPropertyMatchingID += Parameter.SubscribedBy_BusinessParticipant_RefID;
                }
                productGroupQuery.IsDeleted = false;

                productGroup = ORM_CMN_PRO_ProductGroup.Query.Search(Connection, Transaction, productGroupQuery).FirstOrDefault();

                if (productGroup == null)
                {
                    /*
                     * @Create product group for products if product group for that BP and Tenent does not exist
                     * */
                    productGroup = new ORM_CMN_PRO_ProductGroup();
                    productGroup.Tenant_RefID                  = securityTicket.TenantID;
                    productGroup.Creation_Timestamp            = DateTime.Now;
                    productGroup.CMN_PRO_ProductGroupID        = Guid.NewGuid();
                    productGroup.ProductGroup_Name             = new Dict(ORM_CMN_PRO_ProductGroup.TableName);
                    productGroupQuery.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EProductGroup.Treatment);
                    productGroup.ProductGroup_Name.AddEntry(language.CMN_LanguageID, "Treatment Group");

                    //if (Parameter.IsCatalogPublic == false)
                    //{
                    //    productGroup.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EProductGroup.HauseList);
                    //    productGroup.ProductGroup_Name.AddEntry(language.CMN_LanguageID, "HauseList Group");
                    //}
                    //else
                    //{
                    //    productGroup.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(EProductGroup.ABDA);
                    //    productGroup.ProductGroup_Name.AddEntry(language.CMN_LanguageID, "ABDA Group");
                    //}

                    // for only Tenant specific cases add Business Participant ID
                    if (Parameter.SubscribedBy_BusinessParticipant_RefID != Guid.Empty)
                    {
                        productGroup.GlobalPropertyMatchingID += Parameter.SubscribedBy_BusinessParticipant_RefID;
                        productGroup.ProductGroup_Name.AddEntry(language.CMN_LanguageID, "Treatment Group");
                    }
                    productGroup.Save(Connection, Transaction);
                }
                #endregion

                #region create priceList for Catalog

                /*
                 * @create pricelist_Release
                 * */
                ORM_CMN_SLS_Pricelist_Release pricelist_Release = new ORM_CMN_SLS_Pricelist_Release();
                pricelist_Release.CMN_SLS_Pricelist_ReleaseID = Guid.NewGuid();
                pricelist_Release.Release_Version             = "v1";
                if (Parameter.IsCatalogPublic == false)
                {
                    pricelist_Release.PricelistRelease_ValidFrom = Parameter.ValidFrom_Date;
                    pricelist_Release.PricelistRelease_ValidTo   = Parameter.ValidTo_Date;
                }
                else
                {
                    pricelist_Release.IsPricelistAlwaysActive = true;
                }
                pricelist_Release.Tenant_RefID       = securityTicket.TenantID;
                pricelist_Release.Creation_Timestamp = DateTime.Now;
                pricelist_Release.Pricelist_RefID    = Guid.NewGuid();//priceList.CMN_SLS_PricelistID
                pricelist_Release.Save(Connection, Transaction);

                /*
                 * @create pricelist
                 * */
                ORM_CMN_SLS_Pricelist priceList = new ORM_CMN_SLS_Pricelist();
                priceList.CMN_SLS_PricelistID = pricelist_Release.Pricelist_RefID;

                var DBLanguages = cls_Get_All_Languages.Invoke(Connection, Transaction, securityTicket).Result.ToList();

                Dict nameDict = new Dict("cmn_sls_pricelist");
                if (Parameter.IsCatalogPublic == false)
                {
                    for (int i = 0; i < DBLanguages.Count; i++)
                    {
                        nameDict.AddEntry(DBLanguages[i].CMN_LanguageID, Parameter.CatalogName + "_" + Parameter.ValidFrom_Date.ToShortDateString() + "_" + Parameter.ValidTo_Date.ToShortDateString());
                    }
                }
                else
                {
                    for (int i = 0; i < DBLanguages.Count; i++)
                    {
                        nameDict.AddEntry(DBLanguages[i].CMN_LanguageID, "ABDA_PriceList");
                    }
                }
                priceList.Pricelist_Name     = nameDict;
                priceList.Tenant_RefID       = securityTicket.TenantID;
                priceList.Creation_Timestamp = DateTime.Now;
                priceList.Save(Connection, Transaction);

                #endregion

                if (Parameter.IsCatalogPublic == false)
                {
                    #region create and save products in product group and give product its price , product amout and measure unit

                    /*
                     * @create and save products in product group
                     * */

                    bool isAlreadyInABDA = false;
                    foreach (var item in Parameter.Products)
                    {
                        ORM_CMN_PRO_Product product = new ORM_CMN_PRO_Product();

                        // only for Tenant specific cases add Business Participant ID (!Lucentis)
                        if (Parameter.SubscribedBy_BusinessParticipant_RefID == Guid.Empty)
                        {
                            var productQuery = new ORM_CMN_PRO_Product.Query();
                            productQuery.ProductITL   = item.ProductITL;
                            productQuery.Tenant_RefID = securityTicket.TenantID;
                            productQuery.IsDeleted    = false;
                            productQuery.IsProductAvailableForOrdering = true;

                            product = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, productQuery).FirstOrDefault();

                            //if it is not in ABDA
                            if (product == null)
                            {
                                product = new ORM_CMN_PRO_Product();
                                product.CMN_PRO_ProductID             = Guid.NewGuid();
                                product.Creation_Timestamp            = DateTime.Now;
                                product.Tenant_RefID                  = securityTicket.TenantID;
                                product.ProductITL                    = item.ProductITL;
                                product.Product_Name                  = item.Product_Name;
                                product.Product_Description           = item.Product_Description;
                                product.Product_Number                = item.Product_Number;
                                product.IsProduct_Article             = item.IsProduct_Article;
                                product.IsProductAvailableForOrdering = true;
                                product.PackageInfo_RefID             = Guid.NewGuid();//packageInfo.CMN_PRO_PAC_PackageInfoID

                                isAlreadyInABDA = false;
                            }
                            else
                            {
                                isAlreadyInABDA = true;
                            }
                        }
                        else
                        {
                            product.CMN_PRO_ProductID             = Guid.NewGuid();
                            product.Creation_Timestamp            = DateTime.Now;
                            product.Tenant_RefID                  = securityTicket.TenantID;
                            product.ProductITL                    = item.ProductITL;
                            product.Product_Name                  = item.Product_Name;
                            product.Product_Description           = item.Product_Description;
                            product.Product_Number                = item.Product_Number;
                            product.IsProduct_Article             = item.IsProduct_Article;
                            product.IsProductAvailableForOrdering = true;
                            product.PackageInfo_RefID             = Guid.NewGuid();//packageInfo.CMN_PRO_PAC_PackageInfoID

                            isAlreadyInABDA = false;
                        }

                        product.IfImportedFromExternalCatalog_CatalogSubscription_RefID = subscribedCatalog.CMN_PRO_SubscribedCatalogID;
                        product.Save(Connection, Transaction);

                        L3CCfTaIC_1526 pro = new L3CCfTaIC_1526();
                        pro.ProductID = product.CMN_PRO_ProductID;
                        if (product.IsProduct_Article)
                        {
                            pro.Dosage = item.Dosage;
                        }
                        pro.isEdit = false;
                        ProductList.Add(pro);

                        ORM_CMN_PRO_Product_2_ProductGroup product_2_productGroup = new ORM_CMN_PRO_Product_2_ProductGroup();
                        product_2_productGroup.CMN_PRO_Product_RefID      = product.CMN_PRO_ProductID;
                        product_2_productGroup.CMN_PRO_ProductGroup_RefID = productGroup.CMN_PRO_ProductGroupID;
                        product_2_productGroup.Tenant_RefID       = securityTicket.TenantID;
                        product_2_productGroup.Creation_Timestamp = DateTime.Now;
                        product_2_productGroup.Save(Connection, Transaction);

                        if (isAlreadyInABDA == false)
                        {
                            ORM_CMN_SLS_Price price = new ORM_CMN_SLS_Price();
                            price.CMN_SLS_PriceID        = Guid.NewGuid();
                            price.Tenant_RefID           = securityTicket.TenantID;
                            price.Creation_Timestamp     = DateTime.Now;
                            price.PricelistRelease_RefID = pricelist_Release.CMN_SLS_Pricelist_ReleaseID;
                            price.CMN_PRO_Product_RefID  = product.CMN_PRO_ProductID;
                            price.PriceAmount            = item.Price;
                            price.CMN_Currency_RefID     = subscribedCatalog.SubscribedCatalog_Currency_RefID;
                            price.Save(Connection, Transaction);

                            //add amount and Measure
                            ORM_CMN_PRO_PAC_PackageInfo packageInfo = new ORM_CMN_PRO_PAC_PackageInfo();
                            packageInfo.CMN_PRO_PAC_PackageInfoID = product.PackageInfo_RefID;
                            packageInfo.Tenant_RefID          = securityTicket.TenantID;
                            packageInfo.Creation_Timestamp    = DateTime.Now;
                            packageInfo.PackageContent_Amount = item.Amount;

                            //check if MeasureUnit exists for this Tenant
                            var unitsQuery = new ORM_CMN_Unit.Query();
                            unitsQuery.Tenant_RefID = securityTicket.TenantID;
                            unitsQuery.ISOCode      = item.MeasuredInUnit_ISO_um_ums;
                            unitsQuery.IsDeleted    = false;

                            var measuredInUnit = ORM_CMN_Unit.Query.Search(Connection, Transaction, unitsQuery).FirstOrDefault();
                            if (measuredInUnit == null)
                            {
                                ORM_CMN_Unit newMeasuredInUnit = new ORM_CMN_Unit();
                                newMeasuredInUnit.Tenant_RefID       = securityTicket.TenantID;
                                newMeasuredInUnit.Creation_Timestamp = DateTime.Now;
                                newMeasuredInUnit.ISOCode            = item.MeasuredInUnit_ISO_um_ums;
                                newMeasuredInUnit.CMN_UnitID         = Guid.NewGuid();
                                newMeasuredInUnit.Save(Connection, Transaction);

                                packageInfo.PackageContent_MeasuredInUnit_RefID = newMeasuredInUnit.CMN_UnitID;
                            }
                            else
                            {
                                packageInfo.PackageContent_MeasuredInUnit_RefID = measuredInUnit.CMN_UnitID;
                            }

                            packageInfo.Save(Connection, Transaction);

                            if (countryID != Guid.Empty)// if there is a country for this Tenant
                            {
                                #region Create Taxes

                                double productVAT = 0;
                                Double.TryParse(item.VAT, out productVAT);

                                var tax = taxes.Where(i => i.TaxRate == productVAT).SingleOrDefault();

                                if (tax == default(L3TX_GTfCICaT_1359))
                                {
                                    #region CreateTax

                                    var saveTaxParam = new P_L3TX_STX_1119();
                                    saveTaxParam.ACC_TAX_TaxeID = Guid.Empty;
                                    saveTaxParam.TaxName        = new Dict(ORM_ACC_TAX_Tax.TableName);
                                    saveTaxParam.TaxName.AddEntry(language.CMN_LanguageID, productVAT.ToString());
                                    saveTaxParam.TaxRate = productVAT;
                                    if (taxes.Length != 0)
                                    {
                                        saveTaxParam.EconomicRegion_RefID = taxes.First().CMN_EconomicRegionID;
                                        saveTaxParam.Country_RefID        = taxes.First().CMN_CountryID;
                                    }
                                    else
                                    {
                                        saveTaxParam.EconomicRegion_RefID = Guid.Empty;
                                        saveTaxParam.Country_RefID        = countryID;
                                    }
                                    var saveTaxResult = cls_Save_Tax.Invoke(Connection, Transaction, saveTaxParam, securityTicket).Result;

                                    #endregion

                                    #region Update Available taxes

                                    param = new P_L3TX_GTfCICaT_1359();
                                    param.CountryISOCode = "DE";

                                    taxes = cls_Get_Taxes_for_CountryISOCode_and_TenantID.Invoke(Connection, Transaction, param, securityTicket).Result;

                                    tax = taxes.Where(i => i.TaxRate == productVAT).SingleOrDefault();

                                    #endregion
                                }

                                var salesTax = new ORM_CMN_PRO_Product_SalesTaxAssignmnet();
                                salesTax.CMN_PRO_Product_SalesTaxAssignmnetID = Guid.NewGuid();
                                salesTax.Product_RefID            = product.CMN_PRO_ProductID;
                                salesTax.ApplicableSalesTax_RefID = tax.ACC_TAX_TaxeID;
                                salesTax.Creation_Timestamp       = DateTime.Now;
                                salesTax.Tenant_RefID             = securityTicket.TenantID;
                                salesTax.Save(Connection, Transaction);

                                #endregion
                            }
                        }
                    }
                    #endregion
                }

                /*
                 * @See if Supplier already exists in database
                 * */
                ORM_CMN_BPT_Supplier supplier = new ORM_CMN_BPT_Supplier();

                var supplierQuery = new ORM_CMN_BPT_BusinessParticipant.Query();
                supplierQuery.BusinessParticipantITL = Parameter.SupplierData.SupplierITL;
                supplierQuery.Tenant_RefID           = securityTicket.TenantID;
                supplierQuery.IsDeleted = false;

                var supplier_bussinessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, supplierQuery).FirstOrDefault();

                #region if supplier does not exist

                if (supplier_bussinessParticipant == null)
                {
                    /*
                     * @Make Supplier Data
                     * */

                    var tenantQuery = new ORM_CMN_Tenant.Query()
                    {
                        TenantITL    = Parameter.SupplierData.TenantITL,
                        Tenant_RefID = securityTicket.TenantID
                    };

                    var supplierTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();

                    if (supplierTenant == default(ORM_CMN_Tenant))
                    {
                        supplierTenant = new ORM_CMN_Tenant();
                        supplierTenant.CMN_TenantID       = Guid.NewGuid();
                        supplierTenant.TenantITL          = Parameter.SupplierData.TenantITL;
                        supplierTenant.Tenant_RefID       = securityTicket.TenantID;
                        supplierTenant.Creation_Timestamp = DateTime.Now;
                        supplierTenant.Save(Connection, Transaction);
                    }

                    supplier.CMN_BPT_SupplierID            = Guid.NewGuid();
                    supplier.Ext_BusinessParticipant_RefID = Guid.NewGuid();//supplierBussinessParticipant.CMN_BPT_BusinessParticipantID
                    supplier.Creation_Timestamp            = DateTime.Now;
                    supplier.IsDeleted    = false;
                    supplier.Tenant_RefID = securityTicket.TenantID;
                    supplier.Save(Connection, Transaction);

                    ORM_CMN_BPT_BusinessParticipant supplierBussinessParticipant = new ORM_CMN_BPT_BusinessParticipant();
                    supplierBussinessParticipant.CMN_BPT_BusinessParticipantID = supplier.Ext_BusinessParticipant_RefID;
                    supplierBussinessParticipant.DisplayName            = Parameter.SupplierData.Supplier_Name;
                    supplierBussinessParticipant.BusinessParticipantITL = Parameter.SupplierData.SupplierITL;
                    supplierBussinessParticipant.Creation_Timestamp     = DateTime.Now;
                    supplierBussinessParticipant.Tenant_RefID           = securityTicket.TenantID;
                    supplierBussinessParticipant.IsCompany             = true;
                    supplierBussinessParticipant.IsTenant              = true;
                    supplierBussinessParticipant.IfTenant_Tenant_RefID = supplierTenant.CMN_TenantID;
                    supplierBussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID = Guid.NewGuid();//companyInfo.CMN_COM_CompanyInfoID
                    supplierBussinessParticipant.Save(Connection, Transaction);

                    ORM_CMN_COM_CompanyInfo companyInfo = new ORM_CMN_COM_CompanyInfo();
                    companyInfo.CMN_COM_CompanyInfoID = supplierBussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                    companyInfo.Creation_Timestamp    = DateTime.Now;
                    companyInfo.Tenant_RefID          = securityTicket.TenantID;
                    companyInfo.Contact_UCD_RefID     = Guid.NewGuid();//universalContactDetail.CMN_UniversalContactDetailID
                    companyInfo.Save(Connection, Transaction);

                    ORM_CMN_UniversalContactDetail universalContactDetail = new ORM_CMN_UniversalContactDetail();
                    universalContactDetail.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                    universalContactDetail.IsCompany             = true;
                    universalContactDetail.Country_639_1_ISOCode = Parameter.SupplierData.CountryISO;
                    universalContactDetail.Street_Name           = Parameter.SupplierData.Supplier_Name;
                    universalContactDetail.Street_Number         = Parameter.SupplierData.Street_Number;
                    universalContactDetail.ZIP                = Parameter.SupplierData.ZIP;
                    universalContactDetail.Town               = Parameter.SupplierData.Town;
                    universalContactDetail.Region_Code        = Parameter.SupplierData.Region_Code;
                    universalContactDetail.Tenant_RefID       = securityTicket.TenantID;
                    universalContactDetail.Creation_Timestamp = DateTime.Now;
                    universalContactDetail.Save(Connection, Transaction);
                }
                #endregion
                #region if supplier exists , check if its data is changed
                else
                {
                    var tenantQuery = new ORM_CMN_Tenant.Query()
                    {
                        TenantITL    = Parameter.SupplierData.TenantITL,
                        Tenant_RefID = securityTicket.TenantID
                    };

                    var supplierTenant = ORM_CMN_Tenant.Query.Search(Connection, Transaction, tenantQuery).SingleOrDefault();

                    if (supplierTenant == default(ORM_CMN_Tenant))
                    {
                        supplierTenant = new ORM_CMN_Tenant();
                        supplierTenant.CMN_TenantID       = Guid.NewGuid();
                        supplierTenant.TenantITL          = Parameter.SupplierData.TenantITL;
                        supplierTenant.Tenant_RefID       = securityTicket.TenantID;
                        supplierTenant.Creation_Timestamp = DateTime.Now;
                        supplierTenant.Save(Connection, Transaction);

                        supplier_bussinessParticipant.IsTenant = true;
                        supplier_bussinessParticipant.IfTenant_Tenant_RefID = supplierTenant.CMN_TenantID;
                    }

                    supplier_bussinessParticipant.DisplayName = Parameter.SupplierData.Supplier_Name;
                    supplier_bussinessParticipant.Save(Connection, Transaction);

                    var query = new ORM_CMN_BPT_Supplier.Query();
                    query.Ext_BusinessParticipant_RefID = supplier_bussinessParticipant.CMN_BPT_BusinessParticipantID;
                    query.Tenant_RefID = securityTicket.TenantID;
                    query.IsDeleted    = false;

                    supplier = ORM_CMN_BPT_Supplier.Query.Search(Connection, Transaction, query).First();

                    //edit universal contact details

                    var companyInfoQuery = new ORM_CMN_COM_CompanyInfo.Query();
                    companyInfoQuery.CMN_COM_CompanyInfoID = supplier_bussinessParticipant.IfCompany_CMN_COM_CompanyInfo_RefID;
                    companyInfoQuery.Tenant_RefID          = securityTicket.TenantID;
                    companyInfoQuery.IsDeleted             = false;

                    var companyInfo = ORM_CMN_COM_CompanyInfo.Query.Search(Connection, Transaction, companyInfoQuery).First();

                    var universalContactDetailQuery = new ORM_CMN_UniversalContactDetail.Query();
                    universalContactDetailQuery.CMN_UniversalContactDetailID = companyInfo.Contact_UCD_RefID;
                    universalContactDetailQuery.Tenant_RefID = securityTicket.TenantID;
                    universalContactDetailQuery.IsDeleted    = false;

                    var universalContactDetail = ORM_CMN_UniversalContactDetail.Query.Search(Connection, Transaction, universalContactDetailQuery).First();

                    universalContactDetail.Country_639_1_ISOCode = Parameter.SupplierData.CountryISO;
                    universalContactDetail.Street_Name           = Parameter.SupplierData.Supplier_Name;
                    universalContactDetail.Street_Number         = Parameter.SupplierData.Street_Number;
                    universalContactDetail.ZIP         = Parameter.SupplierData.ZIP;
                    universalContactDetail.Town        = Parameter.SupplierData.Town;
                    universalContactDetail.Region_Code = Parameter.SupplierData.Region_Code;
                    universalContactDetail.Save(Connection, Transaction);
                }
                #endregion

                subscribedCatalog.SubscribedCatalog_PricelistRelease_RefID = pricelist_Release.CMN_SLS_Pricelist_ReleaseID;
                subscribedCatalog.PublishingSupplier_RefID = supplier.CMN_BPT_SupplierID;
                subscribedCatalog.Save(Connection, Transaction);

                /*
                 * @send Kika information which catalog has been subscribed to who
                 * */
                var result = _service.SubscribeToCatalog(subscriptionRequest);

                if (result.ResponseStatus != ResponseStatus.OK)
                {
                    throw new Exception("Catalog subscription failed!");
                }
            }
            #endregion

            returnValue.Result = ProductList.ToArray();
            return(returnValue);

            #endregion UserCode
        }