public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (IAppConfigRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); var type = systemValues.First(y => y.Name == "KeywordType"); type.Value = ((int)Enum.Parse(typeof(SeoUrlKeywordTypes), type.Value)).ToString(CultureInfo.InvariantCulture); switch (action) { case ImportAction.Insert: var addItem = InitializeItem(null, systemValues); _repository.Add(addItem); break; case ImportAction.InsertAndReplace: var itemR = systemValues.FirstOrDefault(y => y.Name == "Language"); var itemRKey = systemValues.FirstOrDefault(y => y.Name == "KeywordValue"); var itemRType = Int32.Parse(systemValues.First(y => y.Name == "KeywordType").Value); if (itemR != null && itemRKey != null) { var originalItem = _repository.SeoUrlKeywords.Where(x => x.Language == itemR.Value && x.KeywordValue == itemRKey.Value && x.KeywordType == itemRType).SingleOrDefault(); if (originalItem != null) _repository.Remove(originalItem); } var replaceItem = InitializeItem(null, systemValues); _repository.Add(replaceItem); break; case ImportAction.Update: var itemU = systemValues.FirstOrDefault(y => y.Name == "Language"); var itemUKey = systemValues.FirstOrDefault(y => y.Name == "KeywordValue"); var itemUType = Int32.Parse(systemValues.First(y => y.Name == "KeywordType").Value); if (itemU != null) { var origItem = _repository.SeoUrlKeywords.Where(x => x.Language == itemU.Value && x.KeywordValue.Equals(itemUKey.Value, StringComparison.Ordinal) && x.KeywordType == itemUType).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); _repository.Update(origItem); } } break; case ImportAction.Delete: var itemD = systemValues.First(y => y.Name == "Language"); var itemDKey = systemValues.First(y => y.Name == "KeywordValue"); var itemDType = Int32.Parse(systemValues.First(y => y.Name == "KeywordType").Value); if (itemD != null) { var deleteItem = _repository.SeoUrlKeywords.Where(x => x.Language == itemD.Value && x.KeywordValue == itemDKey.Value && x.KeywordType == itemDType).SingleOrDefault(); if (deleteItem != null) _repository.Remove(deleteItem); } break; } return _error; }
public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (IAppConfigRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); switch (action) { case ImportAction.Insert: var addItem = InitializeItem(null, systemValues); _repository.Add(addItem); break; case ImportAction.InsertAndReplace: var itemR = systemValues.FirstOrDefault(y => y.Name == "LanguageCode"); var itemRKey = systemValues.FirstOrDefault(y => y.Name == "Name"); if (itemR != null) { var originalItem = _repository.Localizations.Where(x => x.LanguageCode == itemR.Value && x.Name == itemRKey.Value).SingleOrDefault(); if (originalItem != null) _repository.Remove(originalItem); } var replaceItem = InitializeItem(null, systemValues); _repository.Add(replaceItem); break; case ImportAction.Update: var itemU = systemValues.FirstOrDefault(y => y.Name == "LanguageCode"); var itemUKey = systemValues.FirstOrDefault(y => y.Name == "Name"); if (itemU != null) { var origItem = _repository.Localizations.Where(x => x.LanguageCode == itemU.Value && x.Name.Equals(itemUKey.Value, StringComparison.Ordinal)).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); _repository.Update(origItem); } } break; case ImportAction.Delete: var itemD = systemValues.FirstOrDefault(y => y.Name == "LanguageCode"); if (itemD != null) { var deleteItem = _repository.Localizations.Where(x => x.LanguageCode == itemD.Value).SingleOrDefault(); if (deleteItem != null) _repository.Remove(deleteItem); } break; } return _error; }
public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (ICatalogRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); switch (action) { case ImportAction.Insert: var addItem = InitializeItem(null, systemValues); _repository.Add(addItem); break; case ImportAction.InsertAndReplace: var itemR = systemValues.FirstOrDefault(y => y.Name == "TaxCategoryId"); if (itemR != null) { var originalItem = _repository.TaxCategories.Where(x => x.TaxCategoryId == itemR.Value).SingleOrDefault(); if (originalItem != null) _repository.Remove(originalItem); } var replaceItem = InitializeItem(null, systemValues); _repository.Add(replaceItem); break; case ImportAction.Update: var itemU = systemValues.FirstOrDefault(y => y.Name == "TaxCategoryId"); if (itemU != null) { var origItem = _repository.TaxCategories.Where(x => x.TaxCategoryId == itemU.Value).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); _repository.Update(origItem); } } break; case ImportAction.Delete: var itemD = systemValues.FirstOrDefault(y => y.Name == "TaxCategoryId"); if (itemD != null) { var deleteItem = _repository.TaxCategories.Where(x => x.TaxCategoryId == itemD.Value).SingleOrDefault(); if (deleteItem != null) _repository.Remove(deleteItem); } break; } return _error; }
public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _catalogRepository = (ICatalogRepository) repository; _repository = (IPricelistRepository) repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); var itemId = systemValues.First(y => y.Name == "ItemId").Value; var catName = systemValues.First(y => y.Name == "CatalogId").Value; if (!string.IsNullOrEmpty(catName)) catalogId = _catalogRepository.Catalogs.Where(cat => cat.Name == catName).First().CatalogId; //get item with the provided ItemId or item Code var originalItems = _catalogRepository.Items.Where(x => x.ItemId == itemId || x.Code == itemId).ToArray(); Item originalItem; //if more than 1 item found and catalogId is not provided - return error, otherwise ok if (originalItems.Count() > 1) { if (!string.IsNullOrEmpty(catalogId)) originalItem = originalItems.FirstOrDefault(x => x.CatalogId == catalogId); else { var catNames = string.Empty; originalItems.ToList().ForEach(x => catNames = catNames + x.CatalogId + ", "); _error = string.Format("Item with code - {0} has matches in catalogs: {1}. Specify catalog property.", itemId, catNames); return _error; } } else { originalItem = originalItems.FirstOrDefault(); } //if item with the code found (not null) try to execute the import action otherwise return error if (originalItem != null) { switch (action) { case ImportAction.Insert: var addItem = InitializeItem(null, systemValues); //set price itemId to the found ItemId addItem.ItemId = originalItem.ItemId; _repository.Add(addItem); break; case ImportAction.InsertAndReplace: var qtyR = systemValues.FirstOrDefault(y => y.Name == "MinQuantity"); var listIdR = systemValues.FirstOrDefault(y => y.Name == "PricelistId"); if (qtyR != null && listIdR != null) { var qtyVal = int.Parse(qtyR.Value); var origItem = _repository.Prices.ToList().Where(x => x.ItemId == originalItem.ItemId && x.MinQuantity == qtyVal && x.PricelistId == listIdR.Value).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); //set price itemId to the found ItemId origItem.ItemId = originalItem.ItemId; _repository.Update(origItem); } else { var newItem = InitializeItem(null, systemValues); //set price itemId to the found ItemId newItem.ItemId = originalItem.ItemId; _repository.Add(newItem); } } break; case ImportAction.Update: var qty = systemValues.FirstOrDefault(y => y.Name == "MinQuantity"); var listId = systemValues.FirstOrDefault(y => y.Name == "PricelistId"); if (qty != null && listId != null) { var qtyVal = int.Parse(qty.Value); var origItem = _repository.Prices.ToList().Where(x => x.ItemId == originalItem.ItemId && x.MinQuantity == qtyVal && x.PricelistId == listId.Value).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); //set price itemId to the found ItemId origItem.ItemId = originalItem.ItemId; _repository.Update(origItem); } } break; case ImportAction.Delete: var qtyValue = systemValues.FirstOrDefault(y => y.Name == "MinQuantity"); var pricelistId = systemValues.FirstOrDefault(y => y.Name == "PricelistId"); if (qtyValue != null && pricelistId != null) { var qtyVal = int.Parse(qtyValue.Value); var deleteItem = _repository.Prices.ToList().Where(x => x.ItemId == originalItem.ItemId && x.MinQuantity == qtyVal && x.PricelistId == pricelistId.Value).SingleOrDefault(); if (deleteItem != null) _repository.Remove(deleteItem); } break; } } else { _error = string.Format("Item with itemId/code - {0} not found", itemId); } return _error; }
public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (ICatalogRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); switch (action) { case ImportAction.Insert: var group = systemValues.First(y => y.Name == "GroupName").Value; var target = systemValues.First(y => y.Name == "TargetId").Value; var source = systemValues.First(y => y.Name == "ItemId").Value; var sourceItems = _repository.Items.Where(x => x.ItemId == source || x.Code == source).ToList(); Item sourceItem; //aa: below condition checks if more than 1 item found - catalogId should be provided and item of the catalog selected, otherwise return error if (sourceItems.Count() > 1) { var sourceCatName = systemValues.First(y => y.Name == "SourceCatalogId").Value; if (!string.IsNullOrEmpty(sourceCatName)) catalogId = _repository.Catalogs.Where(cat => cat.Name == sourceCatName).First().CatalogId; if (!string.IsNullOrEmpty(catalogId)) sourceItem = sourceItems.FirstOrDefault(x => x.CatalogId == catalogId); else { var catNames = string.Empty; sourceItems.ForEach(x => catNames = catNames + x.CatalogId + ", "); _error = string.Format(notUniqueSourceError, source, catNames); return _error; } } //aa: if 1 item found set it to sourceItem and go further else { sourceItem = sourceItems.FirstOrDefault(); } var targetItems = _repository.Items.Where(x => x.ItemId == target || x.Code == target).ToList(); Item targetItem; //aa: below condition checks if more than 1 item found - catalogId should be provided and item of the catalog selected, otherwise return error if (targetItems.Count() > 1) { var targetCatName = systemValues.First(y => y.Name == "TargetCatalogId").Value; if (!string.IsNullOrEmpty(targetCatName)) catalogId = _repository.Catalogs.Where(cat => cat.Name == targetCatName).First().CatalogId; if (!string.IsNullOrEmpty(catalogId)) targetItem = targetItems.FirstOrDefault(x => x.CatalogId == catalogId); else { var catNames = string.Empty; targetItems.ForEach(x => catNames = catNames + x.CatalogId + ", "); _error = string.Format(notUniqueTargetError, target, catNames); return _error; } } //aa: if 1 item found set it to sourceItem and go further else { targetItem = targetItems.FirstOrDefault(); } if (!string.IsNullOrEmpty(group) && targetItem != null && sourceItem != null) { var associationGroup = _repository.Associations.Where(x => x.AssociationGroup.Name == group && x.ItemId == targetItem.ItemId).SingleOrDefault(); string groupId; if (associationGroup == null) { var addGroup = new AssociationGroup() { ItemId = targetItem.ItemId, Name = group }; _repository.Add(addGroup); groupId = addGroup.AssociationGroupId; } else { groupId = associationGroup.AssociationGroupId; } var addItem = InitializeItem(null, systemValues); ((Association)addItem).AssociationGroupId = groupId; ((Association)addItem).ItemId = sourceItem.ItemId; _repository.Add(addItem); } else { _error = "Not all required data provided"; } break; case ImportAction.InsertAndReplace: var itemR = systemValues.FirstOrDefault(y => y.Name == "AssociationId"); if (itemR != null) { var originalItem = _repository.Associations.Where(x => x.ItemId == itemR.Value).SingleOrDefault(); if (originalItem != null) repository.Remove(originalItem); } var replaceItem = InitializeItem(null, systemValues); repository.Add(replaceItem); break; case ImportAction.Update: var itemU = systemValues.FirstOrDefault(y => y.Name == "AssociationId"); if (itemU != null) { var origItem = _repository.Associations.Where(x => x.ItemId == itemU.Value).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); _repository.Update(origItem); } } break; case ImportAction.Delete: var itemD = systemValues.FirstOrDefault(y => y.Name == "AssociationId"); if (itemD != null) { var deleteItem = _repository.Associations.Where(x => x.ItemId == itemD.Value).SingleOrDefault(); if (deleteItem != null) _repository.Remove(deleteItem); } break; } return _error; }
public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (IOrderRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); switch (action) { case ImportAction.Insert: var itemI = systemValues.FirstOrDefault(y => y.Name == "Code"); if (itemI != null) { var originalItem = _repository.JurisdictionGroups.Where(x => x.Code == itemI.Value).FirstOrDefault(); if (originalItem == null) { var addItem = InitializeItem(null, systemValues); _repository.Add(addItem); originalItem = addItem; } var jurisdictionCode = systemValues.First(x => x.Name == "JurisdictionCode").Value; if (jurisdictionCode != null) { var jItem = _repository.Jurisdictions.Where(x => x.Code == jurisdictionCode).SingleOrDefault(); if (jItem != null) { var relation = new JurisdictionRelation() { JurisdictionId = jItem.JurisdictionId, JurisdictionGroupId = originalItem.JurisdictionGroupId }; _repository.Add(relation); } } } break; case ImportAction.InsertAndReplace: var itemR = systemValues.FirstOrDefault(y => y.Name == "Code"); if (itemR != null) { var originalItem = _repository.JurisdictionGroups.Where(x => x.Code == itemR.Value).SingleOrDefault(); if (originalItem != null) _repository.Remove(originalItem); } var replaceItem = InitializeItem(null, systemValues); _repository.Add(replaceItem); break; case ImportAction.Update: var itemU = systemValues.FirstOrDefault(y => y.Name == "JurisdictionCode"); if (itemU != null) { var origItem = _repository.JurisdictionGroups.Where(x => x.Code == itemU.Value).SingleOrDefault(); if (origItem != null) { InitializeItem(origItem, systemValues); _repository.Update(origItem); } } break; case ImportAction.Delete: var itemD = systemValues.FirstOrDefault(y => y.Name == "JurisdictionCode"); if (itemD != null) { var deleteItem = _repository.JurisdictionGroups.Where(x => x.Code == itemD.Value).SingleOrDefault(); if (deleteItem != null) _repository.Remove(deleteItem); } break; } return _error; }
public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (ICatalogRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); var itemCode = systemValues.SingleOrDefault(y => y.Name == "Code") != null ? systemValues.Single(y => y.Name == "Code").Value : null; var parentCategoryCode = systemValues.SingleOrDefault(val => val.Name == "ParentCategoryId") != null ? systemValues.Single(val => val.Name == "ParentCategoryId").Value : null; var parentCategory = _repository.Categories.Where(cat => cat.CatalogId == catalogId && cat.Code == parentCategoryCode).FirstOrDefault(); //if action is not delete and parent category code provided is not null and there is no category with the code in repository return error if (action != ImportAction.Delete && !string.IsNullOrEmpty(parentCategoryCode) && parentCategory == null) { _error = string.Format("Parent category with the code {0} does not exist", parentCategoryCode); } else { switch (action) { case ImportAction.Insert: //if there is already category with the same code - return error if (_repository.Categories.Where(cat => cat.CatalogId == catalogId && cat.Code == itemCode).FirstOrDefault() != null) { _error = string.Format("Category with the code {0} already exist", itemCode); } else { var addItem = InitializeItem(null, systemValues); addItem.ParentCategoryId = !string.IsNullOrEmpty(parentCategoryCode) ? parentCategory.CategoryId : null; addItem.CatalogId = catalogId; addItem.PropertySetId = propertySetId; _repository.Add(addItem); var propSet = _repository.PropertySets.Expand("PropertySetProperties/Property/PropertyValues") .Where(x => x.PropertySetId == propertySetId) .SingleOrDefault(); if (propSet != null) { var resProps = InitializeProperties(propSet.PropertySetProperties.ToArray(), customValues, addItem.CategoryId); resProps.ForEach(_repository.Add); } } break; case ImportAction.InsertAndReplace: if (itemCode != null) { var originalItem = _repository.Categories.Where(cat => cat.CatalogId == catalogId && cat.Code == itemCode).FirstOrDefault(); if (originalItem != null) { InitializeItem((Category)originalItem, systemValues); originalItem.ParentCategoryId = !string.IsNullOrEmpty(parentCategoryCode) ? parentCategory.CategoryId : null; _repository.Update(originalItem); } else { var addItem = InitializeItem(null, systemValues); addItem.ParentCategoryId = !string.IsNullOrEmpty(parentCategoryCode) ? parentCategory.CategoryId : null; addItem.CatalogId = catalogId; addItem.PropertySetId = propertySetId; _repository.Add(addItem); var propSet = _repository.PropertySets.Expand("PropertySetProperties/Property/PropertyValues") .Where(x => x.PropertySetId == propertySetId) .SingleOrDefault(); if (propSet != null) { var resProps = InitializeProperties(propSet.PropertySetProperties.ToArray(), customValues, addItem.CategoryId); resProps.ForEach(_repository.Add); } } } break; case ImportAction.Update: var itemU = systemValues.FirstOrDefault(y => y.Name == "Code"); if (itemU != null) { var origItem = _repository.Categories.Where(x => x.CategoryId == itemU.Value).SingleOrDefault(); if (origItem != null) { InitializeItem((Category) origItem, systemValues); _repository.Update(origItem); } } break; case ImportAction.Delete: var deleteItem = _repository.Categories.Where(cat => cat.CatalogId == catalogId && cat.Code == itemCode).SingleOrDefault(); if (deleteItem != null) _repository.Remove(deleteItem); break; } } return _error; }
public override string Import(string catalogId, string propertySetId, ImportItem[] systemValues, ImportItem[] customValues, IRepository repository) { var _error = string.Empty; _repository = (ITaxRepository)repository; var action = GetAction(systemValues.First(x => x.Name == "Action").Value); switch (action) { case ImportAction.Insert: var itemI = systemValues.FirstOrDefault(y => y.Name == "TaxId"); if (itemI != null) { var originalItem = _repository.Taxes.Where(x => x.TaxId == itemI.Value); if (originalItem.Count() == 0) { var name = systemValues.FirstOrDefault(y => y.Name == "TaxName"); var type = systemValues.FirstOrDefault(y => y.Name == "TaxType"); var addItem = new Tax { TaxId = itemI.Value, Name = name.Value, TaxType = Int32.Parse(type.Value) }; _repository.Add(addItem); _repository.UnitOfWork.Commit(); } } var tax = _repository.Taxes.Where(x => x.TaxId == itemI.Value); if (tax.Count() > 0) { var t = tax.First(); var value = InitializeItem(null, systemValues); t.TaxValues.Add(value); } break; case ImportAction.InsertAndReplace: var itemR = systemValues.FirstOrDefault(y => y.Name == "TaxId"); if (itemR != null) { var originalItem = _repository.Taxes.Where(x => x.TaxId == itemR.Value).SingleOrDefault(); if (originalItem != null) _repository.Remove(originalItem); } var replaceItem = InitializeItem(null, systemValues); _repository.Add(replaceItem); break; case ImportAction.Update: //var itemU = systemValues.FirstOrDefault(y => y.Name == "PriceId"); //if (itemU != null) //{ // var origItem = _repository.Taxes.Where(x => x.TaxId == itemU.Value).SingleOrDefault(); // if (origItem != null && origItem is TaxValue) // { // InitializeItem((TaxValue)origItem, systemValues); // _repository.Update(origItem); // } //} break; case ImportAction.Delete: var itemD = systemValues.FirstOrDefault(y => y.Name == "TaxId"); if (itemD != null) { var deleteItem = _repository.Taxes.Where(x => x.TaxId == itemD.Value).SingleOrDefault(); if (deleteItem != null) _repository.Remove(deleteItem); } break; } return _error; }