public async Task <IResultModel> Update(AccountUpdateModel model) { var entity = await _accountRepository.GetAsync(model.Id); if (entity == null) { return(ResultModel.Failed("账户不存在!")); } if (entity.IsLock) { return(ResultModel.Failed("账户锁定,不允许修改")); } var account = _mapper.Map(model, entity); var exists = await Exists(account); if (!exists.Successful) { return(exists); } using (var uow = _dbContext.NewUnitOfWork()) { var result = await _accountRepository.UpdateAsync(account, uow); if (result) { result = await _accountRoleRepository.DeleteByAccount(account.Id, uow); if (result) { if (model.Roles != null && model.Roles.Any()) { var accountRoleList = model.Roles.Select(m => new AccountRoleEntity { AccountId = account.Id, RoleId = m }).ToList(); result = await _accountRoleRepository.AddAsync(accountRoleList, uow); } if (result) { uow.Commit(); await ClearPermissionListCache(account.Id); await ClearCache(true, entity.Id); return(ResultModel.Success()); } } } } return(ResultModel.Failed()); }
public async Task <IResultModel> Update(AccountUpdateModel model) { var entity = await _accountRepository.GetAsync(model.Id); if (entity == null) { return(ResultModel.Failed("账户不存在!")); } if (entity.IsLock) { return(ResultModel.Failed("账户锁定,不允许修改")); } var account = _mapper.Map(model, entity); var exists = await Exists(account); if (!exists.Successful) { return(exists); } using (var tran = _accountRepository.BeginTransaction()) { var result = await _accountRepository.UpdateAsync(account, tran); if (result) { result = await _accountRoleRepository.DeleteByAccount(account.Id, tran); if (result) { if (model.Roles != null && model.Roles.Any()) { var accountRoleList = model.Roles.Select(m => new AccountRoleEntity { AccountId = account.Id, RoleId = m }).ToList(); if (await _accountRoleRepository.AddAsync(accountRoleList, tran)) { tran.Commit(); ClearPermissionListCache(account.Id); return(ResultModel.Success()); } } else { tran.Commit(); ClearPermissionListCache(account.Id); return(ResultModel.Success()); } } } } return(ResultModel.Failed()); }