internal Document PutItemHelper(Document doc, PutItemOperationConfig config, bool isAsync)
{
var currentConfig = config ?? new PutItemOperationConfig();
PutItemRequest req = new PutItemRequest
{
TableName = TableName,
Item = doc.ToAttributeMap(Conversion)
};
((Amazon.Runtime.Internal.IAmazonWebServiceRequest)req).AddBeforeRequestHandler(isAsync ?
new RequestEventHandler(UserAgentRequestEventHandlerAsync) :
new RequestEventHandler(UserAgentRequestEventHandlerSync));
if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
req.ReturnValues = EnumMapper.Convert(currentConfig.ReturnValues);
ValidateConditional(currentConfig);
if (currentConfig.Expected != null)
{
req.Expected = currentConfig.Expected.ToExpectedAttributeMap(Conversion);
}
else if (currentConfig.ExpectedState != null &&
currentConfig.ExpectedState.ExpectedValues != null &&
currentConfig.ExpectedState.ExpectedValues.Count > 0)
{
req.Expected = currentConfig.ExpectedState.ToExpectedAttributeMap(Conversion);
if (req.Expected.Count > 1)
req.ConditionalOperator = EnumMapper.Convert(currentConfig.ExpectedState.ConditionalOperator);
}
else if (currentConfig.ConditionalExpression != null && currentConfig.ConditionalExpression.IsSet)
{
currentConfig.ConditionalExpression.ApplyExpression(req, this.Conversion);
}
var resp = DDBClient.PutItem(req);
doc.CommitChanges();
Document ret = null;
if (currentConfig.ReturnValues == ReturnValues.AllOldAttributes)
{
ret = Document.FromAttributeMap(resp.Attributes);
}
return ret;
}