Beispiel #1
0
        public IActionResult UpdateMenu(Guid id, [FromBody] SysMenuCreateOrUpdateViewModel viewModel)
        {
            var response = ResponseModelFactory.CreateInstance;
            var data     = _sysMenuRepo.FindEntity(x => x.Name == viewModel.Name && x.Id != id);

            if (data != null)
            {
                response.SetFailed("菜单名已存在");
                return(Ok(response));
            }
            var entity = _sysMenuRepo.FindEntity(x => x.Id == id);

            if (entity == null)
            {
                response.SetNotFound();
                return(Ok(response));
            }
            viewModel.Icon = string.IsNullOrEmpty(viewModel.Icon) ? "md-menu" : viewModel.Icon;
            _mapper.Map(viewModel, entity);
            entity.Update();

            _sysMenuRepo.Update(entity);

            if (!_unitOfWork.Save())
            {
                response.SetFailed("编辑");
            }
            response.SetData(entity.Id);
            return(Ok(response));
        }
Beispiel #2
0
        public IActionResult CreateMenu([FromBody] SysMenuCreateOrUpdateViewModel viewModel)
        {
            var response = ResponseModelFactory.CreateInstance;
            var data     = _sysMenuRepo.FindEntity(x => x.Name == viewModel.Name);

            if (data != null)
            {
                response.SetFailed("菜单名已存在");
                return(Ok(response));
            }
            var createMenu = _mapper.Map <Sys_Menu>(viewModel);

            createMenu.IsDeleted = (int)CommonEnum.IsDeleted.No;
            createMenu.Icon      = string.IsNullOrEmpty(viewModel.Icon) ? "md-menu" : viewModel.Icon;
            createMenu.Create();

            _sysMenuRepo.Insert(createMenu);

            if (!_unitOfWork.Save())
            {
                response.SetFailed("创建失败");
            }
            response.SetData(createMenu.Id);
            return(Ok(response));
        }