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 GetAvailableTerritoryInternalsThrowsTheExpectedArgumentNullExceptions() { Assert.Throws <ArgumentNullException>(() => _territoriesService.GetAvailableTerritoryInternals(null)); var hierarchy = _contentManager.Create <TerritoryHierarchyPart>("HierarchyType0"); hierarchy.Record = null; Assert.Throws <ArgumentException>(() => _territoriesService.GetAvailableTerritoryInternals(hierarchy)); }
private IEnumerable <DriverResult> CreationEditor(TerritoryPart part, dynamic shapeHelper) { var shapes = new List <DriverResult>(); // We don't know the Hierarchy for this territory here, so we try to get it from // the CreationHierarchy property of the part. We will need it validate a list of // allowed TerritoryInternalRecord var hierarchy = part.CreationHierarchy; if (hierarchy == null) { // We don't really have a hierarchy after all InvalidHierarchyOnCreation(); } else { // Healthy situation var territoryInternals = _territoriesService.GetAvailableTerritoryInternals(hierarchy).ToList(); if (territoryInternals.Any()) { // There are TerritoryInternalRecords we can pick from shapes.Add(ContentShape("Parts_TerritoryPart_Creation", () => shapeHelper.EditorTemplate( TemplateName: "Parts/TerritoryPartCreation", Model: new TerritoryPartViewModel() { AvailableTerritoryInternalRecords = territoryInternals, Hierarchy = hierarchy }, Prefix: Prefix ))); } else { // There is no TerritoryInternalRecord available // This is also verified in the HierarchyTerritoriesAdminController call. However, something // has clearly happened in the meanwhile. _notifier.Error(T("There are no territories that may be added to hierarchy. Content creation will fail.")); } } return(shapes); }