public async Task <ApiRequestResult> AddAsync(MenuDto dto) { var menu = dto.EntityMap <MenuDto, Menu>(); await _menuRepository.AddAsync(menu); return(ApiRequestResult.Success("添加成功")); }
public async Task <IResultModel> Add(MenuAddModel model) { var menu = _mapper.Map <MenuEntity>(model); //根据父节点的等级+1设置当前菜单的等级 if (menu.ParentId != Guid.Empty) { var parentMenu = await _menuRepository.GetAsync(model.ParentId); if (parentMenu == null) { return(ResultModel.Failed("父节点不存在")); } menu.Level = parentMenu.Level + 1; } if (menu.Type == MenuType.Node) { menu.Target = MenuTarget.UnKnown; } if (await _menuRepository.AddAsync(menu)) { await ClearAccountPermissionCache(menu); return(ResultModel.Success(menu.Id)); } return(ResultModel.Failed()); }
public async Task <IResultModel> Add(MenuAddModel model) { var menu = _mapper.Map <MenuEntity>(model); if (await _menuRepository.ExistsNameByParentId(menu.Name, menu.Id, menu.ParentId)) { return(ResultModel.Failed($"节点名称“{menu.Name}”已存在")); } //根据父节点的等级+1设置当前菜单的等级 if (menu.ParentId != Guid.Empty) { var parentMenu = await _menuRepository.GetAsync(model.ParentId); if (parentMenu == null) { return(ResultModel.Failed("父节点不存在")); } menu.Level = parentMenu.Level + 1; } if (menu.Type == MenuType.Node) { menu.Target = MenuTarget.UnKnown; } if (await _menuRepository.AddAsync(menu)) { return(ResultModel.Success()); } return(ResultModel.Failed()); }
public Task <IActionResult> Add(Menu model) { return(Task.Factory.StartNew <IActionResult>(() => { if (!ModelState.IsValid) { return Json(ExcutedResult.FailedResult("数据验证失败")); } MenuRepository.AddAsync(model, false); return Json(ExcutedResult.SuccessResult()); })); }
public async Task <IResultModel> Add(MenuAddModel model) { var menu = _mapper.Map <Menu>(model); try { _uow.BeginTransaction(); if (await _menuRepository.ExistsNameByParentId(menu.Name, menu.Id, menu.ParentId)) { _uow.Rollback(); return(ResultModel.Failed($"节点名称“{menu.Name}”已存在")); } //根据父节点的等级+1设置当前菜单的等级 if (menu.ParentId != Guid.Empty) { var parentMenu = await _menuRepository.GetAsync(model.ParentId); if (parentMenu == null) { _uow.Rollback(); return(ResultModel.Failed("父节点不存在")); } menu.Level = parentMenu.Level + 1; } menu.RouteName = menu.RouteName?.ToLower(); if (menu.Type == MenuType.Node) { menu.Target = MenuTarget.UnKnown; } if (await _menuRepository.AddAsync(menu)) { _uow.Commit(); return(ResultModel.Success()); } _uow.Rollback(); return(ResultModel.Failed()); } catch { _uow.Rollback(); throw; } }
public async Task <ResultEntity> AddOrUpdateAsync(Menu menu) { var result = new ResultEntity(); if (menu.Id > 0) { _menuRepository.Update(menu); } else { await _menuRepository.AddAsync(menu); } result.Success = true; return(result); }
public async Task <IResultModel> Add(MenuAddModel model) { var menu = _mapper.Map <MenuEntity>(model); //根据父节点的等级+1设置当前菜单的等级 if (menu.ParentId != Guid.Empty) { var parentMenu = await _menuRepository.GetAsync(model.ParentId); if (parentMenu == null) { return(ResultModel.Failed("父节点不存在")); } menu.Level = parentMenu.Level + 1; } if (menu.Type == MenuType.Node) { menu.Target = MenuTarget.UnKnown; } using (var tran = _menuRepository.BeginTransaction()) { if (await _menuRepository.AddAsync(menu, tran)) { //同步菜单权限 if (await SyncPermission(menu, model.Permissions, tran)) { //同步按钮 if (await SyncButton(menu, model.Buttons, tran)) { tran.Commit(); await ClearAccountPermissionCache(entity); return(ResultModel.Success()); } } } } return(ResultModel.Failed()); }
public async Task <MenuResponse> SaveAsync(Menu menu, int userId) { var existingUser = await _userCommonRepository.FindById(userId); if (existingUser == null) { return(new MenuResponse("User not found")); } menu.UserCommon = existingUser; try { await _menuRepository.AddAsync(menu); return(new MenuResponse(menu)); } catch (Exception ex) { return(new MenuResponse( $"An error ocurred while saving the menu: {ex.Message}")); } }