示例#1
0
        public async Task <AppSrvResult> UpdateAsync(long id, MenuUpdationDto input)
        {
            var allMenus = await _cacheService.GetAllMenusFromCacheAsync();

            var isExistsCode = allMenus.Any(x => x.Code == input.Code && x.Id != id);

            if (isExistsCode)
            {
                return(Problem(HttpStatusCode.BadRequest, "该菜单编码已经存在"));
            }

            var isExistsName = allMenus.Any(x => x.Name == input.Name && x.Id != id);

            if (isExistsName)
            {
                return(Problem(HttpStatusCode.BadRequest, "该菜单名称已经存在"));
            }

            var parentMenu = allMenus.FirstOrDefault(x => x.Code == input.PCode);
            var updateDto  = ProducePCodes(input, parentMenu);
            var menu       = Mapper.Map <SysMenu>(updateDto);

            menu.Id = id;

            var updatingProps = UpdatingProps <SysMenu>(
                x => x.Code
                , x => x.Component
                , x => x.Hidden
                , x => x.Icon
                , x => x.IsMenu
                , x => x.IsOpen
                , x => x.Levels
                , x => x.Name
                , x => x.Ordinal
                , x => x.PCode
                , x => x.PCodes
                , x => x.Status
                , x => x.Tips
                , x => x.Url
                );

            await _menuRepository.UpdateAsync(menu, updatingProps);

            return(AppSrvResult());
        }
示例#2
0
 public async Task <ActionResult> UpdateAsync([FromRoute] long id, [FromBody] MenuUpdationDto input)
 {
     return(Result(await _menuService.UpdateAsync(id, input)));
 }