Exemple #1
0
        public async Task <ActionResult <string> > Post([FromBody] ItemClaim item)
        {
            item.Date = DateTime.Now;

            try
            {
                var record = new Dictionary <string, AttributeValue>
                {
                    { "username", new AttributeValue {
                          S = item.Username
                      } },
                    { "item", new AttributeValue {
                          S = item.Item
                      } },
                    { "summary", new AttributeValue {
                          S = item.Summary
                      } },
                    { "date", new AttributeValue {
                          S = item.Date.ToString("dd.MM.yyyy HH:mm:ss")
                      } }
                };

                var table = await _dynamoClient.PutItemAsync("claims", record);
            }
            catch (Exception)
            {
                return(BadRequest("Something went wrong with DynamoDB call 911"));
            }

            return(Ok("Got it!"));
        }
Exemple #2
0
        public async Task <IActionResult> Claim([FromBody] ItemClaim claim)
        {
            var item = await _dbContext.Items.SingleOrDefaultAsync(x => x.ItemCode == claim.ItemCode);

            if (item == null)
            {
                return(BadRequest($"Item {claim.ItemCode} not found"));
            }
            if (item.TotalQuantity < claim.Quantity)
            {
                return(BadRequest($"Item {claim.ItemCode} doesn't have enough quantity"));
            }

            item.TotalQuantity = item.TotalQuantity - claim.Quantity;

            await _dbContext.SaveChangesAsync();

            return(Ok(item));
        }