public async Task <IdentityResult> UpdateAsync(U user, CancellationToken cancellationToken) { _logger.LogDebug("UpdateAsync({0})", user.NormalizedEmail); // Was the NormalizedUserName modified? UserAddendum addendum = s_userAddendums.GetOrCreateValue(user); if (user.NormalizedUserName == addendum.NormalizedUserName) { // NormalizedUserName was not modified. The common and efficient case. return(await Rpc.TranslateExceptionsAsync(() => _datastore.UpsertAsync(UserToEntity(user), CallSettings.FromCancellationToken(cancellationToken)))); } Entity entity = UserToEntity(user); Entity indexEntity = new Entity() { Key = _nnindexKeyFactory.CreateKey(user.NormalizedUserName), [USER_KEY] = entity.Key }; var result = await InTransactionAsync(cancellationToken, async (transaction, callSettings) => { // NormalizedUserName was modified. Have to update the // index too. if (!string.IsNullOrEmpty(addendum.NormalizedUserName)) { transaction.Delete(_nnindexKeyFactory .CreateKey(addendum.NormalizedUserName)); } indexEntity[USER_KEY].ExcludeFromIndexes = true; transaction.Upsert(entity); transaction.Upsert(indexEntity); await transaction.CommitAsync(callSettings); }); if (result.Succeeded) { addendum.NormalizedUserName = user.NormalizedUserName; } return(result); }
public async Task <IdentityResult> DeleteAsync(R role, CancellationToken cancellationToken) { return(await Rpc.TranslateExceptionsAsync(() => _datastore.DeleteAsync(KeyFromRoleId(role.Id), CallSettings.FromCancellationToken(cancellationToken)))); }
public async Task <IdentityResult> CreateAsync(R role, CancellationToken cancellationToken) { return(await Rpc.TranslateExceptionsAsync(() => _datastore.InsertAsync(RoleToEntity(role), CallSettings.FromCancellationToken(cancellationToken)))); }