protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3DT_1055 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 ORM_CMN_PRO_Dimension item = null; item = ORM_CMN_PRO_Dimension.Query.Search(Connection, Transaction, new ORM_CMN_PRO_Dimension.Query { IsDeleted = false, Tenant_RefID = securityTicket.TenantID, CMN_PRO_DimensionID = Parameter.DimensionTemplateID }).FirstOrDefault(); if (item == null) { returnValue.Status = FR_Status.Error_Internal; returnValue.ErrorMessage = String.Format("No dimension template with id = {1} found.", Parameter.DimensionTemplateID.ToString()); return(returnValue); } item.IsDeleted = true; item.Save(Connection, Transaction); returnValue.Result = item.CMN_PRO_DimensionID; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L3D_SDT_1335 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); var defaultLanguages = ORM_CMN_Language.Query.Search(Connection, Transaction, new ORM_CMN_Language.Query { IsDeleted = false, Tenant_RefID = securityTicket.TenantID }); ORM_CMN_PRO_Dimension dimension = new ORM_CMN_PRO_Dimension(); dimension.Load(Connection, Transaction, Parameter.CMN_PRO_DimensionID); if (dimension.CMN_PRO_DimensionID == null || dimension.CMN_PRO_DimensionID == Guid.Empty) { dimension.CMN_PRO_DimensionID = Parameter.CMN_PRO_DimensionID; } dimension.DimensionName = new Dict(ORM_CMN_PRO_Dimension.TableName); dimension.IsDeleted = false; dimension.IsDimensionTemplate = true; dimension.Tenant_RefID = securityTicket.TenantID; dimension.Save(Connection, Transaction); foreach (var lang in defaultLanguages) { dimension.DimensionName.AddEntry(lang.CMN_LanguageID, Parameter.DimensionName); } var status = dimension.Save(Connection, Transaction); foreach (var dimensionValue in Parameter.DimensionValue) { ORM_CMN_PRO_Dimension_Value orm_dimensionValue = new ORM_CMN_PRO_Dimension_Value(); orm_dimensionValue.Load(Connection, Transaction, dimensionValue.CMN_PRO_Dimension_ValueID); if (orm_dimensionValue == null || orm_dimensionValue.CMN_PRO_Dimension_ValueID == Guid.Empty) { orm_dimensionValue.CMN_PRO_Dimension_ValueID = dimensionValue.CMN_PRO_Dimension_ValueID; } orm_dimensionValue.Dimensions_RefID = dimension.CMN_PRO_DimensionID; orm_dimensionValue.DimensionValue_Text = new Dict(ORM_CMN_PRO_Dimension.TableName); orm_dimensionValue.OrderSequence = dimensionValue.OrderSequence; orm_dimensionValue.IsDeleted = dimensionValue.IsDeleted; orm_dimensionValue.Tenant_RefID = securityTicket.TenantID; orm_dimensionValue.Save(Connection, Transaction); foreach (var lang in defaultLanguages) { orm_dimensionValue.DimensionValue_Text.AddEntry(lang.CMN_LanguageID, dimensionValue.DimensionValue_Text); } status = orm_dimensionValue.Save(Connection, Transaction); } if (status.Status == FR_Status.Success) { returnValue.Result = dimension.CMN_PRO_DimensionID; } return(returnValue); #endregion UserCode }
protected static FR_Bool Execute(DbConnection Connection, DbTransaction Transaction, P_L5ZW_SDfNC_1707 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Bool(); returnValue.Result = false; //Put your code here #region get securityTicket and businessParticipantID by Paramter.AccountID and set defaultLanguageID Guid tenantID; Guid businessParticipantID; if (Parameter.AccountID == Guid.Empty) { return(returnValue); } ORM_USR_Account orm_account = new ORM_USR_Account(); var result = orm_account.Load(Connection, Transaction, Parameter.AccountID); if (result.Status != FR_Status.Success || orm_account.USR_AccountID == Guid.Empty) { return(returnValue); } tenantID = orm_account.Tenant_RefID; securityTicket = new CSV2Core.SessionSecurity.SessionSecurityTicket() { TenantID = tenantID }; ORM_CMN_BPT_BusinessParticipant.Query businessParticipantQuery = new ORM_CMN_BPT_BusinessParticipant.Query(); businessParticipantQuery.IfTenant_Tenant_RefID = tenantID; businessParticipantQuery.IsDeleted = false; ORM_CMN_BPT_BusinessParticipant businessParticipant = ORM_CMN_BPT_BusinessParticipant.Query.Search(Connection, Transaction, businessParticipantQuery).FirstOrDefault(); if (businessParticipant == null) { return(returnValue); } businessParticipantID = businessParticipant.CMN_BPT_BusinessParticipantID; #endregion #region get languages for tenant and set parameter dict values P_L2LN_GALFTID_1530 languageParam = new P_L2LN_GALFTID_1530() { Tenant_RefID = tenantID }; L2LN_GALFTID_1530[] languages = cls_Get_All_Languages_ForTenantID.Invoke(Connection, Transaction, languageParam, securityTicket).Result; SetParameterDictValues(Parameter, languages); List <ISOLanguage> languagesISOs = new List <ISOLanguage>(); languagesISOs.AddRange(languages.Select(l => new ISOLanguage() { ISO = l.ISO_639_1, LanguageID = l.CMN_LanguageID }).ToList()); #endregion #region save defaultLanguage // We are setting language for bp and acc var defaultLanguage = languages.FirstOrDefault(i => i.ISO_639_1.ToLower().Contains(Parameter.DefaultLanguageCode.ToLower())); if (defaultLanguage != null) { businessParticipant.DefaultLanguage_RefID = defaultLanguage.CMN_LanguageID; businessParticipant.Save(Connection, Transaction); orm_account.DefaultLanguage_RefID = defaultLanguage.CMN_LanguageID; orm_account.Save(Connection, Transaction); } #endregion #region save default country if (Parameter.DefaultCountry != null) { ORM_CMN_Country country = new ORM_CMN_Country(); country.CMN_CountryID = Guid.NewGuid(); country.Country_ISOCode_Alpha3 = Parameter.DefaultCountry.Code; country.Country_Name = new Dict() { DictionaryID = Guid.NewGuid() }; country.Creation_Timestamp = DateTime.Now; country.Default_Currency_RefID = Guid.Empty; country.Default_Language_RefID = Guid.Empty; country.Tenant_RefID = tenantID; country.IsDeleted = false; country.IsDefault = true; foreach (var languageItem in languages) { country.Country_Name.UpdateEntry(languageItem.CMN_LanguageID, Parameter.DefaultCountry.Name); } country.Save(Connection, Transaction); } #endregion #region save default currency //asign currency if (Parameter.DefaultCurrency != null) { ORM_CMN_Currency currency = new ORM_CMN_Currency(); currency.CMN_CurrencyID = Guid.NewGuid(); currency.Creation_Timestamp = DateTime.Now; currency.IsDeleted = false; currency.ISO4127 = Parameter.DefaultCurrency.Code; currency.Name = new Dict() { DictionaryID = Guid.NewGuid() }; currency.Tenant_RefID = tenantID; foreach (var language in languages) { currency.Name.UpdateEntry(language.CMN_LanguageID, Parameter.DefaultCurrency.Name); } currency.Save(Connection, Transaction); //set default currency ORM_CMN_BPT_BusinessParticipant businessPart = new ORM_CMN_BPT_BusinessParticipant(); businessPart.Load(Connection, Transaction, businessParticipantID); businessPart.DefaultCurrency_RefID = currency.CMN_CurrencyID; businessPart.Save(Connection, Transaction); } #endregion #region save organisational units if (Parameter.OrganisationalUnitParameters.Length > 0) { foreach (var item in Parameter.OrganisationalUnitParameters) { cls_Save_Office.Invoke(Connection, Transaction, item, securityTicket); } } #endregion #region save cost centers if (Parameter.CostCenterParameters.Length > 0) { foreach (var item in Parameter.CostCenterParameters) { cls_Save_CostCenter.Invoke(Connection, Transaction, item, securityTicket); } } #endregion #region save warehouses if (Parameter.WarehousesParameters.Length > 0) { #region save warehouse group P_L2WH_SWHG_1327 warehouseGroupParam = new P_L2WH_SWHG_1327(); warehouseGroupParam.Parent_RefID = Guid.Empty; warehouseGroupParam.WarehouseGroup_Name = "Waregouse group"; warehouseGroupParam.WarehouseGroup_Description = new Dict() { DictionaryID = Guid.NewGuid() }; foreach (var language in languages) { warehouseGroupParam.WarehouseGroup_Description.UpdateEntry(language.CMN_LanguageID, String.Empty); } var warehouseGroupID = cls_Save_Warehouse_Group.Invoke(Connection, Transaction, warehouseGroupParam, securityTicket).Result; #endregion foreach (var item in Parameter.WarehousesParameters) { item.LOG_WRH_WarehouseGroupID = warehouseGroupID; cls_Save_Warehouse.Invoke(Connection, Transaction, item, securityTicket); } } #endregion #region create dimension templates string jsonTemplates = ReadFromFile.LoadContentFromFile(@"Dimensions.json"); List <Dimension> dimensionTemplates = JsonConvert.DeserializeObject <List <Dimension> >(jsonTemplates); int orderSequence = 1; ORM_CMN_PRO_Dimension orm_dimension; ORM_CMN_PRO_Dimension_Value orm_dimensionValue; foreach (var template in dimensionTemplates) { orderSequence = 1; #region save dimension orm_dimension = new ORM_CMN_PRO_Dimension(); orm_dimension.Product_RefID = Guid.Empty; orm_dimension.DimensionName = new Dict() { DictionaryID = Guid.NewGuid() }; orm_dimension.IsDimensionTemplate = true; orm_dimension.Tenant_RefID = tenantID; foreach (var language in languages) { orm_dimension.DimensionName.UpdateEntry(language.CMN_LanguageID, template.Name); } orm_dimension.Save(Connection, Transaction); #endregion #region save dimension values foreach (var templateValue in template.DimansionValues) { orm_dimensionValue = new ORM_CMN_PRO_Dimension_Value(); orm_dimensionValue.Dimensions_RefID = orm_dimension.CMN_PRO_DimensionID; orm_dimensionValue.DimensionValue_Text = new Dict() { DictionaryID = Guid.NewGuid() }; orm_dimensionValue.Tenant_RefID = tenantID; orm_dimensionValue.OrderSequence = orderSequence; foreach (var language in languages) { orm_dimensionValue.DimensionValue_Text.UpdateEntry(language.CMN_LanguageID, templateValue); } orm_dimensionValue.Save(Connection, Transaction); orderSequence++; } #endregion } #endregion #region create shipment types string shipmentTypesJson = ReadFromFile.LoadContentFromFile(@"ShipmentTypes.json"); List <ShipmentTypes> shipmentTypes = JsonConvert.DeserializeObject <List <ShipmentTypes> >(shipmentTypesJson); ORM_LOG_SHP_Shipment_Type orm_shipmentType; foreach (var type in shipmentTypes) { #region save LOG_SHP_Shipment_Type orm_shipmentType = new ORM_LOG_SHP_Shipment_Type(); orm_shipmentType.ShipmentType_Name = new Dict() { DictionaryID = Guid.NewGuid() }; orm_shipmentType.ShipmentType_Description = new Dict() { DictionaryID = Guid.NewGuid() }; orm_shipmentType.Tenant_RefID = tenantID; foreach (var language in languages) { orm_shipmentType.ShipmentType_Name.UpdateEntry(language.CMN_LanguageID, type.Name); orm_shipmentType.ShipmentType_Description.UpdateEntry(language.CMN_LanguageID, string.Empty); } orm_shipmentType.Save(Connection, Transaction); #endregion } #endregion #region create number ranges string numberRangesJson = ReadFromFile.LoadContentFromFile(@"NumberRanges.json"); NumberRange numberRanges = JsonConvert.DeserializeObject <NumberRange>(numberRangesJson); ORM_CMN_NumberRange_UsageArea numberRangeUsageArea; ORM_CMN_NumberRange orm_numberRanges; foreach (var item in numberRanges.NumberRanges) { if (Parameter.IsCustomerRegistration && item.Name == "Customer orders") { continue; } if (!Parameter.IsCustomerRegistration && item.Name == "Distribution orders") { continue; } if (!Parameter.IsCustomerRegistration && item.Name == "Procurement orders") { continue; } numberRangeUsageArea = new ORM_CMN_NumberRange_UsageArea(); numberRangeUsageArea.UsageArea_Name = new Dict() { DictionaryID = Guid.NewGuid() }; numberRangeUsageArea.UsageArea_Description = new Dict() { DictionaryID = Guid.NewGuid() }; foreach (var language in languages) { numberRangeUsageArea.UsageArea_Name.UpdateEntry(language.CMN_LanguageID, item.Name); numberRangeUsageArea.UsageArea_Description.UpdateEntry(language.CMN_LanguageID, string.Empty); } numberRangeUsageArea.Tenant_RefID = tenantID; numberRangeUsageArea.GlobalStaticMatchingID = item.GlobalStaticMatchingID; numberRangeUsageArea.Save(Connection, Transaction); orm_numberRanges = new ORM_CMN_NumberRange(); orm_numberRanges.NumberRange_Name = item.Name; orm_numberRanges.Tenant_RefID = tenantID; orm_numberRanges.NumberRange_UsageArea_RefID = numberRangeUsageArea.CMN_NumberRange_UsageAreaID; orm_numberRanges.FixedPrefix = item.FixedPrefix; orm_numberRanges.Formatting_LeadingFillCharacter = item.FillCharacter; orm_numberRanges.Formatting_NumberLength = item.Length; orm_numberRanges.Value_Current = item.CurrentValue; orm_numberRanges.Value_Start = item.StartValue; orm_numberRanges.Value_End = item.EndValue; orm_numberRanges.Save(Connection, Transaction); } #endregion #region create inventory change reasons string inventoryChangeReasonsJson = ReadFromFile.LoadContentFromFile(@"InventoryChangeReasons.json"); List <InventoryChangeReasons> inventoryChangeReasons = JsonConvert.DeserializeObject <List <InventoryChangeReasons> >(inventoryChangeReasonsJson); ORM_LOG_WRH_InventoryChangeReason orm_inventoryChangeReason; foreach (var reason in inventoryChangeReasons) { #region save inventory change reason orm_inventoryChangeReason = new ORM_LOG_WRH_InventoryChangeReason(); orm_inventoryChangeReason.GlobalPropertyMatchingID = InventoryChangeReasons.InventoryChangeReasonGlobalPropertyMatchingID + "-" + reason.Name; orm_inventoryChangeReason.InventoryChange_Name = new Dict() { DictionaryID = Guid.NewGuid() }; orm_inventoryChangeReason.InventoryChange_Description = new Dict() { DictionaryID = Guid.NewGuid() }; orm_inventoryChangeReason.Tenant_RefID = tenantID; foreach (var language in languages) { orm_inventoryChangeReason.InventoryChange_Name.UpdateEntry(language.CMN_LanguageID, reason.Name); orm_inventoryChangeReason.InventoryChange_Description.UpdateEntry(language.CMN_LanguageID, string.Empty); } orm_inventoryChangeReason.Save(Connection, Transaction); #endregion } #endregion #region create shipment statuses var shipmentStatuses = Enum.GetValues(typeof(EShipmentStatus)); var shipmentStatusDicts = EnumUtils.GetDictObjectsForStaticListData <EShipmentStatus>( ResourceFilePath.ShipmentStatus, ORM_LOG_SHP_Shipment_Status.TableName, languagesISOs); var statusCodeCount = 1; ORM_LOG_SHP_Shipment_Status shipmentStatus; foreach (EShipmentStatus status in shipmentStatuses) { shipmentStatus = new ORM_LOG_SHP_Shipment_Status(); shipmentStatus.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription((EShipmentStatus)status); shipmentStatus.Status_Code = statusCodeCount++; shipmentStatus.Status_Name = shipmentStatusDicts[EnumUtils.GetEnumDescription((EShipmentStatus)status)]; shipmentStatus.Tenant_RefID = tenantID; shipmentStatus.Save(Connection, Transaction); } #endregion if (Parameter.IsCustomerRegistration) { #region create procurement order statuses var procurementStatuses = Enum.GetValues(typeof(EProcurementStatus)); ORM_ORD_PRC_ProcurementOrder_Status procurementOrderStatus; foreach (EProcurementStatus status in procurementStatuses) { procurementOrderStatus = new ORM_ORD_PRC_ProcurementOrder_Status(); procurementOrderStatus.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription(status); procurementOrderStatus.Tenant_RefID = tenantID; procurementOrderStatus.Save(Connection, Transaction); } #endregion } else { #region create customer order statuses var customerOrderStatuses = Enum.GetValues(typeof(ECustomerOrderStatus)); var customerOrderStatusesDicts = EnumUtils.GetDictObjectsForStaticListData <ECustomerOrderStatus>( ResourceFilePath.CustomerOrderStatus, ORM_ORD_CUO_CustomerOrder_Status.TableName, languagesISOs); var count = 1; ORM_ORD_CUO_CustomerOrder_Status customerOrderStatus; foreach (var status in customerOrderStatuses) { customerOrderStatus = new ORM_ORD_CUO_CustomerOrder_Status(); customerOrderStatus.GlobalPropertyMatchingID = EnumUtils.GetEnumDescription((ECustomerOrderStatus)status); customerOrderStatus.Status_Code = count++; customerOrderStatus.Status_Name = customerOrderStatusesDicts[EnumUtils.GetEnumDescription((ECustomerOrderStatus)status)]; customerOrderStatus.Tenant_RefID = tenantID; customerOrderStatus.Save(Connection, Transaction); } #endregion } returnValue.Result = true; return(returnValue); #endregion UserCode }
protected static FR_Guid Execute(DbConnection Connection, DbTransaction Transaction, P_L5PR_IPfC_1648 Parameter, CSV2Core.SessionSecurity.SessionSecurityTicket securityTicket = null) { #region UserCode var returnValue = new FR_Guid(); var defaultLanguages = ORM_CMN_Language.Query.Search(Connection, Transaction, new ORM_CMN_Language.Query { IsDeleted = false, Tenant_RefID = securityTicket.TenantID }); var productFromCatalog = Parameter.Product; ORM_CMN_PRO_SubscribedCatalog subscribedCatalog = new ORM_CMN_PRO_SubscribedCatalog(); var existingCatalog = ORM_CMN_PRO_SubscribedCatalog.Query.Search(Connection, Transaction, new ORM_CMN_PRO_SubscribedCatalog.Query() { CatalogCodeITL = productFromCatalog.CatalogITL }); if (existingCatalog != null && existingCatalog.Count() > 0) { subscribedCatalog = existingCatalog.First(); } var supplierID = subscribedCatalog.PublishingSupplier_RefID; ORM_CMN_PRO_Product productToCreateUpdate = new ORM_CMN_PRO_Product(); productToCreateUpdate.CMN_PRO_ProductID = Guid.NewGuid(); ORM_CMN_PRO_Product.Query productDbQuery = new ORM_CMN_PRO_Product.Query(); productDbQuery.ProductITL = productFromCatalog.ProductITL; productDbQuery.Tenant_RefID = securityTicket.TenantID; productDbQuery.IsDeleted = false; var product = ORM_CMN_PRO_Product.Query.Search(Connection, Transaction, productDbQuery); if (product != null && product.Count > 0) { productToCreateUpdate = product.First(); ORM_CMN_PRO_Dimension.Query dimensionQuery = new ORM_CMN_PRO_Dimension.Query(); dimensionQuery.Product_RefID = productToCreateUpdate.CMN_PRO_ProductID; dimensionQuery.Tenant_RefID = securityTicket.TenantID; dimensionQuery.IsDeleted = false; var dimensions = ORM_CMN_PRO_Dimension.Query.Search(Connection, Transaction, dimensionQuery); foreach (var dimension in dimensions) { ORM_CMN_PRO_Dimension_Value.Query dimensionValuesQuery = new ORM_CMN_PRO_Dimension_Value.Query(); dimensionValuesQuery.Dimensions_RefID = dimension.CMN_PRO_DimensionID; dimensionValuesQuery.Tenant_RefID = securityTicket.TenantID; var dimensionValues = ORM_CMN_PRO_Dimension_Value.Query.Search(Connection, Transaction, dimensionValuesQuery); foreach (var dimensionValue in dimensionValues) { ORM_CMN_PRO_Variant_DimensionValue.Query dimensionValueVariantQuery = new ORM_CMN_PRO_Variant_DimensionValue.Query(); dimensionValueVariantQuery.DimensionValue_RefID = dimensionValue.CMN_PRO_Dimension_ValueID; ORM_CMN_PRO_Variant_DimensionValue.Query.SoftDelete(Connection, Transaction, dimensionValueVariantQuery); } ORM_CMN_PRO_Dimension_Value.Query.SoftDelete(Connection, Transaction, dimensionValuesQuery); } ORM_CMN_PRO_Dimension.Query.SoftDelete(Connection, Transaction, dimensionQuery); } productToCreateUpdate.IsImportedFromExternalCatalog = true; productToCreateUpdate.Product_Name = new Dict(ORM_CMN_PRO_Product.TableName); productToCreateUpdate.IsDeleted = false; productToCreateUpdate.ProductITL = productFromCatalog.ProductITL; productToCreateUpdate.Product_Description = new Dict(ORM_CMN_PRO_Product.TableName); productToCreateUpdate.Tenant_RefID = securityTicket.TenantID; productToCreateUpdate.Product_Number = productFromCatalog.Code; foreach (var lang in defaultLanguages) { productToCreateUpdate.Product_Name.AddEntry(lang.CMN_LanguageID, productFromCatalog.Name); productToCreateUpdate.Product_Description.AddEntry(lang.CMN_LanguageID, productFromCatalog.Description); } productToCreateUpdate.Save(Connection, Transaction); returnValue.Result = productToCreateUpdate.CMN_PRO_ProductID; foreach (var customizationToDelete in ORM_CMN_PRO_CUS_Customization.Query.Search(Connection, Transaction, new ORM_CMN_PRO_CUS_Customization.Query() { Product_RefID = productToCreateUpdate.CMN_PRO_ProductID })) { ORM_CMN_PRO_CUS_Customization.Query.SoftDelete(Connection, Transaction, new ORM_CMN_PRO_CUS_Customization.Query() { CMN_PRO_CUS_CustomizationID = customizationToDelete.CMN_PRO_CUS_CustomizationID }); if (ORM_CMN_PRO_CUS_Customization_Variant.Query.Exists(Connection, Transaction, new ORM_CMN_PRO_CUS_Customization_Variant.Query() { Customization_RefID = customizationToDelete.CMN_PRO_CUS_CustomizationID })) { ORM_CMN_PRO_CUS_Customization_Variant.Query.SoftDelete(Connection, Transaction, new ORM_CMN_PRO_CUS_Customization_Variant.Query() { Customization_RefID = customizationToDelete.CMN_PRO_CUS_CustomizationID }); } } var customizationOrderSequence = 0; if (productFromCatalog.Customizations != null) { productToCreateUpdate.IsCustomizable = true; productToCreateUpdate.Save(Connection, Transaction); foreach (var customization in productFromCatalog.Customizations) { ORM_CMN_PRO_CUS_Customization customizationToSave = new ORM_CMN_PRO_CUS_Customization(); customizationToSave.CMN_PRO_CUS_CustomizationID = Guid.NewGuid(); customizationToSave.Customization_Description = new Dict(ORM_CMN_PRO_CUS_Customization.TableName); customizationToSave.Customization_Name = new Dict(ORM_CMN_PRO_CUS_Customization.TableName); customizationToSave.IsDeleted = false; customizationToSave.Product_RefID = productToCreateUpdate.CMN_PRO_ProductID; customizationToSave.Tenant_RefID = securityTicket.TenantID; customizationToSave.OrderSequence = customizationOrderSequence; customizationOrderSequence++; foreach (var lang in defaultLanguages) { customizationToSave.Customization_Description.UpdateEntry(lang.CMN_LanguageID, customization.Description); customizationToSave.Customization_Name.UpdateEntry(lang.CMN_LanguageID, customization.Name); } customizationToSave.Save(Connection, Transaction); var customizationVariantOrderSequence = 0; foreach (var customizationVariant in customization.CustomizationVariants) { ORM_CMN_PRO_CUS_Customization_Variant customizationVariantsToSave = new ORM_CMN_PRO_CUS_Customization_Variant(); customizationVariantsToSave.CMN_PRO_CUS_Customization_VariantID = Guid.NewGuid(); customizationVariantsToSave.Customization_RefID = customizationToSave.CMN_PRO_CUS_CustomizationID; customizationVariantsToSave.CustomizationVariant_Name = new Dict(ORM_CMN_PRO_CUS_Customization_Variant.TableName); customizationVariantsToSave.OrderSequence = customizationVariantOrderSequence; customizationVariantOrderSequence++; customizationVariantsToSave.IsDeleted = false; customizationVariantsToSave.Tenant_RefID = securityTicket.TenantID; foreach (var lang in defaultLanguages) { customizationVariantsToSave.CustomizationVariant_Name.UpdateEntry(lang.CMN_LanguageID, customizationVariant.Name); } customizationVariantsToSave.Save(Connection, Transaction); } } } ORM_CMN_PRO_Product_Variant.Query productVariantQuery = new ORM_CMN_PRO_Product_Variant.Query(); productVariantQuery.CMN_PRO_Product_RefID = productToCreateUpdate.CMN_PRO_ProductID; productVariantQuery.Tenant_RefID = securityTicket.TenantID; productVariantQuery.IsDeleted = false; var productVariantsDb = ORM_CMN_PRO_Product_Variant.Query.Search(Connection, Transaction, productVariantQuery); List <ORM_CMN_PRO_Dimension> dimensionsToCreate = new List <ORM_CMN_PRO_Dimension>(); List <ORM_CMN_PRO_Dimension_Value> dimensionValuesToCreate = new List <ORM_CMN_PRO_Dimension_Value>(); foreach (var productVariantFromCatalog in productFromCatalog.Variants) { ORM_CMN_PRO_Product_Variant.Query variantToCreateQuery = new ORM_CMN_PRO_Product_Variant.Query(); variantToCreateQuery.ProductVariantITL = productVariantFromCatalog.ITL; variantToCreateQuery.Tenant_RefID = securityTicket.TenantID; var isVariantSaved = ORM_CMN_PRO_Product_Variant.Query.Exists(Connection, Transaction, variantToCreateQuery); ORM_CMN_PRO_Product_Variant productVariantToCreate = new ORM_CMN_PRO_Product_Variant(); if (isVariantSaved) { productVariantToCreate.Load(Connection, Transaction, ORM_CMN_PRO_Product_Variant.Query.Search(Connection, Transaction, variantToCreateQuery).FirstOrDefault().CMN_PRO_Product_VariantID); } else { productVariantToCreate.CMN_PRO_Product_VariantID = Guid.NewGuid(); } productVariantToCreate.IsStandardProductVariant = productVariantFromCatalog.DefaultVariant; productVariantToCreate.CMN_PRO_Product_RefID = productToCreateUpdate.CMN_PRO_ProductID; productVariantToCreate.IsDeleted = false; productVariantToCreate.Tenant_RefID = securityTicket.TenantID; productVariantToCreate.IsImportedFromExternalCatalog = true; productVariantToCreate.ProductVariantITL = productVariantFromCatalog.ITL; productVariantToCreate.VariantName = new Dict(ORM_CMN_PRO_Product_Variant.TableName); foreach (var lang in defaultLanguages) { productVariantToCreate.VariantName.UpdateEntry(lang.CMN_LanguageID, productVariantFromCatalog.Name); } productVariantToCreate.Save(Connection, Transaction); ORM_CMN_Price procurementPrice = new ORM_CMN_Price(); procurementPrice.CMN_PriceID = Guid.NewGuid(); procurementPrice.IsDeleted = false; procurementPrice.Tenant_RefID = securityTicket.TenantID; procurementPrice.Save(Connection, Transaction); foreach (var price in productVariantFromCatalog.PriceGrades) { ORM_CMN_Price_Value priceValues = new ORM_CMN_Price_Value(); priceValues.Price_RefID = procurementPrice.CMN_PriceID; var procurementPriceAmount = price.SalesPrice ?? 0; priceValues.PriceValue_Amount = (double)procurementPriceAmount; priceValues.PriceValue_Currency_RefID = subscribedCatalog.SubscribedCatalog_Currency_RefID; priceValues.IsDeleted = false; priceValues.Tenant_RefID = securityTicket.TenantID; priceValues.Save(Connection, Transaction); } ORM_CMN_PRO_Product_Supplier productSupplier = new ORM_CMN_PRO_Product_Supplier(); productSupplier.CMN_BPT_Supplier_RefID = supplierID; productSupplier.CMN_PRO_Product_RefID = productVariantToCreate.CMN_PRO_Product_RefID; productSupplier.CMN_PRO_Product_Variant_RefID = productVariantToCreate.CMN_PRO_Product_VariantID; productSupplier.ProcurementPrice_RefID = procurementPrice.CMN_PriceID; productSupplier.Tenant_RefID = securityTicket.TenantID; productSupplier.SupplierPriority = 0; productSupplier.IsDeleted = false; productSupplier.Save(Connection, Transaction); foreach (var dimension in productVariantFromCatalog.Dimensions) { if (dimensionsToCreate.Where(x => x.DimensionName.Contents.First().Content == dimension.Key).Count() == 0) { ORM_CMN_PRO_Dimension dimensionToCreate = new ORM_CMN_PRO_Dimension(); dimensionToCreate.DimensionName = new Dict(ORM_CMN_PRO_Dimension.TableName); foreach (var lang in defaultLanguages) { dimensionToCreate.DimensionName.AddEntry(lang.CMN_LanguageID, dimension.Key); } dimensionToCreate.OrderSequence = dimensionsToCreate.Count() + 1; dimensionToCreate.CMN_PRO_DimensionID = Guid.NewGuid(); dimensionToCreate.Product_RefID = productVariantToCreate.CMN_PRO_Product_RefID; dimensionToCreate.IsDeleted = false; dimensionToCreate.Tenant_RefID = securityTicket.TenantID; dimensionsToCreate.Add(dimensionToCreate); } var dimensionValue = dimensionValuesToCreate.Where(x => x.DimensionValue_Text.Contents.First().Content == dimension.Value); ORM_CMN_PRO_Dimension_Value dimensionValueToCreate = new ORM_CMN_PRO_Dimension_Value(); if (dimensionValue != null && dimensionValue.Count() > 0) { dimensionValueToCreate = dimensionValue.First(); } else { dimensionValueToCreate.DimensionValue_Text = new Dict(ORM_CMN_PRO_Dimension_Value.TableName); foreach (var lang in defaultLanguages) { dimensionValueToCreate.DimensionValue_Text.AddEntry(lang.CMN_LanguageID, dimension.Value); } dimensionValueToCreate.Dimensions_RefID = dimensionsToCreate.First(x => x.DimensionName.Contents.First().Content == dimension.Key).CMN_PRO_DimensionID; dimensionValueToCreate.CMN_PRO_Dimension_ValueID = Guid.NewGuid(); dimensionValueToCreate.OrderSequence = dimensionValuesToCreate.Count() + 1; dimensionValueToCreate.IsDeleted = false; dimensionValueToCreate.Tenant_RefID = securityTicket.TenantID; dimensionValuesToCreate.Add(dimensionValueToCreate); } ORM_CMN_PRO_Variant_DimensionValue variantDimensionValueToCreate = new ORM_CMN_PRO_Variant_DimensionValue(); variantDimensionValueToCreate.CMN_PRO_Variant_DimensionValueID = Guid.NewGuid(); variantDimensionValueToCreate.DimensionValue_RefID = dimensionValueToCreate.CMN_PRO_Dimension_ValueID; variantDimensionValueToCreate.ProductVariant_RefID = productVariantToCreate.CMN_PRO_Product_VariantID; variantDimensionValueToCreate.IsDeleted = false; variantDimensionValueToCreate.Tenant_RefID = securityTicket.TenantID; variantDimensionValueToCreate.Save(Connection, Transaction); } } foreach (var dimensionToCreate in dimensionsToCreate) { dimensionToCreate.Save(Connection, Transaction); } foreach (var dimensionValueToCreate in dimensionValuesToCreate) { dimensionValueToCreate.Save(Connection, Transaction); } return(returnValue); #endregion UserCode }
protected static FR_Base Execute(DbConnection Connection, DbTransaction Transaction, P_L3VA_SVfP_1019 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; } 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 }
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 }