示例#1
0
 public ActionResult SaveMenu(SaveMenuModel model)
 {
     if (model.MenuId == 0)
     {
         var info = new AdminMenu
         {
             CreateDate = DateTime.Now,
             LinkUrl    = model.LinkUrl,
             MenuName   = model.MenuName,
             ParentId   = model.ParentId,
             SortOrder  = model.SortOrder,
         };
         _menusTask.Add(info);
         return(Json(new RequestResultDto()
         {
             Ret = 0, Msg = "添加成功"
         }));
     }
     else
     {
         var info = _menusTask.GetByMenuId((int)model.MenuId);
         if (info != null)
         {
             info.LinkUrl   = model.LinkUrl;
             info.MenuName  = model.MenuName;
             info.ParentId  = model.ParentId;
             info.SortOrder = model.SortOrder;
             _menusTask.Update(info);
         }
         return(Json(new RequestResultDto()
         {
             Ret = 0, Msg = "修改成功"
         }));
     }
 }
示例#2
0
        public ActionResult Create([FromForm] SaveMenuModel model)
        {
            // TODO: Add insert logic here
            //查询是否存在该菜单
            if (SystemMenuHelper.Exists(p => p.Name == model.ControllName && p.ActionRoute == model.ControllUrl))
            {
                return(Json(ResponseHelper.Error("该菜单已经存在了!")));
            }
            var MenuModel = new SystemMenu
            {
                ActionRoute = model.ControllUrl.ToLower(),
                CreatedTime = DateTime.Now,
                Icon        = model.Icon,
                IsUse       = Convert.ToBoolean(model.Status),
                Name        = model.ControllName,
                ParentId    = Convert.ToInt32(model.ParentCode),
                Remark      = model.Remark,
                Sort        = model.Sort,
                Type        = model.ControllType
            };
            var menuId = SystemMenuHelper.Insert(MenuModel);

            //给系统预留角色把权限绑上
            RoleAuthMappingHelper.Insert(new RoleAuthMapping {
                CreatedTime = DateTime.Now, MenuId = menuId, RoleId = 1
            });
            if (CacheUser.UId == "1")
            {
                CacheUser.AuthMenu.Add(menuId);
                HttpContext.Session.SetString("UserInfo", JsonConvert.SerializeObject(CacheUser));
            }
            return(Json(ResponseHelper.Success("ok")));
        }
示例#3
0
        public ActionResult SaveMenu(int?menuid)
        {
            var parentList = _menusTask.GetParentList().ToSelectList(c => c.MenuId.ToString(), c => c.MenuName);

            parentList.Insert(0, new SelectListItem {
                Text = "根菜单", Value = "0"
            });
            ViewData["ParentList"] = parentList;

            var model = new SaveMenuModel();

            if (menuid != null)
            {
                var info = _menusTask.GetByMenuId((int)menuid);
                if (info != null)
                {
                    model = EntityMapper.Map <AdminMenu, SaveMenuModel>(info);
                }
            }
            return(View(model));
        }
示例#4
0
        public ActionResult Edit([FromForm] SaveMenuModel model)
        {
            // TODO: Add update logic here
            var MenuModel = SystemMenuHelper.GetModel(model.Code);

            //查询是否存在该菜单
            if (SystemMenuHelper.Exists(p => p.Id != model.Code && p.Name == model.ControllName && p.ActionRoute == model.ControllUrl))
            {
                return(Json(new { status = 0, msg = "该菜单已经存在,请修改!" }));
            }
            MenuModel.Remark      = model.Remark;
            MenuModel.IsUse       = Convert.ToBoolean(model.Status);
            MenuModel.Name        = model.ControllName;
            MenuModel.Type        = model.ControllType;
            MenuModel.ActionRoute = model.ControllUrl.ToLower();
            MenuModel.Icon        = model.Icon;
            MenuModel.Sort        = model.Sort;
            MenuModel.ParentId    = Convert.ToInt32(model.ParentCode);
            SystemMenuHelper.Update(MenuModel);
            return(Json(ResponseHelper.Success("ok")));
        }
示例#5
0
        public ActionResult SaveMenu(SaveMenuModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.MenuId == null)
                {
                    var info = new AdminMenu
                    {
                        CreateDate = DateTime.Now,
                        LinkUrl    = model.LinkUrl,
                        MenuName   = model.MenuName,
                        ParentId   = model.ParentId,
                        SortOrder  = model.SortOrder,
                    };
                    _menusTask.Add(info);
                }
                else
                {
                    var info = _menusTask.GetByMenuId((int)model.MenuId);
                    if (info != null)
                    {
                        info.LinkUrl   = model.LinkUrl;
                        info.MenuName  = model.MenuName;
                        info.ParentId  = model.ParentId;
                        info.SortOrder = model.SortOrder;
                        _menusTask.Update(info);
                    }
                }
                return(AlertMsg("保存成功", Request.UrlReferrer.PathAndQuery));
            }

            var parentList = _menusTask.GetParentList().ToSelectList(c => c.MenuId.ToString(), c => c.MenuName);

            parentList.Insert(0, new SelectListItem {
                Text = "根菜单", Value = "0"
            });
            ViewData["ParentList"] = parentList;

            return(View(model));
        }