public async Task <IResultModel> BindPermission(ButtonBindPermissionModel model) { _uow.BeginTransaction(); //删除旧数据 if (await _buttonPermissionRepository.RemoveByButtonId(model.Id)) { if (model.PermissionList == null || !model.PermissionList.Any()) { _uow.Commit(); await ClearAccountPermissionCache(model.Id); return(ResultModel.Success()); } //添加新数据 var entityList = new List <ButtonPermission>(); model.PermissionList.ForEach(p => { entityList.Add(new ButtonPermission { ButtonId = model.Id, PermissionId = p }); }); if (await _buttonPermissionRepository.AddAsync(entityList)) { _uow.Commit(); await ClearAccountPermissionCache(model.Id); return(ResultModel.Success()); } } _uow.Rollback(); return(ResultModel.Failed()); }
/// <summary> /// 同步按钮权限 /// </summary> /// <param name="button"></param> /// <param name="permissions"></param> /// <param name="transaction"></param> /// <returns></returns> private async Task <bool> SyncButtonPermission(ButtonEntity button, List <string> permissions, IDbTransaction transaction) { //删除旧数据 if (await _buttonPermissionRepository.DeleteByButton(button.Code, transaction)) { if (permissions == null || !permissions.Any()) { return(true); } //添加新数据 var entityList = new List <ButtonPermissionEntity>(); permissions.ForEach(code => { entityList.Add(new ButtonPermissionEntity { ButtonCode = button.Code, PermissionCode = code.ToLower() }); }); if (await _buttonPermissionRepository.AddAsync(entityList, transaction)) { return(true); } } return(false); }