public IActionResult EditAdminMenu(AdminMenu model)
        {
            if (!ModelState.IsValid)
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage));
                tip.Message = messages;
                return(Json(tip));
            }
            if (model.Id <= 0)
            {
                tip.Message = "错误参数传递!";
                return(Json(tip));
            }
            AdminMenu entity = AdminMenu.Find(AdminMenu._.Id == model.Id);

            if (entity == null)
            {
                tip.Message = "系统找不到本记录!";
                return(Json(tip));
            }
            //赋值
            entity.MenuName = model.MenuName;
            //如果key修改了。判断是否有存在
            if (entity.MenuKey != model.MenuKey)
            {
                if (AdminMenu.FindCount(AdminMenu._.MenuKey == model.MenuKey & AdminMenu._.Id != entity.Id, null, null, 0, 0) > 0)
                {
                    tip.Message = "您修改的菜单KEY已经存在,请填写其他的!";
                    return(Json(tip));
                }
                entity.MenuKey = model.MenuKey;
            }
            entity.Link      = model.Link;
            entity.IsHide    = model.IsHide;
            entity.ClassName = model.ClassName;
            entity.Rank      = model.Rank;
            if (entity.PId != model.PId)
            {
                //重新获取level和location
                entity.Level    = AdminMenu.GetNewLevel(model.PId);
                entity.Location = AdminMenu.GetNewLocation(model.PId);
            }
            entity.PId = model.PId;
            entity.Update();

            //处理权限
            IList <AdminMenuEvent> oldevent = AdminMenuEvent.FindAll(AdminMenuEvent._.MenuId == entity.Id, null, null, 0, 0);

            //所有的权限
            IList <TargetEvent> listevent = TargetEvent.FindAll(TargetEvent._.Id > 0, TargetEvent._.Rank.Asc(), null, 0, 0);

            //新的权限
            string[] eventkeys           = Request.Form["eventkey"];
            List <AdminMenuEvent> listme = new List <AdminMenuEvent>();

            if (eventkeys != null && eventkeys.Length > 0)
            {
                foreach (string s in eventkeys)
                {
                    if (Utils.IsInt(s))
                    {
                        TargetEvent te = listevent.FirstOrDefault(t => t.Id == int.Parse(s));
                        if (te != null)
                        {
                            AdminMenuEvent tmp = new AdminMenuEvent();
                            tmp.EventId   = te.Id;
                            tmp.EventKey  = te.EventKey;
                            tmp.EventName = te.EventName;
                            tmp.MenuKey   = model.MenuKey;
                            tmp.MenuId    = entity.Id;
                            listme.Add(tmp);
                        }
                    }
                }
            }

            //判断是否在旧的里面
            listme.ForEach(s =>
            {
                var oe = oldevent.FirstOrDefault(o => o.EventId == s.EventId);
                //如果是旧列表存在,则删掉旧列表里面的,然后更新自己
                if (oe != null)
                {
                    s.Id = oe.Id;
                    s.Update();
                    oldevent.Remove(oe);
                }
                else
                {
                    //如果不存在,则是新增的。直接新增处理
                    s.Insert();
                }
            });
            //如果还有,则删除旧列表里面的
            if (oldevent != null && oldevent.Count > 0)
            {
                oldevent.Delete();
            }

            tip.Status    = JsonTip.SUCCESS;
            tip.Message   = "编辑后台菜单成功";
            tip.ReturnUrl = "close";
            return(Json(tip));
        }