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()); }
private Subscription GetSubscriptionById(string subsID) { Subscription subscription = new Subscription(); var query = DynamoClient.QueryAsync(new QueryRequest { TableName = "Subscription", Select = Select.SPECIFIC_ATTRIBUTES, ProjectionExpression = "Id,Content_Type,Secret,WebHookUrl", KeyConditionExpression = "Id = :Id", ExpressionAttributeValues = new Dictionary <string, AttributeValue> { { ":Id", new AttributeValue { S = subsID } } } }); if (query != null) { if (query.Result.HttpStatusCode == System.Net.HttpStatusCode.OK) { query.Result.Items.ForEach(itens => { subscription.Id = itens.Where(k => k.Key == "Id").FirstOrDefault().Value?.S; subscription.Content_Type = itens.Where(k => k.Key == "Content_Type").FirstOrDefault().Value?.S; subscription.Secret = itens.Where(k => k.Key == "Secret").FirstOrDefault().Value?.S; subscription.WebHookUrl = itens.Where(k => k.Key == "WebHookUrl").FirstOrDefault().Value?.S; }); } } return(subscription); }
///------------------------------------------------------------------------------------------------- /// <summary> Sets the Skill's persistant session attributes in DynamoDB. </summary> /// /// <remarks> Austin Wilson, 9/15/2018. </remarks> /// /// <param name="attributes"> The attributes to set. </param> /// <param name="callback"> The callback. </param> ///------------------------------------------------------------------------------------------------- public void SetSessionAttributes(Dictionary<string, AttributeValue> attributes, Action<SetSessionAttributesEventData> callback) { var playerItem = new Dictionary<string, AttributeValue> { {"id", new AttributeValue {S = alexaUserDynamoKey}}, {"attributes", new AttributeValue {M = attributes}} }; DynamoClient.PutItemAsync(tableName, playerItem, (result) => { if (result.Exception == null) { if (debug) { Debug.Log(displayName + "SetSessionAttributes " + result.Response.HttpStatusCode); } RaiseSetSessionAttributesResponseHandler(false, callback); } else { if (debug) { Debug.LogError(displayName + "SetSessionAttributes: " + result.Exception.Message); } RaiseSetSessionAttributesResponseHandler(true, callback, result.Exception); } }); }
private async Task DeleteAllItemsAsync() { // scan for all records var scanRequest = new ScanRequest { TableName = TableName }; do { var scanResponse = await DynamoClient.ScanAsync(scanRequest); // delete each returned item foreach (var item in scanResponse.Items) { await DynamoClient.DeleteItemAsync(new DeleteItemRequest { TableName = TableName, Key = { ["PK"] = item["PK"], ["SK"] = item["SK"] } }); } scanRequest.ExclusiveStartKey = scanResponse.LastEvaluatedKey; } while(scanRequest.ExclusiveStartKey.Any()); }
public DynamoClientTests() { _dynamoDbClient = new DynamoClient(); try { _dynamoDbClient.SetupAsync().Wait(); } catch (AggregateException e) { //ignore table already created Console.WriteLine(e); } }
public async Task <IActionResult> Delete(string id) { var deleteItemResponse = await DynamoClient.DeleteItemAsync(_tableName, new Dictionary <string, AttributeValue> { { "Uuid", new AttributeValue { S = id } } }, ReturnValue.ALL_OLD); if (deleteItemResponse.Attributes.Count == 0) { return(NotFound()); } return(new NoContentResult()); }
public async Task <IEnumerable <TodoItem> > GetAll() { var scanConditions = new Dictionary <string, Condition>(); var list = new List <TodoItem>(); var scanResponse = await DynamoClient.ScanAsync(_tableName, scanConditions); foreach (Dictionary <string, AttributeValue> item in scanResponse.Items) { list.Add(new TodoItem { Uuid = item["Uuid"].S, Name = item["Name"].S, IsComplete = Int32.Parse(item["IsComplete"].N) }); } return(list); }
///------------------------------------------------------------------------------------------------- /// <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)); }
public async Task <IActionResult> Create([FromBody] TodoItem item) { if (item == null) { return(BadRequest()); } item.Uuid = NewGuid().ToString(); 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(CreatedAtRoute("GetTodo", new { id = item.Uuid }, item)); }
public void Test1() { var test = new DynamoClient(new CofigurationManager()); Assert.Pass(); }