コード例 #1
0
ファイル: OrgListController.cs プロジェクト: hidha/OrgTree
        public ActionResult Index(string FileName)
        {
            var result = new HierarchyViewModel();

            if (string.IsNullOrEmpty(FileName))
            {
                result.Error = new Error()
                {
                    Message = "File not specified, Click <a href='/'>here</a> to continue"
                };
                return(View(result));
            }

            try
            {
                using (StreamReader sr = new StreamReader(Server.MapPath(FileName)))
                {
                    var empList = JsonConvert.DeserializeObject <List <Employee> >(sr.ReadToEnd());
                    result.EmployeeHierachyList = Hierarchy.ProcessEmployeeList(empList);
                    result.MaxLevel             = result.EmployeeHierachyList.Max(x => x.Level);
                }
            }
            catch (FileNotFoundException ex)
            {
                result.Error = new Error()
                {
                    Message = ex.Message
                };
            }

            return(View(result));
        }
コード例 #2
0
        private void Collapse(HierarchyViewModel hierarchy, HierarchyPath hierarchyPath)
        {
            HierarchyItemViewModel item = this.FindItem(hierarchy, hierarchyPath);

            if (item != null)
            {
                item.Expanded = false;
                item.Categories.Clear();
            }
        }
コード例 #3
0
        private void Select(HierarchyViewModel hierarchy, HierarchyPath hierarchyPath)
        {
            this.UnselectAll(hierarchy);

            HierarchyItemViewModel item = this.FindItem(hierarchy, hierarchyPath);

            if (item != null)
            {
                item.Selected = true;
            }
        }
コード例 #4
0
        private void Expand(HierarchyViewModel hierarchy, HierarchyPath hierarchyPath, List <LoadCategoriesInstruction> loadCategoriesInstructions)
        {
            CatalogItemViewModel catalog = hierarchy.FirstOrDefault(cata => cata.Catalog.Code.EqualsOrdinalIgnoreCase(hierarchyPath.Catalog));

            if (catalog != null)
            {
                loadCategoriesInstructions.Add(
                    new LoadCategoriesInstruction(
                        catalog.Catalog.CatalogId,
                        hierarchyPath.TargetCatalog ? CatalogHierarchyServices.RootCategoryCode : hierarchyPath.Categories.Last(),
                        this.CreateAppender(hierarchy, hierarchyPath)
                        )
                    );
            }
        }
コード例 #5
0
        private void Initialize(HierarchyViewModel hierarchy, HierarchyPath hierarchyPath, List <LoadCategoriesInstruction> loadCategoriesInstructions)
        {
            IEnumerable <CatalogItemViewModel> newlyLoadedCatalogs = this.RefreshCatalogs(hierarchy)
                                                                     .Where(cata => !cata.Catalog.Code.EqualsOrdinalIgnoreCase(hierarchyPath.Catalog));

            loadCategoriesInstructions.AddRange(
                (hierarchy.Count == 1 ? hierarchy : newlyLoadedCatalogs).Select(
                    cata => new LoadCategoriesInstruction(
                        cata.Catalog.CatalogId,
                        CatalogHierarchyServices.RootCategoryCode,
                        this.CreateAppender(cata)
                        )
                    )
                );
        }
コード例 #6
0
        public HierarchyViewModel GetModel(CatalogHierarchyPart part)
        {
            HierarchyViewModel hierarchy = this.GetRequestHieararchy(part);

            if (hierarchy == null)
            {
                hierarchy = this.EnsureHierarchy(part);

                Boolean       isTarget      = this._target == part.Id;
                HierarchyPath hierarchyPath = new HierarchyPath(this.PathSeparator, isTarget ? this._path : null);
                List <LoadCategoriesInstruction> loadCategoriesInstructions = new List <LoadCategoriesInstruction>();

                this.Initialize(hierarchy, hierarchyPath, loadCategoriesInstructions);

                if (isTarget)
                {
                    this.EnsurePath(hierarchy, hierarchyPath, loadCategoriesInstructions);

                    if (this.ExpandParameterValue.EqualsOrdinalIgnoreCase(this._action))
                    {
                        this.Expand(hierarchy, hierarchyPath, loadCategoriesInstructions);
                    }

                    this.Execute(hierarchy, loadCategoriesInstructions);

                    if (this.CollapseParameterValue.EqualsOrdinalIgnoreCase(this._action))
                    {
                        this.Collapse(hierarchy, hierarchyPath);
                    }

                    if (this.SelectParameterValue.EqualsOrdinalIgnoreCase(this._action))
                    {
                        this.Select(hierarchy, hierarchyPath);
                    }
                }
                else
                {
                    this.Execute(hierarchy, loadCategoriesInstructions);
                }

                this.EnsureSelection(part, hierarchy);
                this.RegisterHierarchyForRequest(part, hierarchy);
            }

            return(hierarchy);
        }
コード例 #7
0
        private void EnsureSelection(CatalogHierarchyPart part, HierarchyViewModel hierarchy)
        {
            IEnumerable <HierarchyItemViewModel> selectables = (hierarchy.Count == 1 ? hierarchy.SelectMany(cata => cata.Categories) : hierarchy.Cast <HierarchyItemViewModel>()).ToList();

            if (part.GenerateUrls)
            {
                this.UnselectAll(hierarchy);
            }
            else if (!this.HasSelection(selectables))
            {
                HierarchyItemViewModel item = selectables.FirstOrDefault();

                if (item != null)
                {
                    item.Selected = true;
                }
            }
        }
コード例 #8
0
        private HierarchyItemViewModel FindItem(HierarchyViewModel hierarchy, HierarchyPath hierarchyPath)
        {
            HierarchyItemViewModel item = hierarchy.FirstOrDefault(cata => cata.Catalog.Code.EqualsOrdinalIgnoreCase(hierarchyPath.Catalog));

            if (item != null)
            {
                foreach (String categoryCode in hierarchyPath.Categories)
                {
                    item = item.Categories.FirstOrDefault(cate => cate.Category.Code.EqualsOrdinalIgnoreCase(categoryCode));

                    if (item == null)
                    {
                        break;
                    }
                }
            }

            return(item);
        }
コード例 #9
0
        private void EnsurePath(HierarchyViewModel hierarchy, HierarchyPath hierarchyPath, List <LoadCategoriesInstruction> loadCategoriesInstructions)
        {
            CatalogItemViewModel catalog = hierarchy.FirstOrDefault(cata => cata.Catalog.Code.EqualsOrdinalIgnoreCase(hierarchyPath.Catalog));

            if (catalog != null)
            {
                loadCategoriesInstructions.AddRange(
                    hierarchyPath.Categories
                    .Select((c, i) => new { Code = c, Index = i })
                    .Where(o => this.FindItem(hierarchy, new HierarchyPath(catalog.Catalog.Code, hierarchyPath.Categories.Take(o.Index + 1))) == null)
                    .Select(
                        o => new LoadCategoriesInstruction(
                            catalog.Catalog.CatalogId,
                            o.Index == 0 ? CatalogHierarchyServices.RootCategoryCode : hierarchyPath.Categories.ElementAtOrDefault(o.Index - 1),
                            this.CreateAppender(hierarchy, new HierarchyPath(catalog.Catalog.Code, hierarchyPath.Categories.Take(o.Index)))
                            )
                        )
                    );
            }
        }
コード例 #10
0
        private void Execute(HierarchyViewModel hierarchy, List <LoadCategoriesInstruction> loadCategoriesInstructions)
        {
            if (loadCategoriesInstructions.Any())
            {
                this._webStoreServices.UsingClient(
                    c =>
                {
                    IQueryable <CategoryHierarchy> categoryhierarchiesQuery = c.CatalogClient.CategoryHierarchies.Include(ch => ch.ParentCategory)
                                                                              .Include(ch => ch.Category.Catalog);

                    foreach (ICatalogEventHandler catalogEventHandler in this._catalogEventHandlers)
                    {
                        foreach (Expression <Func <CategoryHierarchy, Object> > include in catalogEventHandler.GetCategoriesInclusions())
                        {
                            categoryhierarchiesQuery = categoryhierarchiesQuery.Include(include);
                        }
                    }

                    CategoryHierarchy[] categoryhierarchies = categoryhierarchiesQuery.Where(this.GetConditions(loadCategoriesInstructions)).ToArray();

                    loadCategoriesInstructions.ForEach(
                        lci =>
                        lci.OnLoad(
                            categoryhierarchies.Where(
                                ch => ch.ParentCategory.Code.EqualsOrdinalIgnoreCase(lci.Parent) &&
                                ch.Category.CatalogId == lci.CatalogId
                                )
                            .OrderBy(ch => ch.Order)
                            .Select(ch => new CategoryItemViewModel {
                        Category = ch.Category
                    })
                            )
                        );
                }
                    );
            }
        }
コード例 #11
0
        private IEnumerable <CatalogItemViewModel> RefreshCatalogs(HierarchyViewModel hierarchy)
        {
            List <CatalogItemViewModel> previouslyLoadedCatalogs = hierarchy.ToList();

            this._webStoreServices.UsingClient(
                c =>
            {
                IQueryable <ExtendedCatalog> catalogsQuery = c.CatalogClient.Catalogs;

                foreach (ICatalogEventHandler catalogEventHandler in this._catalogEventHandlers)
                {
                    foreach (Expression <Func <ExtendedCatalog, Object> > include in catalogEventHandler.GetCatalogsInclusions())
                    {
                        catalogsQuery = catalogsQuery.Include(include);
                    }
                }

                ExtendedCatalog[] catalogs = catalogsQuery.ToArray();

                IEnumerable <CatalogItemViewModel> models = catalogs.OrderBy(cata => cata.Name)
                                                            .Select(
                    cata =>
                {
                    CatalogItemViewModel catalog = previouslyLoadedCatalogs.FirstOrDefault(pcata => pcata.Catalog.CatalogId == cata.CatalogId) ?? new CatalogItemViewModel();
                    catalog.Catalog = cata;
                    return(catalog);
                }
                    );

                hierarchy.Clear();
                hierarchy.AddRange(models);
            }
                );

            return(hierarchy.Where(cata => !previouslyLoadedCatalogs.Any(pcata => pcata.Catalog.CatalogId == cata.Catalog.CatalogId)));
        }
コード例 #12
0
 public void SetUp()
 {
     _hierarchyViewModel = new HierarchyViewModel();
 }
コード例 #13
0
 private CatalogItemViewModel GetCatalog(HierarchyViewModel hierarchy, CategoryItemViewModel category)
 {
     return(hierarchy.FirstOrDefault(cata => this.Contains(cata.Categories, category)));
 }
コード例 #14
0
 private void RegisterHierarchyForRequest(CatalogHierarchyPart part, HierarchyViewModel hierarchy)
 {
     this._orchardServices.WorkContext.HttpContext.Items[this.GetHierarchyRequestKey(part)] = hierarchy;
 }
コード例 #15
0
 private Action <IEnumerable <CategoryItemViewModel> > CreateAppender(HierarchyViewModel hierarchy, HierarchyPath hierarchyPath)
 {
     return(this.CreateAppender(() => this.FindItem(hierarchy, hierarchyPath)));
 }