Пример #1
0
        /// <summary>
        /// Updates an existing token.
        /// </summary>
        /// <param name="token">The token to update.</param>
        /// <param name="cancellationToken">The <see cref="CancellationToken"/> that can be used to abort the operation.</param>
        /// <returns>
        /// A <see cref="Task"/> that can be used to monitor the asynchronous operation.
        /// </returns>
        public virtual async Task UpdateAsync(OpenIddictToken token, CancellationToken cancellationToken)
        {
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }

            await _dynamoDb.UpdateItemAsync(TableName, new Dictionary <string, AttributeValue> {
                { "Id", new AttributeValue(token.Id) },
            }, new Dictionary <string, AttributeValueUpdate> {
                { "ApplicationId", new AttributeValueUpdate(DynamoDBHelper.CreateAttributeVale(token.ApplicationId),
                                                            AttributeAction.PUT) },
                { "AuthorizationId", new AttributeValueUpdate(DynamoDBHelper.CreateAttributeVale(token.AuthorizationId),
                                                              AttributeAction.PUT) },
                { "Subject", new AttributeValueUpdate(new AttributeValue(token.Subject),
                                                      AttributeAction.PUT) },
                { "Type", new AttributeValueUpdate(new AttributeValue(token.Type),
                                                   AttributeAction.PUT) }
            });
        }
Пример #2
0
        public async Task <IdentityResult> CreateAsync(UserInfo user, CancellationToken cancellationToken)
        {
            var request = new UpdateItemRequest
            {
                Key = new Dictionary <string, AttributeValue>()
                {
                    { "Id", new AttributeValue {
                          N = "-1"
                      } }
                },
                ExpressionAttributeValues = new Dictionary <string, AttributeValue>()
                {
                    { ":incr", new AttributeValue {
                          N = "1"
                      } }
                },
                UpdateExpression = "SET UserCounter = UserCounter + :incr",
                TableName        = "Users",
                ReturnValues     = "UPDATED_NEW" // Give me all attributes of the updated item.
            };
            var response = await _dynamoDb.UpdateItemAsync(request);

            var userId = response.Attributes["UserCounter"].N;

            await _dynamoDb.PutItemAsync("Users", new Dictionary <string, AttributeValue>
            {
                { "Id", new AttributeValue {
                      N = userId
                  } },
                { "UserName", new AttributeValue(user.UserName) },
                { "Email", new AttributeValue(user.Email) },
                { "PasswordHash", new AttributeValue(user.PasswordHash) }
            },
                                         cancellationToken);

            user.Id = userId;

            return(IdentityResult.Success);
        }