public JsonResult GetSecondAndThirdCategoriesByTopId(long id) { ICategoryService categoryService = ServiceHelper.Create <ICategoryService>(); CategoryTreeModel[] array = ( from item in categoryService.GetCategoryByParentId(id) select new CategoryTreeModel() { Id = item.Id, Name = item.Name, ParentCategoryId = item.ParentCategoryId, Depth = item.Depth }).ToArray(); CategoryTreeModel[] categoryTreeModelArray = array; for (int i = 0; i < categoryTreeModelArray.Length; i++) { CategoryTreeModel categoryByParentId = categoryTreeModelArray[i]; categoryByParentId.Children = from item in categoryService.GetCategoryByParentId(categoryByParentId.Id) select new CategoryTreeModel() { Id = item.Id, Name = item.Name, ParentCategoryId = item.ParentCategoryId, Depth = item.Depth }; } return(Json(new { success = true, categoies = array }, JsonRequestBehavior.AllowGet)); }
private TreeViewItemTool CreateTreeViewItem(CategoryTreeModel category) { TreeViewItemTool result = new TreeViewItemTool { Header = category.CategoryName, Tag = category, ContextMenu = new ContextMenu() }; MenuItem itemAdd = new MenuItem { Header = "Add Child Category" }; MenuItem itemDelete = new MenuItem { Header = "Delete Category" }; itemAdd.Click += this.CategoryItem_Add; itemDelete.Click += this.CategoryItem_Delete; result.ContextMenu.Items.Add(itemAdd); result.ContextMenu.Items.Add(itemDelete); return(result); }
public ActionResult Tree() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var customerChoice = _genericAttributeService.Value.GetAttribute <string>("Customer", _workContext.CurrentCustomer.Id, "AdminCategoriesType"); if (customerChoice == null || customerChoice.Equals("List")) { _genericAttributeService.Value.SaveAttribute <string>(_workContext.CurrentCustomer, "AdminCategoriesType", "Tree"); } var allStores = _storeService.GetAllStores(); var model = new CategoryTreeModel(); foreach (var store in allStores) { model.AvailableStores.Add(new SelectListItem { Text = store.Name, Value = store.Id.ToString() }); } return(View(model)); }
private void CategoryItem_Add(object sender, RoutedEventArgs e) { try { if (InputBox.ShowDialog("Category", "Name").IsFalse()) { return; } ; int studyCategoryId = BiblesData.Database.InsertCategory(InputBox.Result, this.SelectedCategory.StudyCategoryId); CategoryTreeModel treeModel = new CategoryTreeModel { CategoryName = InputBox.Result, ParentStudyCategoryId = this.SelectedCategory.StudyCategoryId, StudyCategoryId = studyCategoryId }; ((TreeViewItemTool)this.uxCategoryTree.SelectedItem).Items.Add(this.CreateTreeViewItem(treeModel)); ((TreeViewItemTool)this.uxCategoryTree.SelectedItem).IsExpanded = true; } catch (Exception err) { ErrorLog.ShowError(err); } }
private bool SelectCategoryItem(TreeViewItemTool parent, int studyCategoryId) { if (parent.Tag != null) { CategoryTreeModel tagValue = parent.Tag.To <CategoryTreeModel>(); if (tagValue.StudyCategoryId == studyCategoryId) { parent.IsSelected = true; return(true); } } if (parent.Items == null) { return(false); } foreach (TreeViewItemTool child in parent.Items) { child.IsExpanded = this.SelectCategoryItem(child, studyCategoryId); if (child.IsExpanded) { return(true); } } return(false); }
public CategoryTreeExplorerPaneViewModel() { this.ContentId = "CategoryTreeExplorerPane"; this.Title = "カテゴリ一覧"; this._CategoryTreeModel = CategoryTreeModel.CreateInitializeTreeModel(); }
public static CategoryTreeModel CreateInitializeTreeModel() { var model = new CategoryTreeModel(); model.Root.Load(true); return(model); }
private void LoadCategoryChildren(CategoryTreeModel category, TreeViewItemTool categoryTreeItem) { foreach (CategoryTreeModel childCategory in category.ChildCategories) { TreeViewItemTool childTreeItem = this.CreateTreeViewItem(childCategory); this.LoadCategoryChildren(childCategory, childTreeItem); categoryTreeItem.Items.Add(childTreeItem); } }
private void LoadTreeChildren(CategoryTreeModel parent, List <StudyCategoryModel> categoriesList) { foreach (StudyCategoryModel child in categoriesList.Where(ci => ci.ParentStudyCategoryId == parent.StudyCategoryId)) { CategoryTreeModel childItem = child.CopyToObject(new CategoryTreeModel()).To <CategoryTreeModel>(); this.LoadTreeChildren(childItem, categoriesList); parent.ChildCategories.Add(childItem); } }
public ActionResult Tree() { var customerChoice = _genericAttributeService.Value.GetAttribute <string>("Customer", _workContext.CurrentCustomer.Id, "AdminCategoriesType"); if (customerChoice == null || customerChoice.Equals("List")) { _genericAttributeService.Value.SaveAttribute(_workContext.CurrentCustomer, "AdminCategoriesType", "Tree"); } var model = new CategoryTreeModel { IsSingleStoreMode = _storeService.IsSingleStoreMode(), CanEdit = Services.Permissions.Authorize(Permissions.Catalog.Category.Update) }; return(View(model)); }
public ActionResult Tree() { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var allStores = _storeService.GetAllStores(); var model = new CategoryTreeModel(); foreach (var store in allStores) { model.AvailableStores.Add(new SelectListItem { Text = store.Name, Value = store.Id.ToString() }); } return(View(model)); }
public ActionResult TreeLoadChildren(TreeViewItem node, CategoryTreeModel model) { var parentId = !string.IsNullOrEmpty(node.Value) ? Convert.ToInt32(node.Value) : 0; var urlHelper = new UrlHelper(this.ControllerContext.RequestContext); var parentCategories = _categoryService.GetAllCategoriesByParentCategoryId(parentId, true); if (parentId == 0 && model.SearchStoreId != 0) { for (int i = parentCategories.Count - 1; i >= 0; --i) { var category = parentCategories[i]; if (!category.LimitedToStores || (category.LimitedToStores && !_storeMappingService.GetStoresIdsWithAccess(category).Contains(model.SearchStoreId))) { parentCategories.Remove(category); } } } var children = parentCategories.Select(x => { var childCount = _categoryService.GetAllCategoriesByParentCategoryId(x.Id, true).Count; string text = (childCount > 0 ? "{0} ({1})".FormatInvariant(x.Name, childCount) : x.Name); var item = new TreeViewItem { Text = x.Alias.HasValue() ? "{0} <span class='label'>{1}</span>".FormatCurrent(text, x.Alias) : text, Encoded = x.Alias.IsEmpty(), Value = x.Id.ToString(), LoadOnDemand = (childCount > 0), Enabled = true, ImageUrl = Url.Content(x.Published ? "~/Administration/Content/images/ico-content.png" : "~/Administration/Content/images/ico-content-o60.png"), Url = urlHelper.Action("Edit", "Category", new { id = x.Id }) }; return(item); }); return(new JsonResult { Data = children }); }
public List <CategoryTreeModel> GetCategoryTree() { Task <List <StudyCategoryModel> > categoriesTask = BiblesData.database .Table <StudyCategoryModel>() .ToListAsync(); List <CategoryTreeModel> result = new List <CategoryTreeModel>(); List <StudyCategoryModel> categoriesList = categoriesTask.Result; foreach (StudyCategoryModel category in categoriesList.Where(pi => pi.ParentStudyCategoryId == 0)) { CategoryTreeModel resultItem = category.CopyToObject(new CategoryTreeModel()).To <CategoryTreeModel>(); this.LoadTreeChildren(resultItem, categoriesList); result.Add(resultItem); } return(result); }