Example #1
0
        public static JToken Run(
            [WorkflowActionTrigger] JToken parameters,
            ILogger log)
        {
            var shipmentRequest = parameters.Root.ToObject <ShipmentRequest>();

            //Update Stock
            foreach (var item in shipmentRequest.ShipmentItems)
            {
                using (var httpClient = new HttpClient())
                {
                    var stockUpdateRequest = new StockUpdateRequest
                    {
                        ItemId = item.ItemId,
                        Qty    = item.Qty * -1
                    };
                    var content = new StringContent(JsonConvert.SerializeObject(stockUpdateRequest), Encoding.UTF8, "application/json");

                    var response = httpClient.PostAsync(System.Environment.GetEnvironmentVariable("warehouse_setstockurl"), content).Result;
                }
            }


            return(new JObject {
                { "Message", $"Shipment for order: {shipmentRequest.OrderId} succeeded" }
            });
        }
        public async Task <IActionResult> Put(long warehouseId, [FromBody] IList <StockVm> stockVms)
        {
            var currentUser = await _workContext.GetCurrentUser();

            foreach (var item in stockVms)
            {
                if (item.AdjustedQuantity == 0)
                {
                    continue;
                }

                var stockUpdateRequest = new StockUpdateRequest
                {
                    WarehouseId      = warehouseId,
                    ProductId        = item.ProductId,
                    AdjustedQuantity = item.AdjustedQuantity,
                    Note             = item.Note,
                    UserId           = currentUser.Id
                };

                await _stockService.UpdateStock(stockUpdateRequest);
            }

            return(Accepted());
        }
Example #3
0
        private static void PostStockUpdate(OgoShipApi api)
        {
            Console.WriteLine("Create New StockUpdate");
            var stockUpdate1 = new StockUpdateRequest
            {
                WarehouseCode    = "TEST",
                Status           = "",
                Supplier         = "Test supplier",
                Containers       = 1,
                Pallets          = 10,
                Parcels          = 100,
                DeliveredBy      = "Test Supplier",
                ReceiveDate      = DateTime.UtcNow.AddDays(5),
                MerchantComments = "Test Merchant Comment",
                TrackingCodes    = new List <string> {
                    "123456789", "987654321"
                },
                SpecialAction = "special action comment if needed",
                Reference     = "testreference",
                Products      = new List <StockUpdateRequest.ProductUpdateRequest>
                {
                    new StockUpdateRequest.ProductUpdateRequest
                    {
                        Code               = "TestProductCode",
                        Name               = "Test Product",
                        ExpectedQuantity   = 100,
                        SupplyPrice        = (decimal?)10.99,
                        EANCode            = "1234567890",
                        CountryOfOrigin    = "FI",
                        CustomsDescription = "Test product made out of test",
                        HsCode             = "20111222"
                    }
                }
            };

            api.AddStockUpdate(stockUpdate1);



            Console.WriteLine("Get stock update by reference");
            var stockUpdates = api.GetStockUpdate(null, stockUpdate1.Reference, null);

            foreach (var stockUpdate in stockUpdates)
            {
                Console.WriteLine($"Reference: {stockUpdate.Reference}");
            }
        }
Example #4
0
        /// <summary>
        /// Add new stock update
        /// </summary>
        /// <param name="stockUpdate"></param>
        /// <returns></returns>
        public StockUpdateRequest AddStockUpdate(StockUpdateRequest stockUpdate)
        {
            Debug.WriteLine($"Request new product update");

            var request = new RestRequest($"/api/v1/StockUpdate", Method.POST);

            request.AddJsonBody(stockUpdate);

            var apiResponse = Execute <StockUpdateRequest>(request);

            if (!apiResponse.IsSuccessful)
            {
                throw new Exception("Error");
            }

            return(apiResponse.Data);
        }
        public async Task <IActionResult> Put(long warehouseId, [FromBody] IList <StockVm> stockVms)
        {
            var currentUser = await _workContext.GetCurrentUser();

            var warehouse = _warehouseRepository.Query().FirstOrDefault(x => x.Id == warehouseId);

            if (warehouse == null)
            {
                return(NotFound());
            }

            if (!User.IsInRole("admin") && warehouse.VendorId != currentUser.VendorId)
            {
                return(BadRequest(new { error = "You don't have permission to manage this warehouse" }));
            }

            foreach (var item in stockVms)
            {
                if (item.AdjustedQuantity == 0)
                {
                    continue;
                }

                var stockUpdateRequest = new StockUpdateRequest
                {
                    WarehouseId      = warehouseId,
                    ProductId        = item.ProductId,
                    AdjustedQuantity = item.AdjustedQuantity,
                    Note             = item.Note,
                    UserId           = currentUser.Id
                };

                await _stockService.UpdateStock(stockUpdateRequest);
            }

            return(Accepted());
        }