/// <summary> /// Clones the node entry. /// </summary> /// <param name="catalogId">The catalog id.</param> /// <param name="catalogNodeId">The catalog node id.</param> /// <param name="catalogEntryId">The catalog entry id.</param> /// <param name="targetCatalogId">The target catalog id.</param> /// <param name="targetCatalogNodeId">The target catalog node id.</param> private void CloneNodeEntry(int catalogId, int catalogNodeId, int catalogEntryId, int targetCatalogId, int targetCatalogNodeId) { using (TransactionScope scope = new TransactionScope()) { CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(catalogEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); if (catalogEntryDto.CatalogEntry.Count > 0) { if (catalogId <= 0) { catalogId = catalogEntryDto.CatalogEntry[0].CatalogId; } if (targetCatalogId <= 0) { targetCatalogId = catalogId; } CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(catalogId, catalogNodeId, catalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogEntry)); CatalogAssociationDto catalogAssociationDto = CatalogContext.Current.GetCatalogAssociationDtoByEntryId(catalogEntryId); CatalogEntryDto newCatalogEntryDto = new CatalogEntryDto(); newCatalogEntryDto.CatalogEntry.ImportRow(catalogEntryDto.CatalogEntry[0]); newCatalogEntryDto.CatalogEntry[0].SetAdded(); newCatalogEntryDto.CatalogEntry[0].Code = Guid.NewGuid().ToString(); if (catalogEntryDto.CatalogItemSeo.Count > 0) { foreach (CatalogEntryDto.CatalogItemSeoRow row in catalogEntryDto.CatalogItemSeo.Rows) { newCatalogEntryDto.CatalogItemSeo.ImportRow(row); newCatalogEntryDto.CatalogItemSeo[newCatalogEntryDto.CatalogItemSeo.Count - 1].SetAdded(); newCatalogEntryDto.CatalogItemSeo[newCatalogEntryDto.CatalogItemSeo.Count - 1].Uri = Guid.NewGuid().ToString() + ".aspx"; } } if (catalogEntryDto.Variation.Count > 0) { foreach (CatalogEntryDto.VariationRow row in catalogEntryDto.Variation.Rows) { newCatalogEntryDto.Variation.ImportRow(row); newCatalogEntryDto.Variation[newCatalogEntryDto.Variation.Count - 1].SetAdded(); } } if (catalogEntryDto.SalePrice.Count > 0) { foreach (CatalogEntryDto.SalePriceRow row in catalogEntryDto.SalePrice.Rows) { CatalogEntryDto.SalePriceRow newRow = newCatalogEntryDto.SalePrice.NewSalePriceRow(); newRow.ItemArray = row.ItemArray; newRow.ItemCode = newCatalogEntryDto.CatalogEntry[0].Code; newCatalogEntryDto.SalePrice.Rows.Add(newRow); //newCatalogEntryDto.SalePrice.ImportRow(row); //newCatalogEntryDto.SalePrice[newCatalogEntryDto.SalePrice.Count - 1].ItemCode = newCatalogEntryDto.CatalogEntry[0].Code; //newCatalogEntryDto.SalePrice[newCatalogEntryDto.SalePrice.Count - 1].SetAdded(); } } if (catalogEntryDto.Inventory.Count > 0) { foreach (CatalogEntryDto.InventoryRow row in catalogEntryDto.Inventory.Rows) { newCatalogEntryDto.Inventory.ImportRow(row); newCatalogEntryDto.Inventory[newCatalogEntryDto.Inventory.Count - 1].SetAdded(); newCatalogEntryDto.Inventory[newCatalogEntryDto.Inventory.Count - 1].SkuId = newCatalogEntryDto.CatalogEntry[0].Code; } } if (newCatalogEntryDto.HasChanges()) { CatalogContext.Current.SaveCatalogEntry(newCatalogEntryDto); } if (newCatalogEntryDto.CatalogEntry.Count > 0) { CatalogEntryDto.CatalogEntryRow entry = newCatalogEntryDto.CatalogEntry[0]; int newCatalogEntryId = entry.CatalogEntryId; int metaClassId = entry.MetaClassId; // load list of MetaFields for MetaClass MetaClass metaClass = MetaClass.Load(CatalogContext.MetaDataContext, metaClassId); MetaFieldCollection metaFields = metaClass.MetaFields; // cycle through each language and get meta objects CatalogContext.MetaDataContext.UseCurrentUICulture = false; string[] languages = GetCatalogLanguages(catalogId); if (languages != null) { foreach (string language in languages) { CatalogContext.MetaDataContext.UseCurrentUICulture = false; CatalogContext.MetaDataContext.Language = language; MetaObject metaObject = MetaObject.Load(CatalogContext.MetaDataContext, catalogEntryDto.CatalogEntry[0].CatalogEntryId, metaClassId); MetaObject newMetaObject = MetaObject.NewObject(CatalogContext.MetaDataContext, newCatalogEntryId, metaClassId, FrameworkContext.Current.Profile.UserName); foreach (MetaField metaField in metaFields) { // skip system MetaFields if (!metaField.IsUser) { continue; } switch (metaField.DataType) { case MetaDataType.File: case MetaDataType.Image: case MetaDataType.ImageFile: MetaFile metaFile = (MetaFile)metaObject[metaField]; if (metaFile != null) { newMetaObject[metaField] = new MetaFile(metaFile.Name, metaFile.ContentType, metaFile.Buffer); } break; default: if (metaObject[metaField] != null) { newMetaObject[metaField] = metaObject[metaField]; } break; } } newMetaObject.AcceptChanges(CatalogContext.MetaDataContext); } } CatalogContext.MetaDataContext.UseCurrentUICulture = false; CatalogRelationDto newCatalogRelationDto = new CatalogRelationDto(); foreach (CatalogRelationDto.CatalogEntryRelationRow row in catalogRelationDto.CatalogEntryRelation.Rows) { if (row.ParentEntryId == catalogEntryId) { newCatalogRelationDto.CatalogEntryRelation.ImportRow(row); newCatalogRelationDto.CatalogEntryRelation[newCatalogRelationDto.CatalogEntryRelation.Count - 1].SetAdded(); newCatalogRelationDto.CatalogEntryRelation[newCatalogRelationDto.CatalogEntryRelation.Count - 1].ParentEntryId = newCatalogEntryId; } } if (targetCatalogNodeId > 0) { foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows) { if (row.CatalogEntryId == catalogEntryId) { newCatalogRelationDto.NodeEntryRelation.ImportRow(row); newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].SetAdded(); newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogId = targetCatalogId; newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogNodeId = targetCatalogNodeId; newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogEntryId = newCatalogEntryId; } } } if (newCatalogRelationDto.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(newCatalogRelationDto); } CatalogAssociationDto newCatalogAssociationDto = new CatalogAssociationDto(); foreach (CatalogAssociationDto.CatalogAssociationRow row in catalogAssociationDto.CatalogAssociation.Rows) { newCatalogAssociationDto.CatalogAssociation.ImportRow(row); newCatalogAssociationDto.CatalogAssociation[newCatalogAssociationDto.CatalogAssociation.Count - 1].SetAdded(); newCatalogAssociationDto.CatalogAssociation[newCatalogAssociationDto.CatalogAssociation.Count - 1].CatalogEntryId = newCatalogEntryId; } foreach (CatalogAssociationDto.CatalogEntryAssociationRow row in catalogAssociationDto.CatalogEntryAssociation.Rows) { newCatalogAssociationDto.CatalogEntryAssociation.ImportRow(row); newCatalogAssociationDto.CatalogEntryAssociation[newCatalogAssociationDto.CatalogEntryAssociation.Count - 1].SetAdded(); //newCatalogAssociationDto.CatalogEntryAssociation[newCatalogAssociationDto.CatalogEntryAssociation.Count - 1].CatalogEntryId = newCatalogEntryId; } if (newCatalogAssociationDto.HasChanges()) { CatalogContext.Current.SaveCatalogAssociation(newCatalogAssociationDto); } } } scope.Complete(); } }
protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item) { int i = 0; object objSysRowAction = Item[i++]; object objCode = Item[i++]; //Variation object objListPrice = Item[i++]; object objTaxCategoryId = Item[i++]; object objTrackInventory = Item[i++]; object objMerchantId = Item[i++]; object objWarehouseId = Item[i++]; object objWeight = Item[i++]; object objPackageId = Item[i++]; object objMinQuantity = Item[i++]; object objMaxQuantity = Item[i++]; //Inventory object objInStockQuantity = Item[i++]; object objReservedQuantity = Item[i++]; object objReorderMinQuantity = Item[i++]; object objPreorderQuantity = Item[i++]; object objBackorderQuantity = Item[i++]; object objAllowBackorder = Item[i++]; object objAllowPreorder = Item[i++]; object objInventoryStatus = Item[i++]; object objPreorderAvailabilityDate = Item[i++]; object objBackorderAvailabilityDate = Item[i++]; CatalogEntryDto.VariationRow variationRow = null; CatalogEntryDto.InventoryRow inventoryRow = null; try { RowAction sysRowAction = RowAction.Default; if (objSysRowAction != null) { sysRowAction = GetRowActionEnum((string)objSysRowAction); } string Code; if (objCode != null) { Code = (string)objCode; } else { throw new AbsentValue("Code"); } bool bVariationIsNew = false; bool bInventoryIsNew = false; CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(Code, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); if (catalogEntryDto.CatalogEntry.Count > 0) { CatalogEntryDto.CatalogEntryRow entry = catalogEntryDto.CatalogEntry[0]; if (entry.ClassTypeId.Equals(EntryType.Variation, StringComparison.OrdinalIgnoreCase) || entry.ClassTypeId.Equals(EntryType.Package, StringComparison.OrdinalIgnoreCase)) { if (catalogEntryDto.Variation.Count > 0) { if (sysRowAction == RowAction.Insert) { throw new MDPImportException(String.Format("The Variation with with Entry Code '{0}' already exists.", Code)); } variationRow = catalogEntryDto.Variation[0]; if (sysRowAction == RowAction.Delete) { variationRow.Delete(); } } else { if (sysRowAction == RowAction.Update) { throw new MDPImportException(String.Format("The Variation with with Entry Code '{0}' does not exists.", Code)); } if (sysRowAction == RowAction.Delete) { throw new MDPImportException(String.Format("The Variation with with Entry Code '{0}' does not exists.", Code)); } variationRow = catalogEntryDto.Variation.NewVariationRow(); variationRow.CatalogEntryId = entry.CatalogEntryId; variationRow.ListPrice = 0; variationRow.TaxCategoryId = 0; variationRow.TrackInventory = false; variationRow.WarehouseId = 0; variationRow.Weight = 1; variationRow.PackageId = 0; variationRow.MinQuantity = 1; variationRow.MaxQuantity = 100; bVariationIsNew = true; } if (catalogEntryDto.Inventory.Count > 0) { if (sysRowAction == RowAction.Insert) { throw new MDPImportException(String.Format("The Inventory with with Entry Code '{0}' already exists.", Code)); } inventoryRow = catalogEntryDto.Inventory[0]; if (sysRowAction == RowAction.Delete) { inventoryRow.Delete(); } } else { if (sysRowAction == RowAction.Update) { throw new MDPImportException(String.Format("The Inventory with with Entry Code '{0}' does not exists.", Code)); } if (sysRowAction == RowAction.Delete) { throw new MDPImportException(String.Format("The Inventory with with Entry Code '{0}' does not exists.", Code)); } inventoryRow = catalogEntryDto.Inventory.NewInventoryRow(); inventoryRow.ApplicationId = CatalogConfiguration.Instance.ApplicationId; inventoryRow.SkuId = entry.Code; inventoryRow.InStockQuantity = 10; inventoryRow.ReservedQuantity = 2; inventoryRow.ReorderMinQuantity = 1; inventoryRow.PreorderQuantity = 10; inventoryRow.BackorderQuantity = 10; inventoryRow.AllowBackorder = false; inventoryRow.AllowPreorder = false; inventoryRow.InventoryStatus = 0; inventoryRow.PreorderAvailabilityDate = DateTime.UtcNow; inventoryRow.BackorderAvailabilityDate = DateTime.UtcNow; bInventoryIsNew = true; } } else { throw new MDPImportException(String.Format("The Entry with code '{0}' has wrong type ('{1}') for Variation/Inventory import.", Code, entry.ClassTypeId)); } } else { throw new MDPImportException(String.Format("The Entry with code '{0}' does not exists.", Code)); } if (sysRowAction == RowAction.Delete) { CatalogContext.Current.SaveCatalogEntry(catalogEntryDto); return(0); } //Variation if (objListPrice != null) { decimal ListPrice = (decimal)objListPrice; variationRow.ListPrice = ListPrice; } if (objTaxCategoryId != null) { variationRow.TaxCategoryId = GetTaxCategoryId((string)objTaxCategoryId); } if (objTrackInventory != null) { variationRow.TrackInventory = (bool)objTrackInventory; } if (objMerchantId != null) { Guid merchantId = GetMerchantId((string)objMerchantId); if (merchantId != Guid.Empty) { variationRow.MerchantId = merchantId; } } if (objWarehouseId != null) { variationRow.WarehouseId = GetWarehouseId((string)objWarehouseId); } if (objWeight != null) { variationRow.Weight = (double)objWeight; } if (objPackageId != null) { variationRow.PackageId = GetPackageId((string)objPackageId); } if (objMinQuantity != null) { variationRow.MinQuantity = (decimal)objMinQuantity; } if (objMaxQuantity != null) { variationRow.MaxQuantity = (decimal)objMaxQuantity; } if (bVariationIsNew) { catalogEntryDto.Variation.AddVariationRow(variationRow); } //Inventory if (objInStockQuantity != null) { inventoryRow.InStockQuantity = (decimal)objInStockQuantity; } if (objReservedQuantity != null) { inventoryRow.ReservedQuantity = (decimal)objReservedQuantity; } if (objReorderMinQuantity != null) { inventoryRow.ReorderMinQuantity = (decimal)objReorderMinQuantity; } if (objPreorderQuantity != null) { inventoryRow.PreorderQuantity = (decimal)objPreorderQuantity; } if (objBackorderQuantity != null) { inventoryRow.BackorderQuantity = (decimal)objBackorderQuantity; } if (objAllowBackorder != null) { inventoryRow.AllowBackorder = (bool)objAllowBackorder; } if (objAllowPreorder != null) { inventoryRow.AllowPreorder = (bool)objAllowPreorder; } if (objInventoryStatus != null) { inventoryRow.InventoryStatus = (int)objInventoryStatus; } if (objPreorderAvailabilityDate != null) { inventoryRow.PreorderAvailabilityDate = ((DateTime)objPreorderAvailabilityDate).ToUniversalTime(); } if (objBackorderAvailabilityDate != null) { inventoryRow.BackorderAvailabilityDate = ((DateTime)objBackorderAvailabilityDate).ToUniversalTime(); } if (bInventoryIsNew) { catalogEntryDto.Inventory.AddInventoryRow(inventoryRow); } using (TransactionScope tx = new TransactionScope()) { // Save modifications if (catalogEntryDto.HasChanges()) { CatalogContext.Current.SaveCatalogEntry(catalogEntryDto); } tx.Complete(); } } catch (Exception ex) { throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item); } return(variationRow.CatalogEntryId); }
/// <summary> /// Handles the SaveChanges event of the EditSaveControl control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Mediachase.Commerce.Manager.Core.SaveControl.SaveEventArgs"/> instance containing the event data.</param> void EditSaveControl_SaveChanges(object sender, SaveControl.SaveEventArgs e) { // Validate form if (!this.Page.IsValid) { e.RunScript = false; return; } CatalogEntryDto dto = null; CatalogRelationDto relation = null; CatalogAssociationDto association = null; using (TransactionScope scope = new TransactionScope()) { if (CatalogEntryId > 0) { dto = (CatalogEntryDto)Session[_CatalogEntryDtoString]; relation = (CatalogRelationDto)Session[_CatalogRelationDtoString]; association = (CatalogAssociationDto)Session[_CatalogAssociationDtoString]; } if (association == null && CatalogEntryId > 0) { association = LoadAssociation(); } if (relation == null && CatalogEntryId > 0) { relation = LoadRelation(); } if (dto == null && CatalogEntryId > 0) { dto = LoadEntry(); } CreateEmptyDtos(ref dto, ref relation, ref association, true); // Put a dictionary key that can be used by other tabs IDictionary dic = new ListDictionary(); dic.Add(_CatalogEntryDtoString, dto); dic.Add(_CatalogRelationDtoString, relation); dic.Add(_CatalogAssociationDtoString, association); // Call tabs save ViewControl.SaveChanges(dic); // Save modifications if (dto.HasChanges()) { CatalogContext.Current.SaveCatalogEntry(dto); } // get current CatalogEntryId int currentCatalogEntryId = this.CatalogEntryId; if (dto.CatalogEntry != null && dto.CatalogEntry.Rows.Count > 0) { currentCatalogEntryId = dto.CatalogEntry[0].CatalogEntryId; } // Modify relationship CatalogRelationDto.NodeEntryRelationRow relRow = null; // Find existing row if (relation.NodeEntryRelation.Count > 0) { foreach (CatalogRelationDto.NodeEntryRelationRow row in relation.NodeEntryRelation.Rows) { if (row.CatalogEntryId == currentCatalogEntryId && row.CatalogId == ParentCatalogId && row.CatalogNodeId == ParentCatalogNodeId) { relRow = row; break; } } } // If no existing record found, create a new one if (ParentCatalogId > 0 && ParentCatalogNodeId > 0) { if (relRow == null) { relRow = relation.NodeEntryRelation.NewNodeEntryRelationRow(); } if (ParentCatalogId > 0) { relRow.CatalogId = ParentCatalogId; } if (this.ParentCatalogNodeId > 0) { relRow.CatalogNodeId = this.ParentCatalogNodeId; } relRow.CatalogEntryId = currentCatalogEntryId; // Attach if it is a new row if (relRow.RowState == DataRowState.Detached) { relRow.SortOrder = 0; relation.NodeEntryRelation.Rows.Add(relRow); } } // Update newly added entry relationships with a parent catalog entry id if (relation.CatalogEntryRelation.Rows.Count > 0) { foreach (CatalogRelationDto.CatalogEntryRelationRow row in relation.CatalogEntryRelation.Rows) { if (row.RowState == DataRowState.Added && row.ParentEntryId <= 0) { row.ParentEntryId = currentCatalogEntryId; } } } if (relation.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(relation); } // Update newly added entry relationships with a parent catalog entry id if (association.CatalogAssociation.Rows.Count > 0) { foreach (CatalogAssociationDto.CatalogAssociationRow row in association.CatalogAssociation.Rows) { if (row.RowState == DataRowState.Added && row.CatalogEntryId <= 0) { row.CatalogEntryId = currentCatalogEntryId; } } } // Save association modifications if (association.HasChanges()) { CatalogContext.Current.SaveCatalogAssociation(association); } // Call commit changes ViewControl.CommitChanges(dic); // Save modifications if (dto.HasChanges()) { CatalogContext.Current.SaveCatalogEntry(dto); } // Save relation modifications if (relation.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(relation); } // Save association modifications if (association.HasChanges()) { CatalogContext.Current.SaveCatalogAssociation(association); } // Complete transaction scope.Complete(); // we don't need to store Dto in session any more Session.Remove(_CatalogEntryDtoString); Session.Remove(_CatalogRelationDtoString); Session.Remove(_CatalogAssociationDtoString); } }
/// <summary> /// Updates static field /// </summary> /// <param name="item">The data item.</param> /// <returns></returns> private void UpdateStaticField(CatalogEntryDto.CatalogEntryRow item) { CatalogEntryDto dto = new CatalogEntryDto(); CatalogEntryDto.VariationRow[] variationRows = null; decimal decimalValue = 0; int intValue = 0; double doubleValue = 0; switch (FieldName) { case "Name": item.Name = tbItem.Text; dto.CatalogEntry.ImportRow(item); break; case "StartDate": item.StartDate = cdpItem.Value; dto.CatalogEntry.ImportRow(item); break; case "EndDate": item.EndDate = cdpItem.Value; dto.CatalogEntry.ImportRow(item); break; case "TemplateName": item.TemplateName = ddlItem.SelectedValue; dto.CatalogEntry.ImportRow(item); break; case "Code": if (item.InventoryRow != null) { CatalogEntryDto.InventoryRow inventoryRow = item.InventoryRow; inventoryRow.SkuId = tbItem.Text; dto.Inventory.ImportRow(inventoryRow); } item.Code = tbItem.Text; dto.CatalogEntry.ImportRow(item); break; case "SortOrder": intValue = -1; if (Int32.TryParse(tbItem.Text, out intValue)) { CatalogRelationDto relationDto = CatalogContext.Current.GetCatalogRelationDto(item.CatalogId, CatalogNodeId, item.CatalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry)); // Update relations foreach (CatalogRelationDto.NodeEntryRelationRow row in relationDto.NodeEntryRelation) { row.SortOrder = intValue; } if (relationDto.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(relationDto); } } break; case "IsActive": item.IsActive = becItem.IsSelected; dto.CatalogEntry.ImportRow(item); break; case "ListPrice": decimalValue = 0; if (Decimal.TryParse(tbItem.Text, out decimalValue)) { variationRows = item.GetVariationRows(); if (variationRows.Length > 0) { variationRows[0].ListPrice = decimalValue; dto.CatalogEntry.ImportRow(item); dto.Variation.ImportRow(variationRows[0]); } } break; case "TrackInventory": variationRows = item.GetVariationRows(); if (variationRows.Length > 0) { variationRows[0].TrackInventory = becItem.IsSelected; dto.CatalogEntry.ImportRow(item); dto.Variation.ImportRow(variationRows[0]); } break; case "MerchantId": if (!String.IsNullOrEmpty(ddlItem.SelectedValue)) { variationRows = item.GetVariationRows(); if (variationRows.Length > 0) { variationRows[0].MerchantId = new Guid(ddlItem.SelectedValue); dto.CatalogEntry.ImportRow(item); dto.Variation.ImportRow(variationRows[0]); } } break; case "Weight": doubleValue = 0; if (Double.TryParse(tbItem.Text, out doubleValue)) { variationRows = item.GetVariationRows(); if (variationRows.Length > 0) { variationRows[0].Weight = doubleValue; dto.CatalogEntry.ImportRow(item); dto.Variation.ImportRow(variationRows[0]); } } break; case "TaxCategoryId": case "WarehouseId": case "PackageId": if (!String.IsNullOrEmpty(ddlItem.SelectedValue)) { intValue = 0; if (Int32.TryParse(ddlItem.SelectedValue, out intValue)) { variationRows = item.GetVariationRows(); if (variationRows.Length > 0) { variationRows[0][FieldName] = intValue; dto.CatalogEntry.ImportRow(item); dto.Variation.ImportRow(variationRows[0]); } } } break; case "MinQuantity": case "MaxQuantity": decimalValue = 1; if (Decimal.TryParse(tbItem.Text, out decimalValue)) { variationRows = item.GetVariationRows(); if (variationRows.Length > 0) { variationRows[0][FieldName] = decimalValue; dto.CatalogEntry.ImportRow(item); dto.Variation.ImportRow(variationRows[0]); } } break; case "InStockQuantity": case "ReservedQuantity": case "ReorderMinQuantity": case "PreorderQuantity": case "BackorderQuantity": decimalValue = 0; if (Decimal.TryParse(tbItem.Text, out decimalValue)) { if (item.InventoryRow != null) { item.InventoryRow[FieldName] = decimalValue; dto.CatalogEntry.ImportRow(item); dto.Inventory.ImportRow(item.InventoryRow); } } break; case "AllowBackorder": case "AllowPreorder": if (item.InventoryRow != null) { item.InventoryRow[FieldName] = becItem.IsSelected; dto.CatalogEntry.ImportRow(item); dto.Inventory.ImportRow(item.InventoryRow); } break; case "InventoryStatus": if (!String.IsNullOrEmpty(ddlItem.SelectedValue)) { intValue = 0; if (Int32.TryParse(ddlItem.SelectedValue, out intValue)) { if (item.InventoryRow != null) { item.InventoryRow[FieldName] = intValue; dto.CatalogEntry.ImportRow(item); dto.Inventory.ImportRow(item.InventoryRow); } } } break; case "PreorderAvailabilityDate": case "BackorderAvailabilityDate": if (item.InventoryRow != null) { item.InventoryRow[FieldName] = cdpItem.Value; dto.CatalogEntry.ImportRow(item); dto.Inventory.ImportRow(item.InventoryRow); } break; } if (dto.HasChanges()) { CatalogContext.Current.SaveCatalogEntry(dto); } }
protected override int CreateSystemRow(FillDataMode mode, int RowIndex, params object[] item) { int i = 0; object objSysRowAction = item[i++]; //Entry object objCode = item[i++]; object objName = item[i++]; object objClassTypeId = item[i++]; object objStartDate = item[i++]; object objEndDate = item[i++]; object objTemplateName = item[i++]; object objIsActive = item[i++]; object objCategoryCodes = item[i++]; object objSortOrder = item[i++]; //SEO object objSeoTitle = item[i++]; object objSeoUrl = item[i++]; object objSeoDescription = item[i++]; object objSeoKeywords = item[i++]; CatalogEntryDto.CatalogEntryRow entryRow = null; try { RowAction sysRowAction = RowAction.Default; if (objSysRowAction != null) { sysRowAction = GetRowActionEnum((string)objSysRowAction); } string code; if (objCode != null) { code = (string)objCode; } else { throw new AbsentValue("Code"); } bool bIsNew = false; CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(code, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); if (catalogEntryDto.CatalogEntry.Count > 0) { if (sysRowAction == RowAction.Insert) { throw new MDPImportException(String.Format("The Entry with code '{0}' already exists.", code)); } entryRow = catalogEntryDto.CatalogEntry[0]; if (sysRowAction == RowAction.Delete) { CatalogContext.Current.DeleteCatalogEntry(entryRow.CatalogEntryId, true); return(0); } } else { if (sysRowAction == RowAction.Update) { throw new MDPImportException(String.Format("The Entry with code '{0}' does not exists.", code)); } if (sysRowAction == RowAction.Delete) { throw new MDPImportException(String.Format("The Entry with code '{0}' does not exists.", code)); } entryRow = catalogEntryDto.CatalogEntry.NewCatalogEntryRow(); entryRow.ApplicationId = CatalogConfiguration.Instance.ApplicationId; entryRow.CatalogId = _CatalogId; entryRow.Code = code; bIsNew = true; } //Entry if (objName != null) { string Name = (string)objName; entryRow.Name = Name; } else if (bIsNew) { throw new AbsentValue("Name"); } if (objClassTypeId != null) { string classTypeId = (string)objClassTypeId; entryRow.ClassTypeId = classTypeId; } else if (bIsNew) { entryRow.ClassTypeId = EntryType.Product; } if (objStartDate != null) { DateTime startDate = (DateTime)objStartDate; entryRow.StartDate = startDate.ToUniversalTime(); } else if (bIsNew) { entryRow.StartDate = DateTime.UtcNow; } if (objEndDate != null) { DateTime endDate = (DateTime)objEndDate; entryRow.EndDate = endDate.ToUniversalTime(); } else if (bIsNew) { entryRow.EndDate = DateTime.UtcNow.AddYears(1); } if (objTemplateName != null) { string templateName = (string)objTemplateName; entryRow.TemplateName = templateName; } else if (bIsNew) { entryRow.TemplateName = String.Empty; } if (objIsActive != null) { bool IsActive = (bool)objIsActive; entryRow.IsActive = IsActive; } else if (bIsNew) { entryRow.IsActive = false; } int oldMetaClassId = 0; if (!_isSystemClass && _metaClassId > 0) { if (!bIsNew) { oldMetaClassId = entryRow.MetaClassId; } entryRow.MetaClassId = _metaClassId; } else if (bIsNew) { throw new MDPImportException("The new entry cannot be created without metaclass definition."); } if (bIsNew) { catalogEntryDto.CatalogEntry.AddCatalogEntryRow(entryRow); } else { entryRow.SerializedData = null; } //SEO CatalogEntryDto.CatalogItemSeoRow catalogItemSeoRow = null; bool bSeoIsNew = false; if (!String.IsNullOrEmpty(this.Context.Language)) { if (catalogEntryDto.CatalogItemSeo.Count > 0) { DataRow[] drs = catalogEntryDto.CatalogItemSeo.Select(String.Format("LanguageCode LIKE '{0}' AND CatalogEntryId = {1}", this.Context.Language, entryRow.CatalogEntryId)); if (drs.Length > 0) { catalogItemSeoRow = (CatalogEntryDto.CatalogItemSeoRow)drs[0]; } } if (catalogItemSeoRow == null) { catalogItemSeoRow = catalogEntryDto.CatalogItemSeo.NewCatalogItemSeoRow(); catalogItemSeoRow.ApplicationId = CatalogConfiguration.Instance.ApplicationId; catalogItemSeoRow.LanguageCode = this.Context.Language.ToLower(); catalogItemSeoRow.CatalogEntryId = entryRow.CatalogEntryId; bSeoIsNew = true; } if (objSeoTitle != null) { catalogItemSeoRow.Title = (string)objSeoTitle; } if (objSeoUrl != null) { catalogItemSeoRow.Uri = (string)objSeoUrl; } else if (bSeoIsNew) { // Auto generate the URL if empty string name = catalogEntryDto.CatalogEntry.Count > 0 ? catalogEntryDto.CatalogEntry[0].Name : ""; string url = String.Format("{0}.aspx", CommerceHelper.CleanUrlField(name)); int index = 1; while (CatalogContext.Current.GetCatalogEntryByUriDto(url, this.Context.Language).CatalogEntry.Count != 0 || CatalogContext.Current.GetCatalogNodeDto(url, this.Context.Language).CatalogNode.Count != 0) { url = String.Format("{0}-{1}.aspx", CommerceHelper.CleanUrlField(name), index.ToString()); index++; } catalogItemSeoRow.Uri = url; } if (objSeoDescription != null) { catalogItemSeoRow.Description = (string)objSeoDescription; } if (objSeoKeywords != null) { catalogItemSeoRow.Keywords = (string)objSeoKeywords; } if (bSeoIsNew) { catalogEntryDto.CatalogItemSeo.AddCatalogItemSeoRow(catalogItemSeoRow); } } using (TransactionScope tx = new TransactionScope()) { // Save modifications if (catalogEntryDto.HasChanges()) { CatalogContext.Current.SaveCatalogEntry(catalogEntryDto); } int sortOrder = -1; if (objSortOrder != null) { sortOrder = (int)objSortOrder; } if (objCategoryCodes != null) { //NodeEntryRelation string[] categoryCodes = ((string)objCategoryCodes).Split(','); Catalog.Dto.CatalogRelationDto catalogRelationDto = FrameworkContext.Current.CatalogSystem.GetCatalogRelationDto(this._CatalogId, 0, entryRow.CatalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry)); Catalog.Dto.CatalogNodeDto catalogNodeDto = FrameworkContext.Current.CatalogSystem.GetCatalogNodesDto(this._CatalogId); if (catalogNodeDto.CatalogNode.Count > 0) { //remove product from category if (catalogRelationDto.NodeEntryRelation.Count > 0) { foreach (CatalogRelationDto.NodeEntryRelationRow nodeEntryRelationRow in catalogRelationDto.NodeEntryRelation) { DataRow[] catalogNodeDataRows = catalogNodeDto.CatalogNode.Select(String.Format("CatalogNodeId = {0}", nodeEntryRelationRow.CatalogNodeId)); if (catalogNodeDataRows.Length > 0) { Catalog.Dto.CatalogNodeDto.CatalogNodeRow catalogNode = (Catalog.Dto.CatalogNodeDto.CatalogNodeRow)catalogNodeDataRows[0]; bool bExist = false; foreach (string categoryCode in categoryCodes) { if (catalogNode.Code.Equals(categoryCode)) { if (sortOrder >= 0) { nodeEntryRelationRow.SortOrder = sortOrder; } bExist = true; break; } } if (!bExist) { nodeEntryRelationRow.Delete(); } } } } //add entry to category foreach (string categoryCode in categoryCodes) { DataRow[] catalogNodeDataRows = catalogNodeDto.CatalogNode.Select(String.Format("Code = '{0}'", categoryCode.Replace("'", "''"))); if (catalogNodeDataRows.Length > 0) { Catalog.Dto.CatalogNodeDto.CatalogNodeRow catalogNode = (Catalog.Dto.CatalogNodeDto.CatalogNodeRow)catalogNodeDataRows[0]; DataRow[] nodeEntryRelationDataRows = catalogRelationDto.NodeEntryRelation.Select(String.Format("CatalogNodeId = {0}", catalogNode.CatalogNodeId)); if (nodeEntryRelationDataRows.Length == 0) { Catalog.Dto.CatalogRelationDto.NodeEntryRelationRow row = catalogRelationDto.NodeEntryRelation.NewNodeEntryRelationRow(); row.CatalogId = this._CatalogId; row.CatalogEntryId = entryRow.CatalogEntryId; row.CatalogNodeId = catalogNode.CatalogNodeId; if (sortOrder >= 0) { row.SortOrder = sortOrder; } else { row.SortOrder = 0; } catalogRelationDto.NodeEntryRelation.AddNodeEntryRelationRow(row); } } } } if (catalogRelationDto.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto); } } if (!bIsNew && !_isSystemClass && oldMetaClassId != entryRow.MetaClassId) { MetaObject.Delete(this.Context, entryRow.CatalogEntryId, oldMetaClassId); MetaObject obj = MetaObject.NewObject(this.Context, entryRow.CatalogEntryId, entryRow.MetaClassId); obj.AcceptChanges(this.Context); } tx.Complete(); } } catch (Exception ex) { throw new MDPImportException(ex.Message, null, RowIndex, null, null, item); } return(entryRow.CatalogEntryId); }
/// <summary> /// Creates the system row. /// </summary> /// <param name="Mode">The mode.</param> /// <param name="RowIndex">Index of the row.</param> /// <param name="Item">The item.</param> /// <returns></returns> protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item) { int i = 0; object objSysRowAction = Item[i++]; object objCode = Item[i++]; //SaleType object objSaleType = Item[i++]; object objSaleCode = Item[i++]; object objUnitPrice = Item[i++]; object objCurrency = Item[i++]; object objMinQuantity = Item[i++]; object objStartDate = Item[i++]; object objEndDate = Item[i++]; int salePriceId = 0; CatalogEntryDto.SalePriceRow newSalePriceRow = null; try { RowAction sysRowAction = RowAction.Default; if (objSysRowAction != null) { sysRowAction = GetRowActionEnum((string)objSysRowAction); } string Code; if (objCode != null) { Code = (string)objCode; } else { throw new AbsentValue("Code"); } bool bSalePriceIsNew = false; CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(Code, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); if (catalogEntryDto.CatalogEntry.Count > 0) { CatalogEntryDto.CatalogEntryRow entry = catalogEntryDto.CatalogEntry[0]; if (entry.ClassTypeId.Equals(EntryType.Variation, StringComparison.OrdinalIgnoreCase) || entry.ClassTypeId.Equals(EntryType.Package, StringComparison.OrdinalIgnoreCase)) { if (catalogEntryDto.SalePrice.Count == 0) { if (sysRowAction == RowAction.Update) { throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' does not exists.", Code)); } if (sysRowAction == RowAction.Delete) { throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' does not exists.", Code)); } bSalePriceIsNew = true; } newSalePriceRow = catalogEntryDto.SalePrice.NewSalePriceRow(); newSalePriceRow.ItemCode = entry.Code; newSalePriceRow.SaleType = 0; newSalePriceRow.SaleCode = String.Empty; newSalePriceRow.UnitPrice = 0; newSalePriceRow.Currency = GetCatalogDefaultCurrency(); newSalePriceRow.MinQuantity = 0; newSalePriceRow.StartDate = DateTime.UtcNow; newSalePriceRow.EndDate = DateTime.UtcNow.AddMonths(1); } else { throw new MDPImportException(String.Format("The Entry with code '{0}' has wrong type ('{1}') for Variation/Inventory import.", Code, entry.ClassTypeId)); } } else { throw new MDPImportException(String.Format("The Entry with code '{0}' does not exists.", Code)); } //SalePrice if (objSaleType != null) { newSalePriceRow.SaleType = (int)GetSaleTypeId((string)objSaleType); } if (objSaleCode != null) { newSalePriceRow.SaleCode = (string)objSaleCode; } if (objUnitPrice != null) { newSalePriceRow.UnitPrice = (decimal)objUnitPrice; } if (objCurrency != null) { newSalePriceRow.Currency = GetCurrencyCode((string)objCurrency); } if (objMinQuantity != null) { newSalePriceRow.MinQuantity = (decimal)objMinQuantity; } if (objStartDate != null) { newSalePriceRow.StartDate = ((DateTime)objStartDate).ToUniversalTime(); } if (objEndDate != null) { newSalePriceRow.EndDate = ((DateTime)objEndDate).ToUniversalTime(); } if (bSalePriceIsNew) { catalogEntryDto.SalePrice.AddSalePriceRow(newSalePriceRow); } else { IEnumerable <int> result = from SalePriceTable in catalogEntryDto.SalePrice where SalePriceTable.SaleType == newSalePriceRow.SaleType && SalePriceTable.SaleCode == newSalePriceRow.SaleCode && SalePriceTable.Currency == newSalePriceRow.Currency && SalePriceTable.StartDate == newSalePriceRow.StartDate && SalePriceTable.EndDate == newSalePriceRow.EndDate select SalePriceTable.SalePriceId; if (result.Count() == 0) { if (sysRowAction == RowAction.Update) { throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' does not exists.", Code)); } if (sysRowAction == RowAction.Delete) { throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' does not exists.", Code)); } catalogEntryDto.SalePrice.AddSalePriceRow(newSalePriceRow); } else { if (sysRowAction == RowAction.Insert) { throw new MDPImportException(String.Format("The Sales Price for Entry code '{0}' already exists.", Code)); } CatalogEntryDto.SalePriceRow salePriceRow = catalogEntryDto.SalePrice.FindBySalePriceId(result.First()); if (sysRowAction == RowAction.Delete) { salePriceRow.Delete(); } if (sysRowAction == RowAction.Update) { salePriceId = salePriceRow.SalePriceId; salePriceRow.UnitPrice = newSalePriceRow.UnitPrice; salePriceRow.MinQuantity = newSalePriceRow.MinQuantity; } } } using (TransactionScope tx = new TransactionScope()) { // Save modifications if (catalogEntryDto.HasChanges()) { CatalogContext.Current.SaveCatalogEntry(catalogEntryDto); } tx.Complete(); } } catch (Exception ex) { throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item); } return(salePriceId); }