public TerritoryPart SingleTerritory(int internalId) { return(_territoriesService.GetTerritoriesQuery(ConfiguredHierarchy) .Where(tpr => tpr.TerritoryInternalRecord.Id == internalId) .Slice(0, 1) .FirstOrDefault()); }
public ActionResult Index(int id) { ActionResult redirectTo; if (ShouldRedirectForPermissions(id, out redirectTo)) { return(redirectTo); } // list the first level of territories for the selected hierarchy // The null checks for these objects are done in ShouldRedirectForPermissions var hierarchyItem = _contentManager.Get(id, VersionOptions.Latest); var hierarchyPart = hierarchyItem.As <TerritoryHierarchyPart>(); var topLevelOfHierarchy = _territoriesService .GetTerritoriesQuery(hierarchyPart, null, VersionOptions.Latest) .List().ToList(); var model = new TerritoryHierarchyTerritoriesViewModel { HierarchyPart = hierarchyPart, HierarchyItem = hierarchyItem, TopLevelNodes = topLevelOfHierarchy.Select(MakeANode).ToList(), Nodes = _territoriesService. GetTerritoriesQuery(hierarchyPart, VersionOptions.Latest) .List().Select(MakeANode).ToList(), CanAddMoreTerritories = _territoriesService .GetAvailableTerritoryInternals(hierarchyPart) .Any() }; return(View(model)); }
public void GetTerritoryQueriesThrowExceptionForNullHierarchy() { Assert.Throws <ArgumentNullException>(() => _territoriesService.GetTerritoriesQuery(null)); var hierarchy = _contentManager.Create <TerritoryHierarchyPart>("HierarchyType0"); hierarchy.Record = null; Assert.Throws <ArgumentException>(() => _territoriesService.GetTerritoriesQuery(hierarchy)); }
protected override DriverResult Editor(TerritoryHierarchyPart part, dynamic shapeHelper) { var shapes = new List <DriverResult>(); //part.Id == 0: new item if (part.Id != 0) { //if the part is fully configured add a shape that allows managing the territories in the hierarchy if (!string.IsNullOrWhiteSpace(part.TerritoryType)) { if (_territoriesService.GetTerritoryTypes().Any(tt => tt.Name == part.TerritoryType)) { // add the shape for the territories in the hierachy shapes.Add(ContentShape("Parts_TerritoryHierarchy_TerritoryManager", () => shapeHelper.EditorTemplate( TemplateName: "Parts/TerritoryHierarchyTerritoryManager", Model: new TerritoryHierarchyTerritoryManagerViewModel(part) { TopLevelCount = _territoriesService .GetTerritoriesQuery(part, null, VersionOptions.Latest) .Count() }, Prefix: Prefix ))); } else { _notifier.Warning(T("You are not allowed to manage the territories for this hierarchy.")); } } } //add a shape for configuration of the part //Some configuration options may be locked depending on the territories in the hierarchy //e.g. once there are territories, we cannot change the TerritoryType anymore shapes.Add(ContentShape("Parts_TerritoryHierarchy_TerritoryTypeSelection", () => shapeHelper.EditorTemplate( TemplateName: "Parts/TerritoryHierarchyTerritoryTypeSelection", Model: TypeSelectionVM(part), Prefix: Prefix ))); return(Combined(shapes.ToArray())); }