public async Task <IActionResult> Submit([FromBody] QuoteWriteDTO quote) { string referenceId = await _quotesService.SubmitQuote(quote); if (string.IsNullOrEmpty(referenceId)) { return(BadRequest()); } return(Ok(new { referenceId })); }
public async Task <string> SubmitQuote(QuoteWriteDTO quote) { string referenceId = Guid.NewGuid().ToString(); // The best way to get accurate timing long ttlExpiryTimestamp = (long)DateTime.UtcNow.Subtract(DateTime.UnixEpoch) .Add(TimeSpan.FromHours(DataDefinitions.QUOTES_PROPOSAL_TABLE_TTL_VALUE_HOURS)).TotalSeconds; Dictionary <string, AttributeValue> attributes = new Dictionary <string, AttributeValue> { { DataDefinitions.QUOTES_PROPOSAL_TABLE_HASH_KEY, new AttributeValue { S = DateTime.UtcNow.ToString() } }, { DataDefinitions.QUOTES_PROPOSAL_TABLE_SORT_KEY, new AttributeValue { S = referenceId } }, { "Text", new AttributeValue { S = quote.Text } }, { "Quoter", new AttributeValue { S = quote.Quoter } }, { "SubmitterEmail", new AttributeValue { S = quote.SubmitterEmail } }, { DataDefinitions.QUOTES_PROPOSAL_TABLE_TTL, new AttributeValue { N = ttlExpiryTimestamp.ToString() } } }; PutItemRequest request = new PutItemRequest { TableName = DataDefinitions.QUOTES_PROPOSAL_TABLE, Item = attributes }; PutItemResponse response = await _client.PutItemAsync(request); return(response.HttpStatusCode == HttpStatusCode.OK? referenceId: null); }