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

            var defaultLanguages = ORM_CMN_Language.Query.Search(Connection, Transaction, new ORM_CMN_Language.Query
            {
                IsDeleted    = false,
                Tenant_RefID = securityTicket.TenantID
            });
            List <P_L3AS_SAVP_0004> parameterVendorProduct  = new List <P_L3AS_SAVP_0004>();
            List <P_L3AS_SAVV_0040> parameterVendorVariants = new List <P_L3AS_SAVV_0040>();
            #region ImportCatalogProducts
            foreach (var productFromCatalog in Parameter.Products.Where(x => !string.IsNullOrEmpty(x.ProductITL)).ToList())
            {
                P_L5PR_IPfC_1648 importProductFromCatalogParameter = new P_L5PR_IPfC_1648();
                importProductFromCatalogParameter.Product             = new ProductsForImport();
                importProductFromCatalogParameter.Product.CatalogITL  = productFromCatalog.CatalogITL;
                importProductFromCatalogParameter.Product.Code        = productFromCatalog.Code;
                importProductFromCatalogParameter.Product.Custom      = productFromCatalog.Custom;
                importProductFromCatalogParameter.Product.Description = productFromCatalog.Description;
                importProductFromCatalogParameter.Product.Name        = productFromCatalog.Name;
                importProductFromCatalogParameter.Product.LongName    = productFromCatalog.LongName;
                importProductFromCatalogParameter.Product.ProductITL  = productFromCatalog.ProductITL;
                importProductFromCatalogParameter.Product.Variants    = new List <Variant>();
                foreach (var variant in productFromCatalog.Variants)
                {
                    importProductFromCatalogParameter.Product.Variants.Add(variant);
                }
                importProductFromCatalogParameter.Product.Customizations = new List <Customization>();

                if (productFromCatalog.Customizations != null)
                {
                    foreach (var customization in productFromCatalog.Customizations)
                    {
                        importProductFromCatalogParameter.Product.Customizations.Add(customization);
                    }
                }

                importProductFromCatalogParameter.Product.Vat = productFromCatalog.Vat;
                Guid productID = cls_Import_Product_from_Catalog.Invoke(Connection, Transaction, importProductFromCatalogParameter, securityTicket).Result;
                Parameter.Products.Where(x => x.ProductITL == productFromCatalog.ProductITL).ToList().ForEach(x => x.LocalProductID = productID);
            }
            #endregion import

            foreach (var parameterProduct in Parameter.Products)
            {
                ORM_CMN_PRO_Product productDB = new ORM_CMN_PRO_Product();

                #region loadProduct

                productDB.Load(Connection, Transaction, parameterProduct.LocalProductID);

                Guid originalProductId = productDB.CMN_PRO_ProductID;
                #endregion
                P_L3AS_GNoPiAfP_1512 parameterAssortmentProductExists = new P_L3AS_GNoPiAfP_1512();
                parameterAssortmentProductExists.AssortmentID = Parameter.AssortmentID;
                parameterAssortmentProductExists.ProductRefID = originalProductId;
                int numberOfProductsInAssortment = cls_Get_Number_of_Products_in_Assortment_for_ProductID.Invoke(Connection, Transaction, parameterAssortmentProductExists, securityTicket).Result.NumberOfProducts;

                if (numberOfProductsInAssortment == 0)
                {
                    #region SaveProductCopy
                    ORM_CMN_PRO_Product productCopyToCreate = new ORM_CMN_PRO_Product();

                    productCopyToCreate.CMN_PRO_ProductID                    = Guid.NewGuid();
                    productCopyToCreate.ProductITL                           = string.Empty;
                    productCopyToCreate.IsProduct_Article                    = true;
                    productCopyToCreate.IsProductAvailableForOrdering        = true;
                    productCopyToCreate.IsImportedFromExternalCatalog        = false;
                    productCopyToCreate.IsProductForInternalDistributionOnly = true;
                    productCopyToCreate.Product_Name                         = new Dict(ORM_CMN_PRO_Product.TableName);
                    productCopyToCreate.Product_Description                  = new Dict(ORM_CMN_PRO_Product.TableName);
                    productCopyToCreate.PackageInfo_RefID                    = Guid.NewGuid();
                    productCopyToCreate.Creation_Timestamp                   = DateTime.Now;
                    productCopyToCreate.Tenant_RefID                         = securityTicket.TenantID;
                    productCopyToCreate.IsDeleted = false;
                    productCopyToCreate.Save(Connection, Transaction);
                    productCopyToCreate.Product_Number = productDB.Product_Number;
                    foreach (var lang in defaultLanguages)
                    {
                        productCopyToCreate.Product_Name.UpdateEntry(lang.CMN_LanguageID, productDB.Product_Name.Contents.FirstOrDefault().Content);
                        productCopyToCreate.Product_Description.UpdateEntry(lang.CMN_LanguageID, productDB.Product_Description.Contents.FirstOrDefault().Content);
                    }
                    productCopyToCreate.ProductType_RefID      = Guid.Empty;
                    productCopyToCreate.ProductSuccessor_RefID = Guid.Empty;
                    productCopyToCreate.IsDeleted = false;
                    var productDocumentStructureRefID = Guid.NewGuid();
                    if (productDB.Product_DocumentationStructure_RefID != Guid.Empty)
                    {
                        productCopyToCreate.Product_DocumentationStructure_RefID = productDocumentStructureRefID;
                    }
                    productCopyToCreate.Save(Connection, Transaction);
                    #endregion

                    #region copyPicture
                    if (productDB.Product_DocumentationStructure_RefID != Guid.Empty)
                    {
                        var documentStructureHeaders = ORM_DOC_Structure_Header.Query.Search(Connection, Transaction, new ORM_DOC_Structure_Header.Query {
                            DOC_Structure_HeaderID = productDB.Product_DocumentationStructure_RefID
                        });
                        if (documentStructureHeaders != null && documentStructureHeaders.Count() > 0)
                        {
                            var documentStructureHeader = documentStructureHeaders.First();
                            ORM_DOC_Structure_Header docStructureHeaderToCreate = new ORM_DOC_Structure_Header();
                            docStructureHeaderToCreate.DOC_Structure_HeaderID = productDocumentStructureRefID;
                            docStructureHeaderToCreate.IsDeleted    = false;
                            docStructureHeaderToCreate.Label        = documentStructureHeader.Label;
                            docStructureHeaderToCreate.Tenant_RefID = securityTicket.TenantID;
                            docStructureHeaderToCreate.Save(Connection, Transaction);

                            var documentStructures = ORM_DOC_Structure.Query.Search(Connection, Transaction, new ORM_DOC_Structure.Query
                            {
                                Structure_Header_RefID = documentStructureHeader.DOC_Structure_HeaderID
                            });
                            var documentStructureID = Guid.NewGuid();
                            if (documentStructures != null && documentStructures.Count() > 0)
                            {
                                var documentStructure = documentStructures.First();
                                ORM_DOC_Structure structureToCreate = new ORM_DOC_Structure();
                                structureToCreate.Label                   = "Product picture";
                                structureToCreate.DOC_StructureID         = documentStructureID;
                                structureToCreate.Structure_Header_RefID  = docStructureHeaderToCreate.DOC_Structure_HeaderID;
                                structureToCreate.CreatedBy_Account_RefID = securityTicket.AccountID;
                                structureToCreate.Tenant_RefID            = securityTicket.TenantID;
                                structureToCreate.Save(Connection, Transaction);

                                var document2DocumentStructures = ORM_DOC_Document_2_Structure.Query.Search(Connection, Transaction, new ORM_DOC_Document_2_Structure.Query
                                {
                                    Structure_RefID = documentStructure.DOC_StructureID
                                });

                                if (document2DocumentStructures != null && document2DocumentStructures.Count() > 0)
                                {
                                    var document2DocumentStructure = document2DocumentStructures.First();

                                    var documentService = InfrastructureFactory.CreateDocumentService();
                                    var webClient       = new WebClient();
                                    var imageBytes      = webClient.DownloadData(documentService.GenerateDownloadLink(document2DocumentStructure.Document_RefID));

                                    var documentID = documentService.UploadDocument(imageBytes, productCopyToCreate.Product_Number, securityTicket.SessionTicket, null, null);
                                    ORM_DOC_Document documentToCreate = new ORM_DOC_Document();
                                    documentToCreate.DOC_DocumentID = documentID;
                                    documentToCreate.Tenant_RefID   = securityTicket.TenantID;
                                    documentToCreate.Save(Connection, Transaction);


                                    ORM_DOC_Document_2_Structure documentStructureToSave = new ORM_DOC_Document_2_Structure();
                                    documentStructureToSave.Document_RefID        = documentToCreate.DOC_DocumentID;
                                    documentStructureToSave.Structure_RefID       = structureToCreate.DOC_StructureID;
                                    documentStructureToSave.StructureHeader_RefID = docStructureHeaderToCreate.DOC_Structure_HeaderID;
                                    documentStructureToSave.Tenant_RefID          = securityTicket.TenantID;
                                    documentStructureToSave.Save(Connection, Transaction);
                                }
                            }
                        }
                    }

                    #endregion



                    var dimensionsDb = ORM_CMN_PRO_Dimension.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Dimension.Query
                    {
                        IsDeleted     = false,
                        Tenant_RefID  = securityTicket.TenantID,
                        Product_RefID = originalProductId
                    });

                    List <ORM_CMN_PRO_Dimension_Value> dimensionValuesToCreate = new List <ORM_CMN_PRO_Dimension_Value>();

                    #region SaveDimensions
                    foreach (var dimensionDb in dimensionsDb)
                    {
                        var dimensionName = dimensionDb.DimensionName;
                        var dimensionID   = dimensionDb.CMN_PRO_DimensionID;

                        ORM_CMN_PRO_Dimension dimensionCopyToCreate = new ORM_CMN_PRO_Dimension();
                        dimensionCopyToCreate.CMN_PRO_DimensionID    = Guid.NewGuid();
                        dimensionCopyToCreate.Creation_Timestamp     = DateTime.Now;
                        dimensionCopyToCreate.DimensionName          = new Dict(ORM_CMN_PRO_Dimension.TableName);
                        dimensionCopyToCreate.IsDeleted              = false;
                        dimensionCopyToCreate.IsDimensionTemplate    = false;
                        dimensionCopyToCreate.Product_RefID          = productCopyToCreate.CMN_PRO_ProductID;
                        dimensionCopyToCreate.Tenant_RefID           = securityTicket.TenantID;
                        dimensionCopyToCreate.OrderSequence          = dimensionDb.OrderSequence;
                        dimensionCopyToCreate.Modification_Timestamp = DateTime.Now;
                        dimensionCopyToCreate.Save(Connection, Transaction);
                        foreach (var lang in defaultLanguages)
                        {
                            dimensionCopyToCreate.DimensionName.UpdateEntry(lang.CMN_LanguageID, dimensionName.Contents.FirstOrDefault().Content);
                        }
                        dimensionCopyToCreate.Save(Connection, Transaction);

                        var dimensionValuesDb = ORM_CMN_PRO_Dimension_Value.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Dimension_Value.Query
                        {
                            Tenant_RefID     = securityTicket.TenantID,
                            IsDeleted        = false,
                            Dimensions_RefID = dimensionID
                        });

                        dimensionValuesDb.ForEach(x => x.Dimensions_RefID = dimensionCopyToCreate.CMN_PRO_DimensionID);
                        dimensionValuesToCreate.AddRange(dimensionValuesDb);
                    }
                    #endregion

                    var productVariantsDb = ORM_CMN_PRO_Product_Variant.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Product_Variant.Query
                    {
                        Tenant_RefID          = securityTicket.TenantID,
                        IsDeleted             = false,
                        CMN_PRO_Product_RefID = originalProductId
                    });



                    #region AssortmentProductSave
                    ORM_CMN_PRO_ASS_AssortmentProduct assortmentProductToCreate = new ORM_CMN_PRO_ASS_AssortmentProduct();
                    assortmentProductToCreate.CMN_PRO_ASS_AssortmentProductID = Guid.NewGuid();
                    assortmentProductToCreate.Ext_CMN_PRO_Product_RefID       = productCopyToCreate.CMN_PRO_ProductID;
                    assortmentProductToCreate.IsDeleted    = false;
                    assortmentProductToCreate.Tenant_RefID = securityTicket.TenantID;
                    assortmentProductToCreate.Save(Connection, Transaction);
                    #endregion

                    #region Assortment Vendor Product Save
                    P_L3AS_SAVP_0004 parameterVendorProductItem = new P_L3AS_SAVP_0004();
                    parameterVendorProductItem.AssortmentProductID = assortmentProductToCreate.CMN_PRO_ASS_AssortmentProductID;
                    parameterVendorProductItem.ProductRefID        = originalProductId;
                    parameterVendorProduct.Add(parameterVendorProductItem);
                    ORM_CMN_PRO_ASS_AssortmentProduct_VendorProduct assortmentVendorProductToCreate = new ORM_CMN_PRO_ASS_AssortmentProduct_VendorProduct();

                    #endregion

                    #region Assortment2Assortment Product save
                    ORM_CMN_PRO_ASS_Assortment_2_AssortmentProduct assortmentToAssortmentProductToCreate = new ORM_CMN_PRO_ASS_Assortment_2_AssortmentProduct();
                    assortmentToAssortmentProductToCreate.AssignmentID = Guid.NewGuid();
                    assortmentToAssortmentProductToCreate.CMN_PRO_ASS_Assortment_Product_RefID = assortmentProductToCreate.CMN_PRO_ASS_AssortmentProductID;
                    assortmentToAssortmentProductToCreate.CMN_PRO_ASS_Assortment_RefID         = Parameter.AssortmentID;
                    assortmentToAssortmentProductToCreate.IsDeleted    = false;
                    assortmentToAssortmentProductToCreate.Tenant_RefID = securityTicket.TenantID;
                    assortmentToAssortmentProductToCreate.Save(Connection, Transaction);
                    #endregion
                    List <ORM_CMN_PRO_Variant_DimensionValue> variantDimensionValueAssignmentToCreate = new List <ORM_CMN_PRO_Variant_DimensionValue>();
                    foreach (var productVariantDb in productVariantsDb)
                    {
                        #region ProductVariant Save
                        ORM_CMN_PRO_ASS_DistributionPrice distributionPriceToCreate = new ORM_CMN_PRO_ASS_DistributionPrice();
                        distributionPriceToCreate.CMN_PRO_ASS_DistributionPriceID = Guid.NewGuid();
                        distributionPriceToCreate.IsDeleted    = false;
                        distributionPriceToCreate.Tenant_RefID = securityTicket.TenantID;
                        distributionPriceToCreate.Save(Connection, Transaction);

                        ORM_CMN_PRO_Product_Variant productVariantToCreate = new ORM_CMN_PRO_Product_Variant();
                        productVariantToCreate.CMN_PRO_Product_VariantID = Guid.NewGuid();
                        productVariantToCreate.CMN_PRO_Product_RefID     = productCopyToCreate.CMN_PRO_ProductID;
                        productVariantToCreate.Creation_Timestamp        = DateTime.Now;
                        productVariantToCreate.Tenant_RefID      = securityTicket.TenantID;
                        productVariantToCreate.ProductVariantITL = "";
                        productVariantToCreate.ProductVariant_DocumentationStructure_RefID = Guid.Empty;
                        productVariantToCreate.VariantName = new Dict(ORM_CMN_PRO_Product_Variant.TableName);
                        productVariantToCreate.IsDeleted   = false;
                        productVariantToCreate.IsStandardProductVariant      = productVariantDb.IsStandardProductVariant;
                        productVariantToCreate.IsImportedFromExternalCatalog = false;
                        productVariantToCreate.Modification_Timestamp        = DateTime.Now;

                        productVariantToCreate.Save(Connection, Transaction);
                        foreach (var lang in defaultLanguages)
                        {
                            productVariantToCreate.VariantName.UpdateEntry(lang.CMN_LanguageID, productVariantDb.VariantName.Contents.FirstOrDefault().Content);
                        }
                        productVariantToCreate.Save(Connection, Transaction);

                        #endregion

                        #region dimensionValuesAssignemnt

                        var assignmentExists = ORM_CMN_PRO_Variant_DimensionValue.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Variant_DimensionValue.Query
                        {
                            Tenant_RefID = securityTicket.TenantID,

                            ProductVariant_RefID = productVariantDb.CMN_PRO_Product_VariantID
                        });
                        foreach (var variantAssignment in assignmentExists)
                        {
                            variantAssignment.IsDeleted            = false;
                            variantAssignment.ProductVariant_RefID = productVariantToCreate.CMN_PRO_Product_VariantID;
                            variantAssignment.Tenant_RefID         = securityTicket.TenantID;

                            variantDimensionValueAssignmentToCreate.Add(variantAssignment);
                        }
                        #endregion

                        #region AddVariantToAssortment
                        ORM_CMN_PRO_ASS_AssortmentVariant assortmentVariantToCreate = new ORM_CMN_PRO_ASS_AssortmentVariant();
                        assortmentVariantToCreate.CMN_PRO_ASS_AssortmentVariantID   = Guid.NewGuid();
                        assortmentVariantToCreate.Ext_CMN_PRO_Product_Variant_RefID = productVariantToCreate.CMN_PRO_Product_VariantID;
                        assortmentVariantToCreate.IsDeleted = false;
                        assortmentVariantToCreate.DistributionPrice_RefID = distributionPriceToCreate.CMN_PRO_ASS_DistributionPriceID;
                        assortmentVariantToCreate.Tenant_RefID            = securityTicket.TenantID;
                        assortmentVariantToCreate.Save(Connection, Transaction);
                        #endregion
                        P_L3AS_SAVV_0040 parameterVendorVariantItem = new P_L3AS_SAVV_0040();
                        parameterVendorVariantItem.AssortmentVariantID    = assortmentVariantToCreate.CMN_PRO_ASS_AssortmentVariantID;
                        parameterVendorVariantItem.ProductVariantID       = productVariantDb.CMN_PRO_Product_VariantID;
                        parameterVendorVariantItem.OrderSequence          = 1;
                        parameterVendorVariantItem.IsDefaultVendorVariant = true;
                        parameterVendorVariants.Add(parameterVendorVariantItem);
                    }

                    #region SaveDimensionValuesAndAssignment
                    foreach (var dimensionValueToCreate in dimensionValuesToCreate)
                    {
                        var valueName = dimensionValueToCreate.DimensionValue_Text;
                        var valueID   = dimensionValueToCreate.CMN_PRO_Dimension_ValueID;

                        ORM_CMN_PRO_Dimension_Value dimensionValueToCreateUpdate = new ORM_CMN_PRO_Dimension_Value();
                        dimensionValueToCreateUpdate.CMN_PRO_Dimension_ValueID = Guid.NewGuid();
                        dimensionValueToCreateUpdate.Creation_Timestamp        = DateTime.Now;
                        dimensionValueToCreateUpdate.DimensionValue_Text       = new Dict(ORM_CMN_PRO_Dimension_Value.TableName);
                        dimensionValueToCreateUpdate.Dimensions_RefID          = dimensionValueToCreate.Dimensions_RefID;
                        dimensionValueToCreateUpdate.IsDeleted              = false;
                        dimensionValueToCreateUpdate.Tenant_RefID           = securityTicket.TenantID;
                        dimensionValueToCreateUpdate.Modification_Timestamp = DateTime.Now;
                        dimensionValueToCreateUpdate.OrderSequence          = dimensionValueToCreate.OrderSequence;
                        dimensionValueToCreateUpdate.Save(Connection, Transaction);
                        foreach (var lang in defaultLanguages)
                        {
                            dimensionValueToCreateUpdate.DimensionValue_Text.UpdateEntry(lang.CMN_LanguageID, valueName.Contents.FirstOrDefault().Content);
                        }
                        dimensionValueToCreateUpdate.Save(Connection, Transaction);

                        var assignments = variantDimensionValueAssignmentToCreate.Where(x => x.DimensionValue_RefID == valueID).ToList();
                        foreach (var assignment in assignments)
                        {
                            ORM_CMN_PRO_Variant_DimensionValue assignmentToSave = new ORM_CMN_PRO_Variant_DimensionValue();
                            assignmentToSave.CMN_PRO_Variant_DimensionValueID = Guid.NewGuid();
                            assignmentToSave.Creation_Timestamp     = DateTime.Now;
                            assignmentToSave.DimensionValue_RefID   = dimensionValueToCreateUpdate.CMN_PRO_Dimension_ValueID;
                            assignmentToSave.IsDeleted              = false;
                            assignmentToSave.Modification_Timestamp = DateTime.Now;
                            assignmentToSave.ProductVariant_RefID   = assignment.ProductVariant_RefID;
                            assignmentToSave.Tenant_RefID           = securityTicket.TenantID;
                            assignmentToSave.Save(Connection, Transaction);
                        }
                    }
                    #endregion
                }
            }
            cls_Save_Assortment_Vendor_Products.Invoke(Connection, Transaction, parameterVendorProduct.ToArray(), securityTicket);
            cls_Save_Assortment_Vendor_Variants.Invoke(Connection, Transaction, parameterVendorVariants.ToArray(), securityTicket);

            return(returnValue);

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

            ORM_CMN_PRO_ASS_AssortmentProduct assProduct = new ORM_CMN_PRO_ASS_AssortmentProduct();
            assProduct.Load(Connection, Transaction, Parameter.AssortmentProductID);
            assProduct.IsDeleted = true;
            assProduct.Save(Connection, Transaction);

            ORM_CMN_PRO_ASS_Assortment_2_AssortmentProduct.Query ass2prodQuery = new ORM_CMN_PRO_ASS_Assortment_2_AssortmentProduct.Query();
            ass2prodQuery.CMN_PRO_ASS_Assortment_Product_RefID = assProduct.CMN_PRO_ASS_AssortmentProductID;
            var ass2prod = ORM_CMN_PRO_ASS_Assortment_2_AssortmentProduct.Query.Search(Connection, Transaction, ass2prodQuery);

            if (ass2prod != null)
            {
                foreach (var item in ass2prod)
                {
                    item.IsDeleted = true;
                    item.Save(Connection, Transaction);
                }
            }

            ORM_CMN_PRO_ASS_AssortmentProduct_VendorProduct.Query vendorsQuery = new ORM_CMN_PRO_ASS_AssortmentProduct_VendorProduct.Query();
            vendorsQuery.CMN_PRO_ASS_AssortmentProduct_RefID = assProduct.CMN_PRO_ASS_AssortmentProductID;
            var vendors = ORM_CMN_PRO_ASS_AssortmentProduct_VendorProduct.Query.Search(Connection, Transaction, vendorsQuery);

            if (vendors != null)
            {
                foreach (var item in vendors)
                {
                    item.IsDeleted = true;
                    item.Save(Connection, Transaction);
                }
            }

            P_L3AS_GAVfAP_1128 variantsParam = new P_L3AS_GAVfAP_1128()
            {
                AssortmentProductID = Parameter.AssortmentProductID
            };
            var variants = cls_Get_AssortmentVariants_for_AssortmentProduct.Invoke(Connection, Transaction, variantsParam, securityTicket).Result;

            foreach (var variant in variants)
            {
                ORM_CMN_PRO_ASS_AssortmentVariant assortmentVariant = new ORM_CMN_PRO_ASS_AssortmentVariant();
                assortmentVariant.Load(Connection, Transaction, variant.CMN_PRO_ASS_AssortmentVariantID);
                assortmentVariant.IsDeleted = true;
                assortmentVariant.Save(Connection, Transaction);

                ORM_CMN_PRO_ASS_DistributionPrice distributionPrice = new ORM_CMN_PRO_ASS_DistributionPrice();
                distributionPrice.Load(Connection, Transaction, assortmentVariant.DistributionPrice_RefID);
                distributionPrice.IsDeleted = true;
                distributionPrice.Save(Connection, Transaction);
            }

            return(returnValue);

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


            if (Parameter == null)
            {
                returnValue.ErrorMessage = "Parameter is null or there is no product variant defined";
                returnValue.Status       = FR_Status.Error_Internal;
                return(returnValue);
            }

            if (Parameter.Variants == null && Parameter.Dimensions == null && Parameter.DimensionValues == null)
            {
                returnValue.ErrorMessage = "Variants, Dimensions and Dimension Values are not defined";
                returnValue.Status       = FR_Status.Error_Internal;
                return(returnValue);
            }


            if (Parameter.Variants.Length == 0 && Parameter.Dimensions.Length == 0 && Parameter.DimensionValues.Length == 0)
            {
                returnValue.ErrorMessage = "Variants, Dimensions and Dimension Values are not defined";
                returnValue.Status       = FR_Status.Error_Internal;
                return(returnValue);
            }

            #region Variants Create/Update

            foreach (var variant in Parameter.Variants)
            {
                bool createNewVariant = false;
                ORM_CMN_PRO_Product_Variant variantToCreateUpdate = new ORM_CMN_PRO_Product_Variant();

                FR_Base vLoad = variantToCreateUpdate.Load(Connection, Transaction, variant.CMN_PRO_Product_VariantID);
                if (vLoad.Status != FR_Status.Success || variantToCreateUpdate.CMN_PRO_Product_VariantID == Guid.Empty)
                {
                    createNewVariant = true;
                }


                if (createNewVariant)
                {
                    variantToCreateUpdate.CMN_PRO_Product_VariantID = variant.CMN_PRO_Product_VariantID;
                    variantToCreateUpdate.CMN_PRO_Product_RefID     = Parameter.ProductID;
                    variantToCreateUpdate.Creation_Timestamp        = DateTime.Now;
                    variantToCreateUpdate.Tenant_RefID      = securityTicket.TenantID;
                    variantToCreateUpdate.ProductVariantITL = "";
                    variantToCreateUpdate.ProductVariant_DocumentationStructure_RefID = Guid.Empty;
                    variantToCreateUpdate.VariantName = variant.VariantName;
                    variantToCreateUpdate.IsDeleted   = false;

                    ORM_CMN_PRO_ASS_DistributionPrice distributionPriceToCreate = new ORM_CMN_PRO_ASS_DistributionPrice();
                    distributionPriceToCreate.CMN_PRO_ASS_DistributionPriceID = Guid.NewGuid();
                    distributionPriceToCreate.IsDeleted    = false;
                    distributionPriceToCreate.Tenant_RefID = securityTicket.TenantID;
                    distributionPriceToCreate.Save(Connection, Transaction);

                    ORM_CMN_PRO_ASS_AssortmentVariant assortmentVariantToCreate = new ORM_CMN_PRO_ASS_AssortmentVariant();
                    assortmentVariantToCreate.CMN_PRO_ASS_AssortmentVariantID   = Guid.NewGuid();
                    assortmentVariantToCreate.Ext_CMN_PRO_Product_Variant_RefID = variantToCreateUpdate.CMN_PRO_Product_VariantID;
                    assortmentVariantToCreate.IsDeleted = false;
                    assortmentVariantToCreate.DistributionPrice_RefID = distributionPriceToCreate.CMN_PRO_ASS_DistributionPriceID;
                    assortmentVariantToCreate.Tenant_RefID            = securityTicket.TenantID;
                    assortmentVariantToCreate.Save(Connection, Transaction);
                }

                variantToCreateUpdate.IsImportedFromExternalCatalog = variant.IsImportedFromExternalCatalog;
                variantToCreateUpdate.IsObsolete = variant.IsObsolete;
                variantToCreateUpdate.IsProductAvailableForOrdering = variant.IsProductAvailableForOrdering;
                variantToCreateUpdate.IsStandardProductVariant      = variant.IsStandardProductVariant;
                variantToCreateUpdate.Modification_Timestamp        = DateTime.Now;

                variantToCreateUpdate.Save(Connection, Transaction);
            }

            #endregion

            #region Dimensions Create/Update

            foreach (var dimension in Parameter.Dimensions)
            {
                bool createNewDimension = false;
                ORM_CMN_PRO_Dimension dimensionToCreateUpdate = new ORM_CMN_PRO_Dimension();
                FR_Base dLoad = dimensionToCreateUpdate.Load(Connection, Transaction, dimension.CMN_PRO_DimensionID);
                if (dLoad.Status != FR_Status.Success || dimensionToCreateUpdate.CMN_PRO_DimensionID == Guid.Empty)
                {
                    createNewDimension = true;
                }

                if (createNewDimension)
                {
                    dimensionToCreateUpdate.CMN_PRO_DimensionID = dimension.CMN_PRO_DimensionID;
                    dimensionToCreateUpdate.Abbreviation        = dimension.Abbreviation;
                    dimensionToCreateUpdate.Creation_Timestamp  = DateTime.Now;
                    dimensionToCreateUpdate.DimensionName       = dimension.DimensionName;
                    dimensionToCreateUpdate.IsDeleted           = false;
                    dimensionToCreateUpdate.IsDimensionTemplate = false;
                    dimensionToCreateUpdate.Product_RefID       = Parameter.ProductID;
                    dimensionToCreateUpdate.Tenant_RefID        = securityTicket.TenantID;
                }

                dimensionToCreateUpdate.OrderSequence          = dimension.OrderSequence;
                dimensionToCreateUpdate.Modification_Timestamp = DateTime.Now;
                dimensionToCreateUpdate.Save(Connection, Transaction);
            }

            #endregion

            #region Dimension Values Create/Update

            foreach (var dimensionValue in Parameter.DimensionValues)
            {
                bool createNewDimensionValue = false;
                ORM_CMN_PRO_Dimension_Value dimensionValueToCreateUpdate = new ORM_CMN_PRO_Dimension_Value();

                FR_Base dvLoad = dimensionValueToCreateUpdate.Load(Connection, Transaction, dimensionValue.CMN_PRO_Dimension_ValueID);
                if (dvLoad.Status != FR_Status.Success || dimensionValueToCreateUpdate.CMN_PRO_Dimension_ValueID == Guid.Empty)
                {
                    createNewDimensionValue = true;
                }

                if (createNewDimensionValue)
                {
                    dimensionValueToCreateUpdate.CMN_PRO_Dimension_ValueID = dimensionValue.CMN_PRO_Dimension_ValueID;
                    dimensionValueToCreateUpdate.Creation_Timestamp        = DateTime.Now;
                    dimensionValueToCreateUpdate.Dimensions_RefID          = dimensionValue.Dimension_RefID;
                    dimensionValueToCreateUpdate.DimensionValue_Text       = dimensionValue.DimensionValue_Text;
                    dimensionValueToCreateUpdate.IsDeleted    = false;
                    dimensionValueToCreateUpdate.Tenant_RefID = securityTicket.TenantID;
                }

                dimensionValueToCreateUpdate.Modification_Timestamp = DateTime.Now;
                dimensionValueToCreateUpdate.OrderSequence          = dimensionValue.OrderSequence;
                dimensionValueToCreateUpdate.Save(Connection, Transaction);
            }

            #endregion

            #region Assignments

            foreach (var variant in Parameter.Variants)
            {
                foreach (var dimensionValue in Parameter.DimensionValues)
                {
                    if ((variant.DimensionValue1_RefID == dimensionValue.CMN_PRO_Dimension_ValueID) || (variant.DimensionValue2_RefID == dimensionValue.CMN_PRO_Dimension_ValueID))
                    {
                        bool assignmentExists = ORM_CMN_PRO_Variant_DimensionValue.Query.Exists(Connection, Transaction, new ORM_CMN_PRO_Variant_DimensionValue.Query()
                        {
                            IsDeleted            = false,
                            Tenant_RefID         = securityTicket.TenantID,
                            DimensionValue_RefID = dimensionValue.CMN_PRO_Dimension_ValueID,
                            ProductVariant_RefID = variant.CMN_PRO_Product_VariantID
                        });

                        if (!assignmentExists)
                        {
                            ORM_CMN_PRO_Variant_DimensionValue assignment = new ORM_CMN_PRO_Variant_DimensionValue();
                            assignment.CMN_PRO_Variant_DimensionValueID = Guid.NewGuid();
                            assignment.Creation_Timestamp     = DateTime.Now;
                            assignment.DimensionValue_RefID   = dimensionValue.CMN_PRO_Dimension_ValueID;
                            assignment.IsDeleted              = false;
                            assignment.Modification_Timestamp = DateTime.Now;
                            assignment.ProductVariant_RefID   = variant.CMN_PRO_Product_VariantID;
                            assignment.Tenant_RefID           = securityTicket.TenantID;
                            assignment.Save(Connection, Transaction);
                        }
                    }
                }
            }

            #endregion

            return(returnValue);

            #endregion UserCode
        }