public CategorySeoViewModel(ILoginViewModel loginViewModel, ICatalogOutlineBuilder catalogBuilder, IRepositoryFactory<IStoreRepository> storeRepositoryFactory, IRepositoryFactory<IAppConfigRepository> appConfigRepositoryFactory, IAppConfigEntityFactory appConfigEntityFactory, Category item, IEnumerable<string> languages, CatalogBase parentCatalog)
			: base(appConfigRepositoryFactory, appConfigEntityFactory, parentCatalog.DefaultLanguage, languages, item.CategoryId, SeoUrlKeywordTypes.Category)
		{
			_storeRepositoryFactory = storeRepositoryFactory;
			_catalogBuilder = catalogBuilder;
			_loginViewModel = loginViewModel;
			_category = item;
			_catalog = parentCatalog;

			InitializePropertiesForViewing();
		}
        private void BuildCategoryOutline(ref List<CategoryBase> categories, string catalogId, CategoryBase category, bool useCache = true)
        {
            while (true)
            {
                categories.Insert(0, category);

                if (String.IsNullOrEmpty(category.ParentCategoryId)) return;

                var parent = GetCategoryById(catalogId, category.ParentCategoryId, useCache);
                category = parent;
            }
        }
        public CatalogOutline BuildCategoryOutline(string catalogId, CategoryBase category, bool useCache = true)
        {
            // recurring adding elements
            var categories = new List<CategoryBase>();
            var outline = new CatalogOutline { CatalogId = catalogId };
            if (category != null)
            {
                BuildCategoryOutline(ref categories, catalogId, category, useCache);
                outline.Categories.AddRange(categories);
            }

            return outline;
        }
        public TreeCategoryViewModel(
            CategoryBase item,
            IRepositoryFactory<IAppConfigRepository> seoRepositoryFactory,
            IRepositoryFactory<ICatalogRepository> repositoryFactory,
            IViewModelsFactory<ICategoryViewModel> categoryVmFactory,
            IViewModelsFactory<ILinkedCategoryViewModel> linkedCategoryVmFactory,
            IViewModelsFactory<ITreeCategoryViewModel> treeCategoryVmFactory,
            IAuthenticationContext authContext,
            INavigationManager navigationManager)
            : base(repositoryFactory, authContext)
        {
            _treeCategoryVmFactory = treeCategoryVmFactory;
            _seoRepositoryFactory = seoRepositoryFactory;

            InnerItem = item;
            EmbeddedHierarchyEntry = this;
            ViewTitle = new ViewTitleBase
            {
                Title = "Category",
                SubTitle = GetDisplayName(item).ToUpper(CultureInfo.InvariantCulture)
            };

            PriorityChangeCommand = new DelegateCommand<string>(RaisePriorityChangeInteractionRequest);

            OpenItemCommand = new DelegateCommand(() =>
            {
                if (NavigationData == null)
                {
                    var param = new KeyValuePair<string, object>("item", InnerItem);
                    IViewModel editVM;
                    if (InnerItem is Category)
                        editVM = categoryVmFactory.GetViewModelInstance(param, new KeyValuePair<string, object>("parentTreeVM", this));
                    else
                        editVM = linkedCategoryVmFactory.GetViewModelInstance(param);

                    NavigationData = ((IClosable)editVM).NavigationData;
                }
                navigationManager.Navigate(NavigationData);
            });
        }
        private void RaisePriorityChangeInteractionRequest(string parameter)
        {
            var moveUp = parameter == "up";

            var parentHierarchyVM = (HierarchyViewModelBase)Parent;
            var indexThis = parentHierarchyVM.ChildrenModels.IndexOf(this);
            if ((moveUp && indexThis > 0) ||
                (!moveUp && indexThis < parentHierarchyVM.ChildrenModels.Count - 1))
            {
                var indexNext = indexThis + (moveUp ? -1 : 1);
                var siblingVM = (ITreeCategoryViewModel)parentHierarchyVM.ChildrenModels[indexNext];

                using (var repository = _repositoryFactory.GetRepositoryInstance())
                {
                    _innerItem = repository.Categories.Where(x => x.CategoryId == _innerItem.CategoryId).First();
                    var siblingItem = repository.Categories.Where(x => x.CategoryId == siblingVM.InnerItem.CategoryId).First();

                    var tmpPriority = _innerItem.Priority;
                    if (_innerItem.Priority == siblingItem.Priority)
                        _innerItem.Priority = siblingItem.Priority + (moveUp ? 1 : -1);
                    else
                        _innerItem.Priority = siblingItem.Priority;
                    siblingItem.Priority = tmpPriority;

                    repository.UnitOfWork.Commit();
                }

                parentHierarchyVM.Refresh();
            }
        }
        private string GetDisplayName(CategoryBase item)
        {
            var result = String.Empty;

            var category = item as Category;
            if (category != null)
            {
                result = category.Name;
            }
            else
            {
                var linkedCategory = (LinkedCategory)item;
                if (linkedCategory != null)
                {
                    var link = linkedCategory.CategoryLink;
                    if (link != null)
                        result = (link is Category)
                            ? String.Format("{0} ({1})", ((Category)link).Name, linkedCategory.LinkedCatalogId)
                            : String.Format("{0} ({1})", link.CategoryId, linkedCategory.LinkedCatalogId);
                }
            }
            return result;
        }
        public void SetParent(object child, object parent)
        {
            using (var repository = _repositoryFactory.GetRepositoryInstance())
            {
                _innerItem = repository.Categories.Where(x => x.CategoryId == _innerItem.CategoryId).First();

                if (parent is ITreeCategoryViewModel)
                {
                    var targetCategoryVM = parent as ITreeCategoryViewModel;

                    InnerItem.ParentCategoryId = targetCategoryVM.InnerItem.CategoryId;
                    // InnerItem.ParentCategory = targetCategoryVM.InnerItem;

                    Parent = targetCategoryVM;
                }
                else if (parent is ITreeCatalogViewModel || parent is ITreeVirtualCatalogViewModel)
                {
                    // var targetCatalogVM = parent as ICatalogViewModel;
                    InnerItem.ParentCategoryId = null;
                    InnerItem.ParentCategory = null;
                    //InnerItem.Catalog = targetCatalogVM.InnerCatalog;
                    //InnerItem.CatalogId = targetCatalogVM.InnerCatalog.CatalogId;

                    Parent = (IViewModel)parent;
                }

                repository.UnitOfWork.Commit();
            }
        }
예제 #8
0
        /// <summary>
        /// Creates the category model.
        /// </summary>
        /// <param name="category">The category.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">category</exception>
        public static CategoryModel CreateCategoryModel(CategoryBase category)
        {
            if (category == null)
            {
                throw new ArgumentNullException("category");
            }

            var model = new CategoryModel { Category = category };
            model.InjectFrom(category);

            model.LinkedCategories = new List<LinkedCategory>(category.LinkedCategories).ToArray();
            model.CatalogOutline = CatalogClient.BuildCategoryOutline(UserHelper.CustomerSession.CatalogId, category);

            if (category is Category)
            {
                var realCat = category as Category;
                model.CategoryPropertyValues = new List<CategoryPropertyValue>(realCat.CategoryPropertyValues).ToArray();

                if (realCat.PropertySet != null && realCat.CategoryPropertyValues != null)
                {
                    var values = realCat.CategoryPropertyValues;
                    var properties = realCat.PropertySet.PropertySetProperties.SelectMany(x => values.Where(v => v.Name == x.Property.Name
                        && !x.Property.PropertyAttributes.Any(pa => pa.PropertyAttributeName.Equals("Hidden", StringComparison.OrdinalIgnoreCase))
                        && (!x.Property.IsLocaleDependant
                        || string.Equals(v.Locale, CultureInfo.CurrentUICulture.Name, StringComparison.InvariantCultureIgnoreCase))),
                        (r, v) => CreatePropertyModel(r.Priority, r.Property, v, category)).ToArray();

                    model.Properties = new PropertiesModel(properties);
                }
            }
            return model;
        }
        public static string BuildCategoryOutline(ICatalogRepository repository, string catalogId, CategoryBase category)
        {
            if (String.IsNullOrEmpty(category.ParentCategoryId))
            {
                return String.Format("{0}/{1}", catalogId, category.CategoryId);
            }

            // TODO: add caching to this method, otherwise we going to be retrieving same category many times
            var parent = repository.Categories.FirstOrDefault(x => x.CategoryId == category.ParentCategoryId);
            return String.Format("{0}/{1}", BuildCategoryOutline(repository, catalogId, parent), category.CategoryId);
        }
		public SaveCatalogCategoryChangesMessage(CategoryBase category)
		{
			Category = category;
		}
 public CatalogOutline BuildCategoryOutline(string catalogId, CategoryBase category)
 {
     return _catalogOutlineBuilder.BuildCategoryOutline(catalogId, category);
 }