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 InventoryWebServiceRequest ToWmInventoryRequest(this StorefrontInventoryRequest request) { var result = new InventoryWebServiceRequest(); var invReq = new StoreFrontWebServices.InventoryRequest { InventoryRequestDetail = new InventoryRequestDetail[request.Products.Count] }; var partners = new Partner2[2]; var partner0 = new Partner2 { PartnerID = request.PartnerInfo[0].PartnerId, PartnerType = PARTNER_TYPE_SHIPTO }; partners[0] = partner0; var partner = new Partner2 { PartnerID = request.PartnerInfo[1].PartnerId, PartnerType = PARTNER_TYPE_BILLTO }; partners[1] = partner; invReq.InventoryRequestHeader = new InventoryRequestHeader { SalesOrgID = request.SalesAreaInfo.SalesOrgId, DistChannelID = request.SalesAreaInfo.DistChannelId, DivisionID = request.SalesAreaInfo.DivisionId, Partner = partners }; var lineNum = 0; foreach (var p in request.Products) { var inventoryRequestDetail = new InventoryRequestDetail { OrderLineNumber = (lineNum + 1).ToString(CultureInfo.InvariantCulture), ProductID = p.ProductId, Quantity = p.Quantity.ToString(CultureInfo.InvariantCulture), RequestedDate = p.RequestedDate.ToString("yyyyMMdd") }; invReq.InventoryRequestDetail[lineNum] = inventoryRequestDetail; lineNum++; } result.InventoryRequest = invReq; return(result); }
/// <summary> /// This method takes a client inventory request model and converts, makes calls and converts response /// back to client side model /// </summary> /// <param name="inventoryRequest"></param> /// <returns></returns> public InventoryResponse GetInventory(InventoryRequest inventoryRequest) { return(_webMethodClient.GetInventory(inventoryRequest)); }