Exemplo n.º 1
0
        public static void TreeEntityMove <T>(T t, MoveTreeModel model) where T : TreeEntity, new()
        {
            TreeLogic.FixRouteAndNames(t, model);
            t.Save();

            if (MixinDeclarations.IsDeclared(typeof(T), typeof(DisabledMixin)) && model.NewParent != null && model.NewParent.InDB(e => e.Mixin <DisabledMixin>().IsDisabled) && !t.Mixin <DisabledMixin>().IsDisabled)
            {
                t.Execute(DisableOperation.Disable);
            }
        }
Exemplo n.º 2
0
        private static SqlHierarchyId GetNewPosition <T>(MoveTreeModel model, TreeEntity entity)
            where T : TreeEntity
        {
            var newParentRoute = model.NewParent == null?SqlHierarchyId.GetRoot() : model.NewParent.InDB(a => a.Route);

            if (newParentRoute.IsDescendantOf(entity.Route))
            {
                throw new Exception(TreeMessage.ImpossibleToMove0InsideOf1.NiceToString(entity, model.NewParent));
            }

            if (model.InsertPlace == InsertPlace.FirstNode)
            {
                return(newParentRoute.GetDescendant(SqlHierarchyId.Null, FirstChild <T>(newParentRoute)));
            }

            if (model.InsertPlace == InsertPlace.LastNode)
            {
                return(newParentRoute.GetDescendant(LastChild <T>(newParentRoute), SqlHierarchyId.Null));
            }

            var newSiblingRoute = model.Sibling !.InDB(a => a.Route);

            if (!newSiblingRoute.IsDescendantOf(newParentRoute) ||
                newSiblingRoute.GetLevel() != newParentRoute.GetLevel() + 1 ||
                newSiblingRoute == entity.Route)
            {
                throw new Exception(TreeMessage.ImpossibleToMove01Of2.NiceToString(entity, model.InsertPlace.NiceToString(), model.NewParent));
            }

            if (model.InsertPlace == InsertPlace.After)
            {
                return(newParentRoute.GetDescendant(newSiblingRoute, Next <T>(newSiblingRoute)));
            }

            if (model.InsertPlace == InsertPlace.Before)
            {
                return(newParentRoute.GetDescendant(Previous <T>(newSiblingRoute), newSiblingRoute));
            }

            throw new InvalidOperationException("Unexpected InsertPlace " + model.InsertPlace);
        }
Exemplo n.º 3
0
        internal static void FixRouteAndNames <T>(T t, MoveTreeModel model)
            where T : TreeEntity
        {
            var list = t.Descendants().Where(c => c != t).ToList();

            var oldNode = t.Route;

            t.Route = GetNewPosition <T>(model, t);

            t.Save();
            CalculateFullName(t);
            t.Save();

            foreach (T h in list)
            {
                h.Route = h.Route.GetReparentedValue(oldNode, t.Route);
                h.Save();
                CalculateFullName(h);
                h.Save();
            }
        }