Ejemplo n.º 1
0
        public JsonResult AddMainType(string dbName, string ParentId, string FullId)
        {
            MF_MainType mainType = new MF_MainType();

            mainType.Id = GuidHelper.CreateTimeOrderID();

            //非顶部节点
            if (ParentId != dbName)
            {
                mainType.ParentId = ParentId;
            }

            mainType.FullId = FullId + "." + mainType.Id;
            mainType.DBName = dbName;
            mainType.Text   = "新增节点";
            UnitOfWork.Add(mainType);
            UnitOfWork.Commit();
            return(Json(mainType));
        }
Ejemplo n.º 2
0
        public JsonResult MoveMainType(string sourceID, string targetID, string point)
        {
            var source = UnitOfWork.GetByKey <MF_MainType>(sourceID);

            if (point == "append")
            {
                MF_MainType maxOrderItem = null;
                if (targetID == CommonStr.MainTypeTreeRootID)
                {
                    source.ParentId = null;
                    source.FullId   = source.Id;
                    maxOrderItem    = UnitOfWork.Get <MF_MainType>(a => a.ParentId == null).OrderByDescending(a => a.OrderIndex).FirstOrDefault();
                }
                else
                {
                    var target = UnitOfWork.GetByKey <MF_MainType>(targetID);
                    maxOrderItem = UnitOfWork.Get <MF_MainType>(a => a.ParentId == targetID).OrderByDescending(a => a.OrderIndex).FirstOrDefault();

                    source.ParentId = targetID;
                    source.FullId   = target.FullId + "." + source.Id;
                }

                source.OrderIndex = 0;
                if (maxOrderItem != null)
                {
                    source.OrderIndex = maxOrderItem.OrderIndex + 1;
                }
            }
            else if (point == "top")
            {
                var target    = UnitOfWork.GetByKey <MF_MainType>(targetID);
                var targetPre = UnitOfWork.Get <MF_MainType>(a => a.ParentId == target.ParentId && a.OrderIndex < target.OrderIndex)
                                .OrderByDescending(a => a.OrderIndex).FirstOrDefault();

                double orderIndex = 0;
                if (targetPre != null)
                {
                    orderIndex = (targetPre.OrderIndex + target.OrderIndex) / 2;
                }
                else
                {
                    orderIndex = target.OrderIndex - 1;
                }

                source.OrderIndex = orderIndex;
                source.ParentId   = target.ParentId;
                if (!string.IsNullOrEmpty(target.ParentId))
                {
                    source.FullId = target.Parent.FullId + "." + source.Id;
                }
                else
                {
                    source.FullId = source.Id;
                }
            }
            else if (point == "bottom")
            {
                var target     = UnitOfWork.GetByKey <MF_MainType>(targetID);
                var targetNext = UnitOfWork.Get <MF_MainType>(a => a.ParentId == target.ParentId && a.OrderIndex > target.OrderIndex)
                                 .OrderBy(a => a.OrderIndex).FirstOrDefault();

                double orderIndex = 0;
                if (targetNext != null)
                {
                    orderIndex = (targetNext.OrderIndex + target.OrderIndex) / 2;
                }
                else
                {
                    orderIndex = target.OrderIndex + 1;
                }

                source.OrderIndex = orderIndex;
                source.ParentId   = target.ParentId;
                if (!string.IsNullOrEmpty(target.ParentId))
                {
                    source.FullId = target.Parent.FullId + "." + source.Id;
                }
                else
                {
                    source.FullId = source.Id;
                }
            }
            return(Json(UnitOfWork.Commit()));
        }