Ejemplo n.º 1
0
        // /inventory
        // Post
        public static async Task <HttpResponseMessage> UpdateProductsQuantity(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = "inventory")]
            HttpRequestMessage req,
            TraceWriter log,
            [Inject] InventoryController controller)
        {
            log.Info($"C# HTTP trigger function ({nameof(UpdateProductsQuantity)} received a request.");
            var inventoryProducts = await req.Content.ReadAsAsync <List <InvProductOperation> >();

            try
            {
                var result = await controller.UpdateAvailableProductsQuantity(inventoryProducts);

                return(JsonResponse(result, HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                log.Error($"Error in {nameof(controller.UpdateAvailableProductsQuantity)}", e);
                throw;
            }
        }
Ejemplo n.º 2
0
        // /inventory/skus?sku=ASDF&sku=ASDG&sku=ASDH
        public static async Task <HttpResponseMessage> GetInventoryBySku(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "inventory")]
            HttpRequestMessage req,
            TraceWriter log,
            [Inject] InventoryController controller)
        {
            log.Info($"C# HTTP trigger function ({nameof(GetInventoryBySku)} received a request.");
            var skus    = req.GetQueryNameValuePairs();
            var skuList = skus.Where(k => k.Key == "sku").Select(v => v.Value).ToList();

            if (skuList.Any())
            {
                var result = await controller.QueryInventoryBySkuList(skuList);

                return(JsonResponse(result, HttpStatusCode.OK));
            }
            else
            {
                return(req.CreateErrorResponse(HttpStatusCode.BadRequest,
                                               "Invalid querystring params, expects '?sku=XXXX&sku=XXXY'"));
            }
        }