public async Task <IResultModel> BindMenuPermission(RoleMenuPermissionBindModel model) { if (!await _roleRepository.ExistsAsync(m => m.Id == model.RoleId)) { return(ResultModel.Failed("½ÇÉ«²»´æÔÚ")); } var menus = new List <RoleMenuEntity>(); var permissions = new List <RolePermissionEntity>(); if (model.Menus != null && model.Menus.Any()) { menus = model.Menus.Select(m => new RoleMenuEntity { RoleId = model.RoleId, MenuId = m.MenuId, MenuChecked = m.MenuChecked }).ToList(); } foreach (var menu in model.Menus) { foreach (var button in menu.Buttons) { if (button.Checked) { var per = _mapper.Map <RolePermissionEntity>(button); per.RoleId = model.RoleId; permissions.Add(per); } } } try { _dbContext.Db.BeginTran(); await _roleMenuRepository.DeleteAsync(m => m.RoleId == model.RoleId, _dbContext.Db); if (menus.Any()) { await _roleMenuRepository.InsertRangeAsync(menus, _dbContext.Db); } await _rolePermissionRepository.DeleteAsync(m => m.RoleId == model.RoleId, _dbContext.Db); if (permissions.Any()) { await _rolePermissionRepository.InsertRangeAsync(permissions, _dbContext.Db); } _dbContext.Db.CommitTran(); } catch (Exception ex) { _dbContext.Db.RollbackTran(); return(ResultModel.Failed(ex.Message)); } return(ResultModel.Success()); }
public async Task <OperationResponse> DeleteAsync() { var response = await _roleMenuRepository.DeleteAsync(new Guid()); return(response); }