예제 #1
0
        private void UpdateTerritoryPosition(
            TerritoryPart territoryPart, TerritoryHierarchyPart hierarchyPart, TerritoryPart parentPart = null)
        {
            var context = new UpdateContentContext(territoryPart.ContentItem);

            _handlers.Invoke(handler => handler.Updating(context), Logger);
            if (parentPart == null)
            {
                _territoriesHierarchyService.AddTerritory(territoryPart, hierarchyPart); // move to root
            }
            else
            {
                _territoriesHierarchyService.AssignParent(territoryPart, parentPart);
            }
            _handlers.Invoke(handler => handler.Updated(context), Logger);
        }
        protected override void Importing(TerritoryPart part, ImportContentContext context)
        {
            // Set stuff in the record based off what is being imported
            if (context.Data.Element(part.PartDefinition.Name) == null)
            {
                return;
            }

            var hierarchyIdentity = context.Attribute(part.PartDefinition.Name, "HierarchyId");

            if (hierarchyIdentity == null)
            {
                part.Record.Hierarchy = null;
            }
            else
            {
                var ci        = context.GetItemFromSession(hierarchyIdentity);
                var hierarchy = ci.As <TerritoryHierarchyPart>();
                _territoriesHierarchyService.AddTerritory(part, hierarchy);
            }

            var parentIdentity = context.Attribute(part.PartDefinition.Name, "ParentTerritoryId");

            if (parentIdentity == null)
            {
                part.Record.ParentTerritory = null;
            }
            else
            {
                var ci     = context.GetItemFromSession(parentIdentity.ToString());
                var parent = ci.As <TerritoryPart>();
                _territoriesHierarchyService.AssignParent(part, parent);
            }


            var internalIdentity = context.Attribute(part.PartDefinition.Name, "TerritoryInternalRecordId");

            if (internalIdentity == null)
            {
                part.Record.TerritoryInternalRecord = null;
            }
            else
            {
                _territoriesHierarchyService.AssignInternalRecord(part, internalIdentity.ToString());
            }
        }
예제 #3
0
        public void AddTerritoryAddsToFirstLevel()
        {
            // this tests AddTerritory(TerritoryPart, TerritoryHierarchyPart)
            var territory = _contentManager.Create <TerritoryPart>("TerritoryType0");
            var hierarchy = _contentManager.Create <TerritoryHierarchyPart>("HierarchyType0");
            var parent    = _contentManager.Create <TerritoryPart>("TerritoryType0");

            _territoriesHierarchyService.AddTerritory(parent, hierarchy);
            Assert.That(parent.Record.ParentTerritory, Is.EqualTo(null));
            _territoriesHierarchyService.AddTerritory(territory, hierarchy);
            _territoriesHierarchyService.AssignParent(territory, parent);
            Assert.That(territory.Record.Hierarchy.Id, Is.EqualTo(hierarchy.Record.Id));
            Assert.That(territory.Record.ParentTerritory.Id, Is.EqualTo(parent.Record.Id));

            _territoriesHierarchyService.AddTerritory(territory, hierarchy);
            Assert.That(territory.Record.ParentTerritory, Is.EqualTo(null));
        }