static async Task TestCreateItem(string itemId) { var attributes = new List <SdbItemAttribute> { new SdbItemAttribute(StringConstants.USERNAME_ATTRIBUTE, "JohnD"), new SdbItemAttribute(StringConstants.FIRSTNAME_ATTRIBUTE, "John"), new SdbItemAttribute(StringConstants.LASTNAME_ATTRIBUTE, "Doe"), new SdbItemAttribute(StringConstants.AGE_ATTRIBUTE, "35") }; var item = new SdbItem(itemId, attributes); try { var response = await _sdbService.CreateItemAsync(item); Console.WriteLine(response != HttpStatusCode.OK ? $"HttpResponse from the create ite action return code: {response}." : "New user was created."); } catch (AmazonSimpleDBException) { Console.WriteLine("There was and error while creating the item"); } }
/// <summary> /// Creates single item /// </summary> public async Task <HttpStatusCode> CreateItemAsync(SdbItem item) { try { //Add additional attribute for the Exists flag on the newly created item item.Attributes = item.Attributes.Concat(new[] { new SdbItemAttribute(ExistsAttributeName, "1"), }); var convertedAttributes = SimpleDbHelper.ConvertItemAttributesToReplaceableAttributes(item.Attributes); var putRequest = new PutAttributesRequest(_simpleDbDomain, item.ItemName, convertedAttributes.ToList()); var putResponse = await _client.PutAttributesAsync(putRequest); return(putResponse.HttpStatusCode); } catch (AmazonSimpleDBException e) { Console.WriteLine(e.StackTrace); throw; } }
/// <summary> /// Returns single item based on the id /// </summary> public async Task <SdbItem> GetItemAsync(string itemId, bool consistentRead = false) { try { var attributes = await RetrieveItemAttributesFromDb(itemId, consistentRead); if (!attributes.Any()) { return(null); } var item = new SdbItem(itemId, SimpleDbHelper.ConvertAttributesToItemAttributes(attributes)); return(item); } catch (AmazonSimpleDBException e) { Console.WriteLine(e.StackTrace); throw; } }