Exemplo n.º 1
0
        public void AddOrUpdateMenu(int?id, AddOrUpdateMenuInput input)
        {
            if (id.HasValue)
            {
                var parentMenu = input.ParentIdList;
                var menu       = _menuRepository.FirstOrDefault(t => t.Id == id);
                if (menu == null)
                {
                    throw new BusinessException($"未找到数据");
                }
                var hasUri = _menuRepository.GetAll().Any(t => t.Uri == input.Uri.Trim() && input.MenuType == t.MenuType && id != t.Id);
                if (hasUri)
                {
                    throw new BusinessException($"资源标识重复,请修改");
                }
                var hasCode = _menuRepository.GetAll().Any(t => t.Code == input.Code && input.MenuType == t.MenuType && id != t.Id);
                if (hasCode)
                {
                    throw new BusinessException($"菜单编号识重复,请修改");
                }
                var updateEntity = ObjectMapper.Map(input, menu);
                updateEntity.IsActive = input.IsActive;
                updateEntity.ParentId = parentMenu == null || parentMenu.Length < 1 ? null : parentMenu.Last();
                _menuRepository.Update(updateEntity);

                _cache.Remove(AdmConsts.ROLE_URI_CACHE);
            }
            else
            {
                var hasUri = _menuRepository.GetAll().Any(t => t.Uri == input.Uri.Trim() && input.MenuType == t.MenuType);
                if (hasUri)
                {
                    throw new BusinessException($"资源标识重复,请修改");
                }
                var hasCode = _menuRepository.GetAll().Any(t => t.Code == input.Code && input.MenuType == t.MenuType);
                if (hasCode)
                {
                    throw new BusinessException($"菜单编号识重复,请修改");
                }
                var parentMenu = input.ParentIdList;
                var menu       = ObjectMapper.Map <Menu>(input);
                menu.Status   = SysStatus.效;
                menu.Uri      = input.Uri.Trim();
                menu.ParentId = parentMenu == null || parentMenu.Length < 1 ? null : parentMenu.Last();
                _menuRepository.Insert(menu);
            }
        }
Exemplo n.º 2
0
 public IActionResult UpdateRole(int id, [FromBody] AddOrUpdateMenuInput input)
 {
     _menuService.AddOrUpdateMenu(id, input);
     return(Ok(ResponseBody.From("修改成功")));
 }
Exemplo n.º 3
0
 public IActionResult AddMenu([FromBody] AddOrUpdateMenuInput input)
 {
     _menuService.AddOrUpdateMenu(null, input);
     return(Ok(ResponseBody.From("保存成功")));
 }