Ejemplo n.º 1
0
        /// <summary>
        /// 删除该节点以及该节点一下的所有数据
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <returns></returns>
        public bool Deletes(Expression <Func <TopMenus, bool> > whereLambda)
        {
            using (var db = new FrameContext())
            {
                var list       = GetAll();
                var entity     = BaseService.Find(db, whereLambda);
                var deleteList = new List <TopMenus>();
                CommonManage.GetAllChildrenItem(list, entity.Id, deleteList);

                using (var scope = new TransactionScope())
                {
                    deleteList.ForEach(a =>
                    {
                        BaseService.Delete(db, a);
                    });
                    BaseService.Delete(db, entity);

                    scope.Complete();
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 删除该节点以及该节点一下的所有数据
        /// </summary>
        /// <param name="whereLambda"></param>
        /// <returns></returns>
        public CommandResult <List <LeftMenus> > Deletes(Expression <Func <LeftMenus, bool> > whereLambda)
        {
            var result = new CommandResult <List <LeftMenus> >();

            using (var db = new FrameContext())
            {
                var list   = GetAll();
                var entity = BaseService.Find(db, whereLambda);
                if (entity.Sys)
                {
                    result.Message = $"菜单“{entity.DisplayName}”为系统级菜单,不允许删除";
                }
                else if (list.Any(a => a.Sys))
                {
                    result.Message = $"菜单“{entity.DisplayName}”子目录下包含系统级菜单,请重新选择";
                }
                else
                {
                    var deleteList = new List <LeftMenus>();
                    CommonManage.GetAllChildrenItem(list, entity.Id, deleteList);

                    using (var scope = new TransactionScope())
                    {
                        deleteList.ForEach(a =>
                        {
                            BaseService.Delete(db, a);
                        });
                        BaseService.Delete(db, entity);

                        scope.Complete();
                    }

                    result.ResultStatus = ResultStatus.Success;
                    result.Data.Add(entity);
                    deleteList.ForEach(result.Data.Add);
                }
            }
            return(result);
        }