public async Task <IActionResult> Update(string id, [FromBody] TodoItem item) { if (item == null || item.Uuid != id) { return(BadRequest()); } var itemResponse = await DynamoClient.GetItemAsync(_tableName, new Dictionary <string, AttributeValue> { { "Uuid", new AttributeValue { S = id } } }); if (!itemResponse.IsItemSet) { return(NotFound()); } await DynamoClient.PutItemAsync(_tableName, new Dictionary <string, AttributeValue> { { "Uuid", new AttributeValue { S = item.Uuid } }, { "Name", new AttributeValue { S = item.Name } }, { "IsComplete", new AttributeValue { N = item.IsComplete.ToString() } } }); return(new NoContentResult()); }
///------------------------------------------------------------------------------------------------- /// <summary> Gets the Skill's persistant session attributes from DynamoDB. </summary> /// /// <remarks> Austin Wilson, 9/15/2018. </remarks> /// /// <param name="callback"> The callback. </param> ///------------------------------------------------------------------------------------------------- public void GetSessionAttributes(Action<GetSessionAttributesEventData> callback) { var key = new Dictionary<string, AttributeValue> { {"id", new AttributeValue {S = alexaUserDynamoKey}} }; DynamoClient.GetItemAsync(tableName, key, (result) => { if (result.Exception == null) { if (debug) { Debug.Log(displayName + "GetSessionAttributes " + result.Response.HttpStatusCode); } if (result.Response.Item.Count > 0) { Dictionary<string, AttributeValue> values = result.Response.Item["attributes"].M; RaiseGetSessionAttributesResponse(false, values, callback); } else { if (debug) { Debug.Log(displayName + "GetSessionAttributes did not find a user! Are you sure provided the correct table name?"); } RaiseGetSessionAttributesResponse(true, null, callback, new Exception("GetSessionAttributes did not find a user! Are you sure provided the correct table name?")); } } else { if (debug) { Debug.LogError(displayName + "GetSessionAttributes: " + result.Exception.Message); } RaiseGetSessionAttributesResponse(true, null, callback, result.Exception); } }); }
public async Task <IActionResult> GetById(string id) { var itemResponse = await DynamoClient.GetItemAsync(_tableName, new Dictionary <string, AttributeValue> { { "Uuid", new AttributeValue { S = id } } }); if (!itemResponse.IsItemSet) { return(NotFound()); } var item = new TodoItem { Uuid = itemResponse.Item["Uuid"].S, Name = itemResponse.Item["Name"].S, IsComplete = Int32.Parse(itemResponse.Item["IsComplete"].N) }; return(new ObjectResult(item)); }