protected override int CreateSystemRow(FillDataMode mode, params object[] item) { if (mode == FillDataMode.Update) { throw new NotSupportedException("Update is not supported for Incident import"); } string Description = ""; string Resolution = ""; string Workaround = ""; string Title = "Imported incident " + DateTime.Now.ToString("d"); DateTime CreationDate = DateTime.UtcNow; int PriorityId = int.Parse(PortalConfig.IncidentDefaultValuePriorityField); int TypeId = int.Parse(PortalConfig.IncidentDefaultValueTypeField); int SeverityId = int.Parse(PortalConfig.IncidentDefaultValueSeverityField); ; if (item[0] != null) Title = (string)item[0]; if (item[2] != null) CreationDate = DBCommon.GetUTCDate(Security.CurrentUser.TimeZoneId, (DateTime)item[2]); if (item[1] != null) Description = (string)item[1]; if (item[6] != null) Resolution = (string)item[6]; if (item[7] != null) Workaround = item[7].ToString(); if (item[3] != null) PriorityId = GetPriorityId((string)item[3]); if (item[4] != null) TypeId = GetTypeId((string)item[4]); if (item[5] != null) SeverityId = GetSeverityId((string)item[5]); int IncidentId = Incident.Create(Title, Description, TypeId, PriorityId, SeverityId, Security.CurrentUser.UserID, CreationDate); //Issue2.UpdateResolutionInfo(IncidentId, Resolution, Workaround); return IncidentId; }
public virtual FillResult FillData(FillDataMode mode, DataTable rawData, Rule rule, int modifierId, DateTime modified, int maximumErrors) { MetaDataContext.Current.BeginTransaction(); try { FillResult retVal = FillData(mode, rawData, rule, modifierId, modified); if (maximumErrors == -1) { MetaDataContext.Current.Commit(); } else if (retVal.ErrorRows <= maximumErrors) { MetaDataContext.Current.Commit(); } else { MetaDataContext.Current.Rollback(); } return(retVal); } catch { MetaDataContext.Current.Rollback(); throw; } }
public virtual FillResult FillData(FillDataMode mode, DataTable rawData, Rule rule, int modifierId, DateTime modified) { if (rawData == null) { throw new ArgumentNullException("rawData"); } FillResult retVal = new FillResult(rawData.Rows.Count); Validate(rule, rawData); int RowIndex = 0; foreach (DataRow Row in rawData.Rows) { try { int ObjectId = CreateSystemRow(mode, FillItemList(SystemColumnInfos, Row, RowIndex, rule, retVal.warningList)); if (UserColumnInfos.Length != 0) { MetaObject Object = MetaObject.Load(ObjectId, _innerMetaClassName, modifierId, modified); if (Object == null) { Object = MetaObject.NewObject(ObjectId, _innerMetaClassName, modifierId, modified); } CreateUserRow(Object, rule, FillItemList(UserColumnInfos, Row, RowIndex, rule, retVal.warningList)); Object.AcceptChanges(); } else if (ObjectId == -1) { throw new IdleOperationException(); } retVal.SuccessfulRow(); } catch (AlreadyExistException) { } catch (MdpImportException ex) { retVal.ErrorRow(); ex.setRowInfo(Row, RowIndex); retVal.ErrorException(ex); } catch (Exception ex) { retVal.ErrorRow(); retVal.ErrorException(ex); } RowIndex++; } return(retVal); }
protected override int CreateSystemRow(FillDataMode mode, params object[] item) { if (mode == FillDataMode.Update) { throw new NotSupportedException("Update is not supported for Incident import"); } string Description = ""; string Resolution = ""; string Workaround = ""; string Title = "Imported incident " + DateTime.Now.ToString("d"); DateTime CreationDate = DateTime.UtcNow; int PriorityId = int.Parse(PortalConfig.IncidentDefaultValuePriorityField); int TypeId = int.Parse(PortalConfig.IncidentDefaultValueTypeField); int SeverityId = int.Parse(PortalConfig.IncidentDefaultValueSeverityField);; if (item[0] != null) { Title = (string)item[0]; } if (item[2] != null) { CreationDate = DBCommon.GetUTCDate(Security.CurrentUser.TimeZoneId, (DateTime)item[2]); } if (item[1] != null) { Description = (string)item[1]; } if (item[6] != null) { Resolution = (string)item[6]; } if (item[7] != null) { Workaround = item[7].ToString(); } if (item[3] != null) { PriorityId = GetPriorityId((string)item[3]); } if (item[4] != null) { TypeId = GetTypeId((string)item[4]); } if (item[5] != null) { SeverityId = GetSeverityId((string)item[5]); } int IncidentId = Incident.Create(Title, Description, TypeId, PriorityId, SeverityId, Security.CurrentUser.UserID, CreationDate); //Issue2.UpdateResolutionInfo(IncidentId, Resolution, Workaround); return(IncidentId); }
public FillResult FillData(FillDataMode mode, DataTable rawData, Mediachase.MetaDataPlus.Import.Rule rule, int maximumErrors) { using (DbTransaction tran = DbTransaction.Begin()) { FillResult retVal = FillData(mode, rawData, rule, Security.CurrentUser.UserID, DateTime.UtcNow, DbContext.Current.Transaction); if (maximumErrors == -1 || retVal.ErrorRows <= maximumErrors) tran.Commit(); else tran.Rollback(); return retVal; } }
public virtual FillResult FillData(FillDataMode mode, DataTable rawData, Rule rule, int modifierId, DateTime modified, SqlTransaction tran) { MetaDataContext.Current.Transaction = tran; FillResult retVal = null; try { retVal = FillData(mode, rawData, rule, modifierId, modified); } finally { MetaDataContext.Current.Transaction = null; } return(retVal); }
protected override int CreateSystemRow(FillDataMode mode, params object[] item) { if (mode == FillDataMode.Update) { throw new NotSupportedException("Update is not supported for User import"); } string Login = ""; string Password = ""; string FirstName = ""; string LastName = ""; string Email = ""; string Phone = ""; string Fax = ""; string Mobile = ""; string Company = ""; string JobTitle = ""; string Department = ""; string Location = ""; if (item[0] == null || (string)item[0] == "") throw new EmptyFieldException("Login"); else Login = (string)item[0]; if (item[1] == null || (string)item[2] == "") throw new EmptyFieldException("FirstName"); else FirstName = (string)item[2]; if (item[2] == null || (string)item[3] == "") throw new EmptyFieldException("LastName"); else LastName = (string)item[3]; if (item[3] == null || (string)item[1] == "") throw new EmptyFieldException("Password"); else Password = (string)item[1]; if (item[4] != null) Email = (string)item[4]; if (item[5] != null) Phone = (string)item[5]; if (item[6] != null) Fax = (string)item[6]; if (item[7] != null) Mobile = (string)item[7]; if (item[8] != null) Company = (string)item[8]; if (item[9] != null) JobTitle = (string)item[9]; if (item[10] != null) Department = (string)item[10]; if (item[11] != null) Location = (string)item[11]; //TODO: IMGroupId?, LanguageId? int UserId = User.Create(Login, Password, FirstName, LastName, Email, true, null, 0, Phone, Fax, Mobile, JobTitle, Department, Company, Location, User.DefaultTimeZoneId, 1, null, null, -1); return UserId; }
public FillResult FillData(FillDataMode mode, DataTable rawData, Mediachase.MetaDataPlus.Import.Rule rule, int maximumErrors) { using (DbTransaction tran = DbTransaction.Begin()) { FillResult retVal = FillData(mode, rawData, rule, Security.CurrentUser.UserID, DateTime.UtcNow, DbContext.Current.Transaction); if (maximumErrors == -1 || retVal.ErrorRows <= maximumErrors) { tran.Commit(); } else { tran.Rollback(); } return(retVal); } }
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); }
protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item) { int i = 0; object objSysRowAction = Item[i++]; //CatalogNode object objCode = Item[i++]; object objParentCode = Item[i++]; object objName = Item[i++]; object objStartDate = Item[i++]; object objEndDate = Item[i++]; object objTemplateName = Item[i++]; object objIsActive = Item[i++]; object objSortOrder = Item[i++]; //SEO object objSeoTitle = Item[i++]; object objSeoUrl = Item[i++]; object objSeoDescription = Item[i++]; object objSeoKeywords = Item[i++]; CatalogNodeDto.CatalogNodeRow nodeRow = null; try { RowAction sysRowAction = RowAction.Default; if (objSysRowAction != null) { sysRowAction = GetRowActionEnum((string)objSysRowAction); } string Code; if (!String.IsNullOrEmpty((string)objCode)) { Code = (string)objCode; } else { throw new AbsentValue("Code"); } int parentNodeId = 0; if (objParentCode != null) { if (!objParentCode.Equals(String.Empty)) { CatalogNodeDto parentNodeDto = CatalogNodeManager.GetCatalogNodeDto((string)objParentCode, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeInfo)); if (parentNodeDto.CatalogNode.Count > 0) { parentNodeId = parentNodeDto.CatalogNode[0].CatalogNodeId; } } } bool bIsNew = false; CatalogNodeDto catalogNodeDto = CatalogNodeManager.GetCatalogNodeDto(Code, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeFull)); if (catalogNodeDto.CatalogNode.Count > 0) { if (sysRowAction == RowAction.Insert) { throw new MDPImportException(String.Format("The Catalog Node with Code '{0}' already exists.", Code)); } nodeRow = catalogNodeDto.CatalogNode[0]; if (sysRowAction == RowAction.Delete) { CatalogContext.Current.DeleteCatalogNode(nodeRow.CatalogNodeId, nodeRow.CatalogId); return(0); } if (objParentCode != null && parentNodeId > -1) { nodeRow.ParentNodeId = parentNodeId; } } else { if (sysRowAction == RowAction.Update) { throw new MDPImportException(String.Format("The Catalog Node with code '{0}' does not exists.", Code)); } if (sysRowAction == RowAction.Delete) { throw new MDPImportException(String.Format("The Catalog Node with code '{0}' does not exists.", Code)); } nodeRow = catalogNodeDto.CatalogNode.NewCatalogNodeRow(); nodeRow.ApplicationId = CatalogConfiguration.Instance.ApplicationId; nodeRow.CatalogId = _CatalogId; nodeRow.Code = Code; nodeRow.ParentNodeId = parentNodeId; nodeRow.Name = String.Empty; nodeRow.StartDate = DateTime.UtcNow; nodeRow.EndDate = DateTime.UtcNow.AddYears(3); nodeRow.TemplateName = String.Empty; nodeRow.IsActive = false; nodeRow.SortOrder = 0; bIsNew = true; } if (objName != null) { nodeRow.Name = (string)objName; } if (objStartDate != null) { nodeRow.StartDate = ((DateTime)objStartDate).ToUniversalTime(); } if (objEndDate != null) { nodeRow.EndDate = ((DateTime)objEndDate).ToUniversalTime(); } if (objTemplateName != null) { nodeRow.TemplateName = (string)objTemplateName; } if (objIsActive != null) { nodeRow.IsActive = (bool)objIsActive; } if (objSortOrder != null) { nodeRow.SortOrder = (int)objSortOrder; } int oldMetaClassId = 0; if (!_isSystemClass && _metaClassId > 0) { if (!bIsNew) { oldMetaClassId = nodeRow.MetaClassId; } nodeRow.MetaClassId = _metaClassId; } else if (bIsNew) { throw new MDPImportException("The new category cannot be created without metaclass definition."); } if (bIsNew) { catalogNodeDto.CatalogNode.AddCatalogNodeRow(nodeRow); } //SEO CatalogNodeDto.CatalogItemSeoRow catalogItemSeoRow = null; bool bSeoIsNew = false; if (!String.IsNullOrEmpty(this.Context.Language)) { if (catalogNodeDto.CatalogItemSeo.Count > 0) { DataRow[] drs = catalogNodeDto.CatalogItemSeo.Select(String.Format("LanguageCode LIKE '{0}' AND CatalogNodeId = {1}", this.Context.Language, nodeRow.CatalogNodeId)); if (drs.Length > 0) { catalogItemSeoRow = (CatalogNodeDto.CatalogItemSeoRow)drs[0]; } } if (catalogItemSeoRow == null) { catalogItemSeoRow = catalogNodeDto.CatalogItemSeo.NewCatalogItemSeoRow(); catalogItemSeoRow.ApplicationId = CatalogConfiguration.Instance.ApplicationId; catalogItemSeoRow.LanguageCode = this.Context.Language.ToLower(); catalogItemSeoRow.CatalogNodeId = nodeRow.CatalogNodeId; catalogItemSeoRow.Description = String.Empty; catalogItemSeoRow.Keywords = String.Empty; 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 = catalogNodeDto.CatalogNode[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) { catalogNodeDto.CatalogItemSeo.AddCatalogItemSeoRow(catalogItemSeoRow); } } using (TransactionScope tx = new TransactionScope()) { // Save modifications if (catalogNodeDto.HasChanges()) { CatalogContext.Current.SaveCatalogNode(catalogNodeDto); } if (!bIsNew && !_isSystemClass && oldMetaClassId != nodeRow.MetaClassId) { MetaObject.Delete(this.Context, nodeRow.CatalogNodeId, oldMetaClassId); MetaObject obj = MetaObject.NewObject(this.Context, nodeRow.CatalogNodeId, nodeRow.MetaClassId); obj.AcceptChanges(this.Context); } tx.Complete(); } } catch (Exception ex) { throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item); } return(nodeRow.CatalogNodeId); }
protected virtual int CreateSystemRow(FillDataMode mode, params object[] items) { return -1; }
public virtual FillResult FillData(FillDataMode mode, DataTable rawData, Rule rule, int modifierId, DateTime modified, int maximumErrors) { MetaDataContext.Current.BeginTransaction(); try { FillResult retVal = FillData(mode, rawData, rule, modifierId, modified); if (maximumErrors == -1) MetaDataContext.Current.Commit(); else if (retVal.ErrorRows <= maximumErrors) MetaDataContext.Current.Commit(); else MetaDataContext.Current.Rollback(); return retVal; } catch { MetaDataContext.Current.Rollback(); throw; } }
public virtual FillResult FillData(FillDataMode mode, DataTable rawData, Rule rule, int modifierId, DateTime modified, SqlTransaction tran) { MetaDataContext.Current.Transaction = tran; FillResult retVal = null; try { retVal = FillData(mode, rawData, rule, modifierId, modified); } finally { MetaDataContext.Current.Transaction = null; } return retVal; }
public virtual FillResult FillData(FillDataMode mode, DataTable rawData, Rule rule, SqlTransaction tran) { return FillData(mode, rawData, rule, -1, DateTime.Now, tran); }
public virtual FillResult FillData(FillDataMode mode, DataTable rawData, Rule rule, int modifierId, DateTime modified) { if (rawData == null) throw new ArgumentNullException("rawData"); FillResult retVal = new FillResult(rawData.Rows.Count); Validate(rule, rawData); int RowIndex = 0; foreach (DataRow Row in rawData.Rows) { try { int ObjectId = CreateSystemRow(mode, FillItemList(SystemColumnInfos, Row, RowIndex, rule, retVal.warningList)); if (UserColumnInfos.Length != 0) { MetaObject Object = MetaObject.Load(ObjectId, _innerMetaClassName, modifierId, modified); if (Object == null) { Object = MetaObject.NewObject(ObjectId, _innerMetaClassName, modifierId, modified); } CreateUserRow(Object, rule, FillItemList(UserColumnInfos, Row, RowIndex, rule, retVal.warningList)); Object.AcceptChanges(); } else if (ObjectId == -1) throw new IdleOperationException(); retVal.SuccessfulRow(); } catch (AlreadyExistException) { } catch (MdpImportException ex) { retVal.ErrorRow(); ex.setRowInfo(Row, RowIndex); retVal.ErrorException(ex); } catch (Exception ex) { retVal.ErrorRow(); retVal.ErrorException(ex); } RowIndex++; } return retVal; }
public virtual FillResult FillData(FillDataMode mode, DataTable rawData, Rule rule) { return FillData(mode, rawData, rule, -1, DateTime.Now); }
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); }
protected virtual int CreateSystemRow(FillDataMode mode, params object[] items) { return(-1); }
protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item) { int i = 0; object objSysRowAction = Item[i++]; object objAssociationName = Item[i++]; object objParentCode = Item[i++]; object objChildCode = Item[i++]; object objSortOrder = Item[i++]; object objAssociationType = Item[i++]; try { RowAction sysRowAction = RowAction.Default; if (objSysRowAction != null) { sysRowAction = GetRowActionEnum((string)objSysRowAction); } string AssociationName; if (!String.IsNullOrEmpty((string)objAssociationName)) { AssociationName = (string)objAssociationName; } else { throw new AbsentValue("Association Name"); } string parentCode; if (!String.IsNullOrEmpty((string)objParentCode)) { parentCode = (string)objParentCode; } else { throw new AbsentValue("Parent Entry Code"); } string childCode; if (!String.IsNullOrEmpty((string)objChildCode)) { childCode = (string)objChildCode; } else { throw new AbsentValue("Child Entry Code"); } bool bIsNew = false; //Parent Entry CatalogEntryDto.CatalogEntryRow parentEntryRow = null; CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(parentCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.Associations)); if (catalogEntryDto.CatalogEntry.Count > 0) { parentEntryRow = catalogEntryDto.CatalogEntry[0]; } else { throw new MDPImportException(String.Format("The Parent Entry with code '{0}' does not exists.", parentCode)); } //Child Entry CatalogEntryDto.CatalogEntryRow childEntryRow = null; CatalogEntryDto childEntryDto = CatalogEntryManager.GetCatalogEntryDto(childCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo)); if (childEntryDto.CatalogEntry.Count > 0) { childEntryRow = childEntryDto.CatalogEntry[0]; } else { throw new MDPImportException(String.Format("The Child Entry with code '{0}' does not exists.", childCode)); } //CatalogAssociation (define CatalogAssociationId) int catalogAssociationId = 0; CatalogEntryDto.CatalogAssociationRow[] catalogAssociationRows = (CatalogEntryDto.CatalogAssociationRow[])catalogEntryDto.CatalogAssociation.Select(String.Format("AssociationName = '{0}'", AssociationName)); if (catalogAssociationRows.Length == 0) { CatalogEntryDto.CatalogAssociationRow newCatalogAssociationRow = catalogEntryDto.CatalogAssociation.NewCatalogAssociationRow(); newCatalogAssociationRow.CatalogEntryId = parentEntryRow.CatalogEntryId; newCatalogAssociationRow.AssociationName = AssociationName; newCatalogAssociationRow.AssociationDescription = String.Empty; newCatalogAssociationRow.SortOrder = 0; catalogEntryDto.CatalogAssociation.AddCatalogAssociationRow(newCatalogAssociationRow); CatalogContext.Current.SaveCatalogEntry(catalogEntryDto); catalogAssociationId = newCatalogAssociationRow.CatalogAssociationId; } else { catalogAssociationId = catalogAssociationRows[0].CatalogAssociationId; } //catalogEntryAssociationRow CatalogAssociationDto catalogAssociationDto = CatalogAssociationManager.GetCatalogAssociationDto(catalogAssociationId); CatalogAssociationDto.CatalogAssociationRow catalogAssociationRow = catalogAssociationDto.CatalogAssociation[0]; CatalogAssociationDto.CatalogEntryAssociationRow catalogEntryAssociationRow = null; CatalogAssociationDto.CatalogEntryAssociationRow[] catalogEntryAssociationRows = (CatalogAssociationDto.CatalogEntryAssociationRow[])catalogAssociationDto.CatalogEntryAssociation.Select(String.Format("CatalogEntryId = {0}", childEntryRow.CatalogEntryId)); if (catalogEntryAssociationRows.Length == 0) { if (sysRowAction == RowAction.Update) { throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' does not exists.", AssociationName, parentCode, childCode)); } if (sysRowAction == RowAction.Delete) { throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' does not exists.", AssociationName, parentCode, childCode)); } catalogEntryAssociationRow = catalogAssociationDto.CatalogEntryAssociation.NewCatalogEntryAssociationRow(); catalogEntryAssociationRow.CatalogAssociationId = catalogAssociationId; catalogEntryAssociationRow.CatalogEntryId = childEntryRow.CatalogEntryId; catalogEntryAssociationRow.SortOrder = 0; if (catalogAssociationDto.AssociationType.Count > 0) { catalogEntryAssociationRow.AssociationTypeId = catalogAssociationDto.AssociationType[0].AssociationTypeId; } bIsNew = true; } else { if (sysRowAction == RowAction.Insert) { throw new MDPImportException(String.Format("The Catalog Entry Association with name '{0}' for entry code '{1}' and child code '{2}' already exists.", AssociationName, parentCode, childCode)); } catalogEntryAssociationRow = catalogEntryAssociationRows[0]; if (sysRowAction == RowAction.Delete) { catalogEntryAssociationRow.Delete(); CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto); return(0); } } if (objSortOrder != null) { catalogEntryAssociationRow.SortOrder = (int)objSortOrder; } if (objAssociationType != null) { string associationType = (string)objAssociationType; if (!catalogEntryAssociationRow.AssociationTypeId.Equals(associationType)) { CatalogAssociationDto.AssociationTypeRow[] associationTypeRows = (CatalogAssociationDto.AssociationTypeRow[])catalogAssociationDto.AssociationType.Select(String.Format("AssociationTypeId = '{0}'", associationType)); if (associationTypeRows.Length > 0) { catalogEntryAssociationRow.AssociationTypeId = associationTypeRows[0].AssociationTypeId; } } } if (bIsNew) { catalogAssociationDto.CatalogEntryAssociation.AddCatalogEntryAssociationRow(catalogEntryAssociationRow); } using (TransactionScope tx = new TransactionScope()) { // Save modifications if (catalogAssociationDto.HasChanges()) { CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto); } tx.Complete(); } } catch (Exception ex) { throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item); } return(1); }
protected override int CreateSystemRow(FillDataMode Mode, int RowIndex, params object[] Item) { int i = 0; object objSysRowAction = Item[i++]; object objParentCode = Item[i++]; object objChildCode = Item[i++]; object objQuantity = Item[i++]; object objGroupName = Item[i++]; object objSortOrder = Item[i++]; CatalogRelationDto.CatalogEntryRelationRow catalogEntryRelationRow = null; CatalogRelationDto catalogRelationDto = new CatalogRelationDto(); try { RowAction sysRowAction = RowAction.Default; if (objSysRowAction != null) { sysRowAction = GetRowActionEnum((string)objSysRowAction); } string parentCode; if (!String.IsNullOrEmpty((string)objParentCode)) { parentCode = (string)objParentCode; } else { throw new AbsentValue("Parent Entry Code"); } string childCode; if (!String.IsNullOrEmpty((string)objChildCode)) { childCode = (string)objChildCode; } else { throw new AbsentValue("Child Entry Code"); } bool bIsNew = false; CatalogEntryDto catalogEntryDto = CatalogEntryManager.GetCatalogEntryDto(parentCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo)); if (catalogEntryDto.CatalogEntry.Count > 0) { CatalogEntryDto.CatalogEntryRow entry = catalogEntryDto.CatalogEntry[0]; if (entry.ClassTypeId.Equals(EntryType.Product, StringComparison.OrdinalIgnoreCase) || entry.ClassTypeId.Equals(EntryType.Bundle, StringComparison.OrdinalIgnoreCase) || entry.ClassTypeId.Equals(EntryType.Package, StringComparison.OrdinalIgnoreCase) || entry.ClassTypeId.Equals(EntryType.DynamicPackage, StringComparison.OrdinalIgnoreCase)) { CatalogEntryDto childEntryDto = CatalogEntryManager.GetCatalogEntryDto(childCode, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo)); if (childEntryDto.CatalogEntry.Count > 0) { CatalogEntryDto.CatalogEntryRow childEntry = childEntryDto.CatalogEntry[0]; catalogRelationDto = CatalogRelationManager.GetCatalogRelationDto(this._CatalogId, 0, entry.CatalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogEntry)); if (catalogRelationDto.CatalogEntryRelation.Count > 0) { DataRow[] drs = catalogRelationDto.CatalogEntryRelation.Select(String.Format("ParentEntryId = {0} AND ChildEntryId = {1}", entry.CatalogEntryId, childEntry.CatalogEntryId)); if (drs.Length > 0) { catalogEntryRelationRow = (CatalogRelationDto.CatalogEntryRelationRow)drs[0]; if (sysRowAction == RowAction.Insert) { throw new MDPImportException(String.Format("The Relation with Parent Entry code '{0}' and Child Entry code '{1}' already exists.", parentCode, childCode)); } if (sysRowAction == RowAction.Delete) { catalogEntryRelationRow.Delete(); CatalogRelationManager.SaveCatalogRelation(catalogRelationDto); return(0); } } } if (catalogEntryRelationRow == null) { if (sysRowAction == RowAction.Update) { throw new MDPImportException(String.Format("The Relation with Parent Entry code '{0}' and Child Entry code '{1}' does not exists.", parentCode, childCode)); } if (sysRowAction == RowAction.Delete) { throw new MDPImportException(String.Format("The Relation with Parent Entry code '{0}' and Child Entry code '{1}' does not exists.", parentCode, childCode)); } catalogEntryRelationRow = catalogRelationDto.CatalogEntryRelation.NewCatalogEntryRelationRow(); catalogEntryRelationRow.ParentEntryId = entry.CatalogEntryId; catalogEntryRelationRow.ChildEntryId = childEntry.CatalogEntryId; catalogEntryRelationRow.Quantity = 1; catalogEntryRelationRow.GroupName = String.Empty; catalogEntryRelationRow.SortOrder = 0; switch (entry.ClassTypeId) { case EntryType.Product: catalogEntryRelationRow.RelationTypeId = EntryRelationType.ProductVariation; break; case EntryType.Package: catalogEntryRelationRow.RelationTypeId = EntryRelationType.PackageEntry; break; case EntryType.Bundle: case EntryType.DynamicPackage: catalogEntryRelationRow.RelationTypeId = EntryRelationType.BundleEntry; break; } bIsNew = true; } } else { throw new MDPImportException(String.Format("The Child Entry with code '{0}' does not exists.", childCode)); } } else { throw new MDPImportException(String.Format("The Parent Entry with code '{0}' has wrong type ('{1}').", parentCode, entry.ClassTypeId)); } } else { throw new MDPImportException(String.Format("The Parent Entry with code '{0}' does not exists.", parentCode)); } //SalePrice if (objQuantity != null) { catalogEntryRelationRow.Quantity = (decimal)objQuantity; } if (objGroupName != null) { catalogEntryRelationRow.GroupName = (string)objGroupName; } if (objSortOrder != null) { catalogEntryRelationRow.SortOrder = (int)objSortOrder; } if (bIsNew) { catalogRelationDto.CatalogEntryRelation.AddCatalogEntryRelationRow(catalogEntryRelationRow); } using (TransactionScope tx = new TransactionScope()) { // Save modifications if (catalogRelationDto.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto); } tx.Complete(); } } catch (Exception ex) { throw new MDPImportException(ex.Message, null, RowIndex, null, null, Item); } return(catalogEntryRelationRow.ParentEntryId); }
public virtual FillResult FillData(FillDataMode mode, DataTable rawData, Rule rule) { return(FillData(mode, rawData, rule, -1, DateTime.Now)); }
public virtual FillResult FillData(FillDataMode mode, DataTable rawData, Rule rule, SqlTransaction tran) { return(FillData(mode, rawData, rule, -1, DateTime.Now, tran)); }
protected override int CreateSystemRow(FillDataMode mode, params object[] item) { if (mode == FillDataMode.Update) { throw new NotSupportedException("Update is not supported for User import"); } string Login = ""; string Password = ""; string FirstName = ""; string LastName = ""; string Email = ""; string Phone = ""; string Fax = ""; string Mobile = ""; string Company = ""; string JobTitle = ""; string Department = ""; string Location = ""; if (item[0] == null || (string)item[0] == "") { throw new EmptyFieldException("Login"); } else { Login = (string)item[0]; } if (item[1] == null || (string)item[2] == "") { throw new EmptyFieldException("FirstName"); } else { FirstName = (string)item[2]; } if (item[2] == null || (string)item[3] == "") { throw new EmptyFieldException("LastName"); } else { LastName = (string)item[3]; } if (item[3] == null || (string)item[1] == "") { throw new EmptyFieldException("Password"); } else { Password = (string)item[1]; } if (item[4] != null) { Email = (string)item[4]; } if (item[5] != null) { Phone = (string)item[5]; } if (item[6] != null) { Fax = (string)item[6]; } if (item[7] != null) { Mobile = (string)item[7]; } if (item[8] != null) { Company = (string)item[8]; } if (item[9] != null) { JobTitle = (string)item[9]; } if (item[10] != null) { Department = (string)item[10]; } if (item[11] != null) { Location = (string)item[11]; } //TODO: IMGroupId?, LanguageId? int UserId = User.Create(Login, Password, FirstName, LastName, Email, true, null, 0, Phone, Fax, Mobile, JobTitle, Department, Company, Location, User.DefaultTimeZoneId, 1, null, null, -1); return(UserId); }
/// <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); }