Example #1
0
        public InventoryResponse GetInventory(InventoryRequest inventoryWmRequest)
        {
            var inventoryResponse = new InventoryResponse();
            var request           = inventoryWmRequest.ToWmInventoryRequest();
            var backup            = new BackupLogEntry(request, nameof(GetInventory));

            LogRequest(request, nameof(GetInventory));
            var wmInventoryResponse = _soapStoreFrontWebService.InventoryWebServiceAsync(request).Result;

            backup.AddResponse(wmInventoryResponse);
            _repository.InsertOne(backup);
            LogResponse(wmInventoryResponse);

            var failedInventoryItems = new List <FailedItem>();

            while (wmInventoryResponse.ErrorResponse != null)
            {
                var errorMessage = wmInventoryResponse.ErrorResponse.ErrorResponse1.Body[0].Error;
                var productId    = LogFailedItem(failedInventoryItems, errorMessage);

                if (productId == Empty)
                {
                    inventoryResponse.FailedItems  = failedInventoryItems;
                    inventoryResponse.ErrorMessage = "We were not able to obtain response items for all requested products.  Please see list of failed inventory items.";
                    return(inventoryResponse);
                }

                var newItemsList = request.InventoryRequest.InventoryRequestDetail.Where(val => val.ProductID != productId).ToArray();
                request.InventoryRequest.InventoryRequestDetail = newItemsList;
                if (newItemsList.Length == 0)
                {
                    break;
                }
                var backup2 = new BackupLogEntry(request, "Additional GetInventory (to handle failed products");
                LogRequest(request, "Additional GetInventory (to handle failed products");
                wmInventoryResponse = _soapStoreFrontWebService.InventoryWebServiceAsync(request).Result;
                backup2.AddResponse(wmInventoryResponse);
                _repository.InsertOne(backup2);
                LogResponse(wmInventoryResponse);
            }

            inventoryResponse = wmInventoryResponse.ToInventoryResponse();
            if (failedInventoryItems.Count == 0)
            {
                return(inventoryResponse);
            }
            inventoryResponse.FailedItems  = failedInventoryItems;
            inventoryResponse.ErrorMessage = "We were not able to obtain response items for all requested products.  Please see list of failed inventory items.";
            return(inventoryResponse);
        }
        public static InventoryResponse ToInventoryResponse(this InventoryWebServiceResponse1 response)
        {
            var result = new InventoryResponse();

            if (response.InventoryResponse == null)
            {
                return(result);
            }
            result = new InventoryResponse
            {
                InventoryResponseItems = new InventoryResponseItem[response.InventoryResponse.InventoryResponseDetail.Length]
            };

            int itemNum = 0;

            foreach (var serviceInventoryResponseDetail in response.InventoryResponse.InventoryResponseDetail)
            {
                //Values comes in as a string with decimal formatting, e.g "1.00"
                var quantity = Convert.ToDecimal(serviceInventoryResponseDetail.Quantity, CultureInfo.InvariantCulture);
                var inventoryResponseDetail = new InventoryResponseItem
                {
                    OrderLineNumber = serviceInventoryResponseDetail.OrderLineNumber,
                    ProductId       = serviceInventoryResponseDetail.ProductID,
                    Quantity        = quantity,
                    ShippingPoint   = serviceInventoryResponseDetail.ShippingPoint,
                };

                var numOfAvailQty = 0;
                var availableQtyWithDollarValue = serviceInventoryResponseDetail.ItemDetail.Where(itemDetail => Decimal.Parse(itemDetail.AvailableQty, CultureInfo.InvariantCulture) != 0.00M);
                inventoryResponseDetail.Availabilities = new Availability[availableQtyWithDollarValue.ToList().Count];

                foreach (var avaialblity in availableQtyWithDollarValue.Select(itemDetail => new Availability
                {
                    AvailableDate = DateTime.ParseExact(itemDetail.AvailableDate, "yyyyMMdd", CultureInfo.InvariantCulture),
                    AvailableQty = Convert.ToDecimal(itemDetail.AvailableQty, CultureInfo.InvariantCulture)
                }))
                {
                    inventoryResponseDetail.Availabilities[numOfAvailQty] = avaialblity;
                    numOfAvailQty++;
                }
                result.InventoryResponseItems[itemNum] = inventoryResponseDetail;
                itemNum++;
            }

            return(result);
        }