private static CatalogBase CreateCatalog(string catalogName) { var ctlg = new Catalog(); ctlg.CatalogId = catalogName; ctlg.Name = catalogName; //ctlg.StartDate = DateTime.Now.AddYears(-1); //ctlg.EndDate = DateTime.Now.AddYears(1); ctlg.WeightMeasure = WeightUnitOfMeasure.Pounds.GetHashCode(); //ctlg.IsActive = true; //ctlg.SortOrder = 1; ctlg.DefaultLanguage = "en-us"; ctlg.CatalogLanguages.Add(new CatalogLanguage { CatalogId = ctlg.CatalogId, Language = "en-us" }); ctlg.CatalogLanguages.Add(new CatalogLanguage { CatalogId = ctlg.CatalogId, Language = "de-de" }); var property1 = new Property() { Name = "Description", CatalogId = catalogName }; var property2 = new Property() { Name = "Design", CatalogId = catalogName }; var property3 = new Property() { Name = "Model", CatalogId = catalogName }; var propertySet = new PropertySet() { CatalogId = ctlg.CatalogId, Name = "some property set", TargetType = "All" }; propertySet.PropertySetProperties.Add(new PropertySetProperty() { PropertyId = property1.PropertyId, Property = property1, PropertySetId = propertySet.PropertySetId, PropertySet = propertySet }); propertySet.PropertySetProperties.Add(new PropertySetProperty() { PropertyId = property2.PropertyId, Property = property2, PropertySetId = propertySet.PropertySetId, PropertySet = propertySet }); propertySet.PropertySetProperties.Add(new PropertySetProperty() { PropertyId = property3.PropertyId, Property = property3, PropertySetId = propertySet.PropertySetId, PropertySet = propertySet }); ctlg.PropertySets.Add(propertySet); return ctlg; }
public PropertySetViewModel(ICatalogEntityFactory entityFactory, PropertySet item, ObservableCollection<Property> properties) { _entityFactory = entityFactory; InnerItem = item; InnerItem.PropertyChanged -= InnerItem_PropertyChanged; InnerItem.PropertyChanged += InnerItem_PropertyChanged; ItemsCollection = new CollectionChangeGeneral<PropertySetProperty>(InnerItem.PropertySetProperties); AllAvailableProperties = new ObservableCollection<Property>(properties); var view = CollectionViewSource.GetDefaultView(AllAvailableProperties); view.Filter = FilterProperties; TargetTypes = (Enum.GetValues(typeof(PropertyTargetType)).OfType<PropertyTargetType>().Select(x => x.ToString())).ToList(); // data sorting in list var collView2 = CollectionViewSource.GetDefaultView(ItemsCollection.InnerItems); collView2.SortDescriptions.Add(new System.ComponentModel.SortDescription("Priority", System.ComponentModel.ListSortDirection.Ascending)); }
/// <summary> /// Creates the item model. /// </summary> /// <param name="item">The item.</param> /// <param name="propertySet">The property set.</param> /// <returns>ItemModel.</returns> /// <exception cref="System.ArgumentNullException">item</exception> public static ItemModel CreateItemModel(Item item, PropertySet propertySet = null) { if (item == null) { throw new ArgumentNullException("item"); } var model = new ItemModel { Item = item }; model.InjectFrom(item); model.ItemAssets = new List<ItemAsset>(item.ItemAssets).ToArray(); model.EditorialReviews = new List<EditorialReview>(item.EditorialReviews).ToArray(); model.AssociationGroups = new List<AssociationGroup>(item.AssociationGroups).ToArray(); if (propertySet != null && item.ItemPropertyValues != null) { var values = item.ItemPropertyValues; var properties = propertySet.PropertySetProperties.SelectMany(x => values.Where(v => v.Name == x.Property.Name && !x.Property.PropertyAttributes.Any(pa => pa.PropertyAttributeName.Equals("Hidden", StringComparison.OrdinalIgnoreCase)) //skip hidden && (!x.Property.IsLocaleDependant // if not localized ok || string.Equals(v.Locale, CultureInfo.CurrentUICulture.Name, StringComparison.InvariantCultureIgnoreCase) //if current locale match value locale ok || (string.Equals(v.Locale, StoreHelper.GetDefaultLanguageCode(), StringComparison.InvariantCultureIgnoreCase) //if default locale match value locale and values does not contain locale for current property ok && !values.Any(val => val.Name == x.Property.Name && string.Equals(val.Locale, CultureInfo.CurrentUICulture.Name, StringComparison.InvariantCultureIgnoreCase))))), (r, v) => CreatePropertyModel(r.Priority, r.Property, v, item)).ToArray(); model.Properties = new PropertiesModel(properties); } //Find item category if (item.CategoryItemRelations != null) { string categoryId = null; foreach (var rel in item.CategoryItemRelations) { if (rel.CatalogId == UserHelper.CustomerSession.CatalogId) { categoryId = rel.CategoryId; break; } var category = CatalogClient.GetCategoryById(rel.CategoryId); if (category == null) continue; var linkedCategory = category.LinkedCategories.FirstOrDefault( link => link.CatalogId == UserHelper.CustomerSession.CatalogId); if (linkedCategory == null) continue; categoryId = linkedCategory.CategoryId; break; } if (!string.IsNullOrEmpty(categoryId)) { var category = CatalogClient.GetCategoryById(categoryId); var cat = category as Category; if (cat != null) { model.CategoryName = cat.Name.Localize(); } } } return model; }