Exemplo n.º 1
0
 public async Task <IActionResult> AddNewMenu([FromBody] MenuViewModel menu)
 {
     try
     {
         return(Ok(await _trasection.AddMenu(menu)));
     }
     catch (Exception)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError,
                           "Error occure during Registeration"));
     }
 }
Exemplo n.º 2
0
        public BasicResponse <MenuInfo> AddMenu(MenuAddRequest menurequest)
        {
            MenuInfo menuDTO        = menurequest.MenuInfo;
            string   menuCode       = "001"; //菜单编码
            string   parentMenuCode = "";    //父菜单编码
            short    menuMemo       = 0;     //菜单标志
            string   menuSort       = "0";

            if (string.IsNullOrEmpty(menuDTO.MenuName))
            {
                ThrowException("AddMenu", new Exception("模块名称必须输入!"));
            }
            if (string.IsNullOrEmpty(menuDTO.MenuParent))
            {
                ThrowException("AddMenu", new Exception("请选择模块上级模块!"));
            }
            if (!string.IsNullOrEmpty(menuDTO.MenuFile))
            {
                if (!menuDTO.MenuFile.Contains(".dll") && !menuDTO.MenuFile.Contains(".exe"))
                {
                    ThrowException("AddMenu", new Exception("菜单引用文件必须是dll文件或者是exe文件!"));
                }
            }
            parentMenuCode = GetMenuCodeByMenuName(menuDTO.MenuParent.Trim());
            List <MenuModel> MenuList    = _Repository.GetMenuList();
            List <MenuModel> SonMenuList = new List <MenuModel>();

            if (string.IsNullOrEmpty(parentMenuCode))//一级目录
            {
                SonMenuList = MenuList.FindAll(a => a.MenuMemo == -1).OrderByDescending(a => a.MenuCode).ToList();
                if (SonMenuList.Count > 0)
                {
                    //将此一级目录加在当前最后一个一级目录的后面
                    menuCode = (int.Parse(SonMenuList[0].MenuCode) + 1).ToString("000");
                    menuSort = (int.Parse(SonMenuList[0].MenuCode) + 1).ToString();
                }
                else
                {
                    menuSort = "1";
                }
                menuMemo = -1;
            }
            else//子模块
            {
                SonMenuList = MenuList.FindAll(a => a.MenuParent == parentMenuCode).OrderByDescending(a => a.MenuCode).ToList();
                if (SonMenuList.Count > 0)
                {
                    //将此一级目录加在当前最后一个一级目录的后面
                    menuCode = parentMenuCode.ToString() +
                               (int.Parse(SonMenuList[0].MenuCode.Substring(parentMenuCode.Length + 1)) + 1).ToString("000");
                    menuSort = (int.Parse(SonMenuList[0].MenuCode.Substring(parentMenuCode.Length + 1)) + 1).ToString();
                }
                else
                {
                    //当前模块是父模块的第一个模块
                    menuCode = parentMenuCode.ToString() + "001";
                    menuSort = "1";
                }
            }
            menuDTO.MenuCode   = menuCode;
            menuDTO.MenuMemo   = menuMemo;
            menuDTO.MenuSort   = menuSort;
            menuDTO.MenuParent = parentMenuCode;

            //判断菜单名是否存在,只有不存在才能插入
            if (CheckMenuNameExist(menuDTO.MenuName))
            {
                ThrowException("AddMenu", new Exception(String.Format("菜单名:{0} 已存在,请重新输入!", menuDTO.MenuName)));
            }

            var _menu        = ObjectConverter.Copy <MenuInfo, MenuModel>(menuDTO);
            var resultmenu   = _Repository.AddMenu(_menu);
            var menuresponse = new BasicResponse <MenuInfo>();

            menuresponse.Data = ObjectConverter.Copy <MenuModel, MenuInfo>(resultmenu);
            return(menuresponse);
        }
Exemplo n.º 3
0
 public int AddUpdateMenu(MenuViewModel menuVm)
 {
     return(menuVm.Id == 0 ? _menuRepository.AddMenu(menuVm.ToModel()) : _menuRepository.EditMenu(menuVm.ToModel()));
 }