Esempio n. 1
0
 private void AddChildren(List<DepartmentSelectionItemViewModel> result, DepartmentSelectionItemViewModel parentViewModel, IEnumerable<ShortDepartment> models, ref int index)
 {
     if (parentViewModel.Model.ChildDepartments != null && parentViewModel.Model.ChildDepartments.Count > 0)
     {
         var children = models.Where(x => x.ParentDepartmentUID == parentViewModel.Model.UID).ToList();
         foreach (var child in children)
         {
             var itemViewModel = new DepartmentSelectionItemViewModel(child);
             itemViewModel.Level = parentViewModel.Level + 1;
             itemViewModel.ParentUID = parentViewModel.UID;
             itemViewModel.IsLeaf = true;
             parentViewModel.IsLeaf = false;
             result.Insert(index + 1, itemViewModel);
             index++;
             AddChildren(result, itemViewModel, models, ref index);
             itemViewModel.IsExpanded = !itemViewModel.IsLeaf;   // если был добавлен дочерний элемент, то разворачиваем
         }
     }
 }
Esempio n. 2
0
        public JsonResult GetDepartments(Guid organisationUID, Guid? departmentUID)
        {
            var operationResult = DepartmentHelper.Get(new DepartmentFilter
            {
                OrganisationUIDs = new List<Guid> { organisationUID },
                ExceptUIDs = (departmentUID.HasValue && departmentUID.Value != Guid.Empty ? new List<Guid> { departmentUID.Value } : new List<Guid> ())
            });

            var departments = new List<DepartmentSelectionItemViewModel>();
            foreach (var rootItem in operationResult.Where(d => d.ParentDepartmentUID == null || d.ParentDepartmentUID == Guid.Empty))
            {
                var itemViewModel = new DepartmentSelectionItemViewModel(rootItem);
                itemViewModel.Level = 0;
                itemViewModel.ParentUID = Guid.Empty;
                itemViewModel.IsLeaf = true;
                departments.Add(itemViewModel);
                int index = departments.IndexOf(itemViewModel);
                AddChildren(departments, itemViewModel, operationResult, ref index);
                itemViewModel.IsExpanded = !itemViewModel.IsLeaf;   // если был добавлен дочерний элемент, то разворачиваем
            }

            dynamic result = new
            {
                page = 1,
                total = 100,
                records = 100,
                rows = departments,
            };

            return Json(result, JsonRequestBehavior.AllowGet);
        }