private async Task <DialogTurnResult> PackToHandlingUnitPrompt( WaterfallStepContext step, CancellationToken cancellationToken = default(CancellationToken)) { var nBaseUnitQuantityPicked = step.Result; ((PickBatchPickingPost)step.Values[DialogKey]).nBaseUnitQuantityPicked = Convert.ToDouble(nBaseUnitQuantityPicked); //Custom Code Start | Added Code Block step.Values[IsCompleteInventoryUnitPickKey] = _picking.isCompleteInventoryUnitPick((InventoryUnits)step.Values[PickSuggestionKey], Convert.ToDouble(nBaseUnitQuantityPicked)); step.Values[IsHandlingUnitPickKey] = _picking.isHandlingUnitPick((InventoryUnits)step.Values[PickSuggestionKey], Convert.ToDouble(nBaseUnitQuantityPicked)); //We adjust the queued qty down var inventoryUnitPickedFrom = _inventoryunitsService.GetPost(((InventoryUnits)step.Values[PickSuggestionKey]).ixInventoryUnit); inventoryUnitPickedFrom.nBaseUnitQuantityQueued -= (double)step.Values[PickSuggestionQtyKey]; inventoryUnitPickedFrom.UserName = step.Context.Activity.Conversation.Id; await _inventoryunitsService.Edit(inventoryUnitPickedFrom, _commonLookUps.getInventoryUnitTransactionContext().Where(x => x.sInventoryUnitTransactionContext == "Inventory Adjustment").Select(x => x.ixInventoryUnitTransactionContext).FirstOrDefault()); var currentBotUserData = await _botSpielUserStateAccessors.BotUserDataAccessor.GetAsync(step.Context, () => _botUserData); //If we pick complete inventory unit we move it to the picker else we adjust and create/consolidate and then move to the picker if ((bool)step.Values[IsCompleteInventoryUnitPickKey]) { //We now create and execute the move queue for the pickup step.Values[PickedInventoryUnitKey] = ((InventoryUnits)step.Values[PickSuggestionKey]).ixInventoryUnit; MoveQueuesPost moveQueuePost = new MoveQueuesPost(); if (_picking.isHandlingUnitPick((InventoryUnits)step.Values[PickSuggestionKey], Convert.ToDouble(nBaseUnitQuantityPicked))) { moveQueuePost.ixMoveQueueType = _commonLookUps.getMoveQueueTypes().Where(x => x.sMoveQueueType == "Unit Pickup - Consolidated Drop").Select(x => x.ixMoveQueueType).FirstOrDefault(); } else { moveQueuePost.ixMoveQueueType = _commonLookUps.getMoveQueueTypes().Where(x => x.sMoveQueueType == "Consolidated Pickup - Consolidated Drop").Select(x => x.ixMoveQueueType).FirstOrDefault(); } moveQueuePost.ixMoveQueueContext = _commonLookUps.getMoveQueueContexts().Where(x => x.sMoveQueueContext == "Picking").Select(x => x.ixMoveQueueContext).FirstOrDefault(); moveQueuePost.ixSourceInventoryUnit = ((InventoryUnits)step.Values[PickSuggestionKey]).ixInventoryUnit; moveQueuePost.ixTargetInventoryUnit = ((InventoryUnits)step.Values[PickSuggestionKey]).ixInventoryUnit; moveQueuePost.ixSourceInventoryLocation = ((InventoryUnits)step.Values[PickSuggestionKey]).ixInventoryLocation; moveQueuePost.ixTargetInventoryLocation = currentBotUserData.ixInventoryLocation; moveQueuePost.ixSourceHandlingUnit = ((InventoryUnits)step.Values[PickSuggestionKey]).ixHandlingUnit > 0 ? ((InventoryUnits)step.Values[PickSuggestionKey]).ixHandlingUnit : null; moveQueuePost.ixTargetHandlingUnit = ((InventoryUnits)step.Values[PickSuggestionKey]).ixHandlingUnit > 0 ? ((InventoryUnits)step.Values[PickSuggestionKey]).ixHandlingUnit : null; moveQueuePost.sPreferredResource = step.Context.Activity.Conversation.Id; moveQueuePost.nBaseUnitQuantity = Convert.ToDouble(nBaseUnitQuantityPicked); moveQueuePost.dtStartedAt = DateTime.Now; moveQueuePost.ixPickBatch = ((PickBatchPickingPost)step.Values[DialogKey]).ixPickBatch; moveQueuePost.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Active").Select(x => x.ixStatus).FirstOrDefault(); moveQueuePost.UserName = step.Context.Activity.Conversation.Id; var ixMoveQueue = await _movequeuesService.Create(moveQueuePost); //We now complete the move queue for the pickup var moveQueuePickUp = _movequeuesService.GetPost(ixMoveQueue); moveQueuePickUp.dtCompletedAt = DateTime.Now; moveQueuePickUp.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Complete").Select(x => x.ixStatus).FirstOrDefault(); moveQueuePickUp.UserName = moveQueuePost.UserName; await _movequeuesService.Edit(moveQueuePickUp); } else { //Now we adjust the iu remaining down inventoryUnitPickedFrom.nBaseUnitQuantity -= Convert.ToDouble(nBaseUnitQuantityPicked); inventoryUnitPickedFrom.UserName = step.Context.Activity.Conversation.Id; await _inventoryunitsService.Edit(inventoryUnitPickedFrom, _commonLookUps.getInventoryUnitTransactionContext().Where(x => x.sInventoryUnitTransactionContext == "Inventory Adjustment").Select(x => x.ixInventoryUnitTransactionContext).FirstOrDefault()); //Now we either create or edit an iu for the qty picked inventoryUnitPickedFrom.nBaseUnitQuantity = Convert.ToDouble(nBaseUnitQuantityPicked); inventoryUnitPickedFrom.UserName = step.Context.Activity.Conversation.Id; inventoryUnitPickedFrom.ixInventoryLocation = currentBotUserData.ixInventoryLocation; if (_inventoryunitsService.IndexDb().Where(x => x.ixFacility == inventoryUnitPickedFrom.ixFacility && x.ixCompany == inventoryUnitPickedFrom.ixCompany && x.ixMaterial == inventoryUnitPickedFrom.ixMaterial && x.ixInventoryState == inventoryUnitPickedFrom.ixInventoryState && x.ixHandlingUnit == inventoryUnitPickedFrom.ixHandlingUnit && x.ixInventoryLocation == inventoryUnitPickedFrom.ixInventoryLocation && x.sBatchNumber == inventoryUnitPickedFrom.sBatchNumber && x.dtExpireAt == inventoryUnitPickedFrom.dtExpireAt && x.ixStatus == 5 ).Select(x => x.ixInventoryUnit).Any() ) { //We edit the iu inventoryUnitPickedFrom.ixInventoryUnit = _inventoryunitsService.IndexDb().Where(x => x.ixFacility == inventoryUnitPickedFrom.ixFacility && x.ixCompany == inventoryUnitPickedFrom.ixCompany && x.ixMaterial == inventoryUnitPickedFrom.ixMaterial && x.ixInventoryState == inventoryUnitPickedFrom.ixInventoryState && x.ixHandlingUnit == inventoryUnitPickedFrom.ixHandlingUnit && x.ixInventoryLocation == inventoryUnitPickedFrom.ixInventoryLocation && x.sBatchNumber == inventoryUnitPickedFrom.sBatchNumber && x.dtExpireAt == inventoryUnitPickedFrom.dtExpireAt && x.ixStatus == 5 ).Select(x => x.ixInventoryUnit).FirstOrDefault(); inventoryUnitPickedFrom.nBaseUnitQuantity = _inventoryunitsService.GetPost(inventoryUnitPickedFrom.ixInventoryUnit).nBaseUnitQuantity + Convert.ToDouble(nBaseUnitQuantityPicked); await _inventoryunitsService.Edit(inventoryUnitPickedFrom, _commonLookUps.getInventoryUnitTransactionContext().Where(x => x.sInventoryUnitTransactionContext == "Inventory Adjustment").Select(x => x.ixInventoryUnitTransactionContext).FirstOrDefault()); step.Values[PickedInventoryUnitKey] = inventoryUnitPickedFrom.ixInventoryUnit; } else { //We create an iu step.Values[PickedInventoryUnitKey] = await _inventoryunitsService.Create(inventoryUnitPickedFrom, _commonLookUps.getInventoryUnitTransactionContext().Where(x => x.sInventoryUnitTransactionContext == "Inventory Adjustment").Select(x => x.ixInventoryUnitTransactionContext).FirstOrDefault()); } } //We now allocate the picked qty to open allocation lines step.Values[LineQtysPickedKey] = new List <Tuple <Int64, double> >(); var pickedQtyNotAllocated = Convert.ToDouble(nBaseUnitQuantityPicked); _outboundorderlinesinventoryallocationService.IndexDbPost().Where(x => (x.nBaseUnitQuantityAllocated - x.nBaseUnitQuantityPicked) > 0).OrderBy(x => (x.nBaseUnitQuantityAllocated - x.nBaseUnitQuantityPicked) > 0).ToList() .Join(_picking.getOrderLinesInBatchForMaterial(((PickBatchPickingPost)step.Values[DialogKey]).ixPickBatch, ((InventoryUnits)step.Values[PickSuggestionKey]).ixMaterial), ol => ol.ixOutboundOrderLine, olb => olb, (ol, olb) => new { Ol = ol, Olb = olb }).ToList() .ForEach(y => { if ((y.Ol.nBaseUnitQuantityAllocated - y.Ol.nBaseUnitQuantityPicked) <= pickedQtyNotAllocated && pickedQtyNotAllocated > 0) { ((List <Tuple <Int64, double> >)step.Values[LineQtysPickedKey]).Add(new Tuple <long, double>(y.Ol.ixOutboundOrderLine, y.Ol.nBaseUnitQuantityAllocated - y.Ol.nBaseUnitQuantityPicked)); y.Ol.nBaseUnitQuantityPicked += y.Ol.nBaseUnitQuantityAllocated - y.Ol.nBaseUnitQuantityPicked; pickedQtyNotAllocated -= y.Ol.nBaseUnitQuantityAllocated - y.Ol.nBaseUnitQuantityPicked; y.Ol.UserName = step.Context.Activity.Conversation.Id; _outboundorderlinesinventoryallocationService.Edit(y.Ol); } else if ((y.Ol.nBaseUnitQuantityAllocated - y.Ol.nBaseUnitQuantityPicked) > pickedQtyNotAllocated && pickedQtyNotAllocated > 0) { ((List <Tuple <Int64, double> >)step.Values[LineQtysPickedKey]).Add(new Tuple <long, double>(y.Ol.ixOutboundOrderLine, pickedQtyNotAllocated)); y.Ol.nBaseUnitQuantityPicked += pickedQtyNotAllocated; pickedQtyNotAllocated -= pickedQtyNotAllocated; y.Ol.UserName = step.Context.Activity.Conversation.Id; _outboundorderlinesinventoryallocationService.Edit(y.Ol); } } ); //Custom Code End //We have to figure out whether this is a pick of a complete Handling Unit. //Custom Code Start | Replaced Code Block //Replaced Code Block Start //return await step.PromptAsync( // PackToHandlingUnitPromptId, // new PromptOptions // { // Prompt = MessageFactory.Text($"Please enter a PackToHandlingUnit:"), // RetryPrompt = MessageFactory.Text("I didn't understand. Please try again."), // }, // cancellationToken); //Replaced Code Block End if ((bool)step.Values[IsHandlingUnitPickKey]) { ((PickBatchPickingPost)step.Values[DialogKey]).sPackToHandlingUnit = ((InventoryUnits)step.Values[PickSuggestionKey]).HandlingUnits.sHandlingUnit; ((PickBatchPickingPost)step.Values[DialogKey]).ixHandlingUnit = ((InventoryUnits)step.Values[PickSuggestionKey]).HandlingUnits.ixHandlingUnit; //We create the packing record var orderLinesToPack = ((List <Tuple <Int64, double> >)step.Values[LineQtysPickedKey]).GroupBy(x => x.Item1).Select(x => new { ixOutboundOrderLine = x.Key, Total = x.Sum(s => s.Item2) }).ToList(); orderLinesToPack.ForEach(x => { //We check if there is an existing pack record we can use if ( _outboundorderlinepackingService.IndexDb().Where(p => p.ixHandlingUnit == ((PickBatchPickingPost)step.Values[DialogKey]).ixHandlingUnit && p.ixOutboundOrderLine == x.ixOutboundOrderLine ).Any() ) { var outboundorderlinepack = _outboundorderlinepackingService.GetPost(_outboundorderlinepackingService.IndexDb().Where(p => p.ixHandlingUnit == ((PickBatchPickingPost)step.Values[DialogKey]).ixHandlingUnit && p.ixOutboundOrderLine == x.ixOutboundOrderLine ).Select(p => p.ixOutboundOrderLinePack).FirstOrDefault() ); outboundorderlinepack.nBaseUnitQuantityPacked += x.Total; outboundorderlinepack.UserName = step.Context.Activity.Conversation.Id; _outboundorderlinepackingService.Edit(outboundorderlinepack); } else { var outboundorderlinepack = new OutboundOrderLinePackingPost(); outboundorderlinepack.ixOutboundOrderLine = x.ixOutboundOrderLine; outboundorderlinepack.ixHandlingUnit = ((PickBatchPickingPost)step.Values[DialogKey]).ixHandlingUnit; outboundorderlinepack.nBaseUnitQuantityPacked = x.Total; outboundorderlinepack.ixStatus = _commonLookUps.getStatuses().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault(); outboundorderlinepack.UserName = step.Context.Activity.Conversation.Id; _outboundorderlinepackingService.Create(outboundorderlinepack); } } ); return(await step.EndDialogAsync( (PickBatchPickingPost)step.Values[DialogKey], cancellationToken)); } else { return(await step.PromptAsync( PackToHandlingUnitPromptId, new PromptOptions { //Custom Code Start | Replaced Code Block //Replaced Code Block Start //Prompt = MessageFactory.Text($"Please enter a PackToHandlingUnit:"), //Replaced Code Block End Prompt = MessageFactory.Text($"Please enter/scan the Pack To Handling Unit:"), //Custom Code End RetryPrompt = MessageFactory.Text("I didn't understand. Please try again."), }, cancellationToken)); } //Custom Code End }
//Custom Code Start | Replaced Code Block //Replaced Code Block Start //public CreatePickBatchPickingDialog(string id, IPickBatchPickingService pickbatchpickingService, PickBatchPickingPost pickbatchpickingPost, BotSpielUserStateAccessors statePropertyAccessor) //Replaced Code Block End public CreatePickBatchPickingDialog(string id, IPickBatchPickingService pickbatchpickingService, PickBatchPickingPost pickbatchpickingPost, BotSpielUserStateAccessors statePropertyAccessor , IPickBatchesService pickbatchesService , CommonLookUps commonLookUps , Picking picking , IInventoryUnitsService inventoryunitsService , IMoveQueuesService movequeuesService , IHandlingUnitsService handlingunitsService , IOutboundOrderLinesInventoryAllocationService outboundorderlinesinventoryallocationService , IOutboundOrderLinePackingService outboundorderlinepackingService ) //Custom Code End : base(id) { InitialDialogId = Id; _botSpielUserStateAccessors = statePropertyAccessor ?? throw new System.ArgumentNullException("state accessor can't be null"); _pickbatchpickingService = pickbatchpickingService; _pickbatchpickingPost = pickbatchpickingPost; //Custom Code Start | Added Code Block _pickbatchesService = pickbatchesService; _commonLookUps = commonLookUps; _picking = picking; _inventoryunitsService = inventoryunitsService; _movequeuesService = movequeuesService; _handlingunitsService = handlingunitsService; _outboundorderlinesinventoryallocationService = outboundorderlinesinventoryallocationService; _outboundorderlinepackingService = outboundorderlinepackingService; PromptValidator <string> pickBatchPickValidator = async(promptContext, cancellationToken) => { var value = promptContext.Recognized.Value.Trim().ToLower(); if (!_pickbatchesService.IndexDb().Where(x => x.sPickBatch.Trim().ToLower() == value && x.ixStatus != _commonLookUps.getStatuses().Where(s => s.sStatus == "Complete").Select(s => s.ixStatus).FirstOrDefault()).Any()) { await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The pick batch {value} does not exist or is already complete. Please enter a different value or exit."), cancellationToken); return(false); } else { if (_pickbatchesService.IndexDb().Where(x => x.sPickBatch.Trim().ToLower() == value && x.ixStatus == _commonLookUps.getStatuses().Where(s => s.sStatus == "Started").Select(s => s.ixStatus).FirstOrDefault() && !x.bMultiResource).Any()) { await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The pick batch {value} has already been started and is flagged for a single picker. Please enter a different value or exit."), cancellationToken); return(false); } else if (_pickbatchesService.IndexDb().Where(x => x.sPickBatch.Trim().ToLower() == value && x.ixStatus == _commonLookUps.getStatuses().Where(s => s.sStatus == "Inactive").Select(s => s.ixStatus).FirstOrDefault()).Any()) { await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The pick batch {value} has not been activated. Please activate or enter a different value or exit."), cancellationToken); return(false); } return(true); } }; PromptValidator <float> baseUnitQuantityPickedValidator = async(promptContext, cancellationToken) => { var value = promptContext.Recognized.Value; var currentBotUserData = await _botSpielUserStateAccessors.BotUserDataAccessor.GetAsync(promptContext.Context, () => _botUserData); if (value > currentBotUserData.pickSuggestion.Item2) { await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The quantity picked {value.ToString()} must be less than or equal to the quantity suggested {currentBotUserData.pickSuggestion.Item2.ToString()}. Please enter a different value or exit."), cancellationToken); return(false); } else { return(true); } }; //Custom Code End // Define the prompts used in the Dialog. //Custom Code Start | Replaced Code Block //Replaced Code Block Start //AddDialog(new TextPrompt(PickBatchPickPromptId)); //Replaced Code Block End AddDialog(new TextPrompt(PickBatchPickPromptId, pickBatchPickValidator)); //Custom Code End AddDialog(new ChoicePrompt(InventoryUnitPromptId)); AddDialog(new NumberPrompt <float>(BaseUnitQuantityPickedPromptId, baseUnitQuantityPickedValidator)); AddDialog(new TextPrompt(PackToHandlingUnitPromptId)); // Define the conversation flow for the Dialog. WaterfallStep[] steps = new WaterfallStep[] { //PickBatchPickPrompt, //Custom Code Start | Removed Block //InventoryUnitPrompt, //Custom Code End BaseUnitQuantityPickedPrompt, PackToHandlingUnitPrompt, donePrompt, }; AddDialog(new WaterfallDialog(Id, steps)); }
public Task Edit(PickBatchesPost pickbatchesPost) { // Additional validations // Pre-process // Process this._pickbatchesRepository.RegisterEdit(pickbatchesPost); try { this._pickbatchesRepository.Commit(); } catch (Exception ex) { this._pickbatchesRepository.Rollback(); // Log exception throw; } // Post-process //Custom Code Start | Added Code Block if (pickbatchesPost.ixStatus == _commonLookUps.getStatuses().Where(s => s.sStatus == "Complete").Select(s => s.ixStatus).FirstOrDefault()) { // We check if the shipment associated with the orders on the batch has been manifested. If not we try and find an active manifest else we create a new one and add the shipment to it var outboundShipments = _outboundordersRepository.IndexDb().Where(x => x.ixPickBatch == pickbatchesPost.ixPickBatch).Select(x => x.ixOutboundShipment).ToList(); var outboundShipmentsNotManifested = _outboundshipmentsService.IndexDb().Where(x => x.ixOutboundCarrierManifest == null) .Join(outboundShipments, os => os.ixOutboundShipment, o => o, (os, o) => new { Os = os, O = o }) .Select(s => s.Os.ixOutboundShipment).ToList(); outboundShipmentsNotManifested.ForEach(x => { var outboundShipment = _outboundshipmentsService.GetPost(x); if ( _outboundcarriermanifestsService.IndexDb().Where(m => m.ixFacility == outboundShipment.ixFacility && m.ixCarrier == outboundShipment.ixCarrier && m.ixStatus == _commonLookUps.getStatuses().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault() ).Any()) { var ixOutboundCarrierManifest = _outboundcarriermanifestsService.IndexDb().Where(m => m.ixFacility == outboundShipment.ixFacility && m.ixCarrier == outboundShipment.ixCarrier && m.ixStatus == _commonLookUps.getStatuses().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault() ).Select(m => m.ixOutboundCarrierManifest).FirstOrDefault(); outboundShipment.ixOutboundCarrierManifest = ixOutboundCarrierManifest; outboundShipment.UserName = pickbatchesPost.UserName; _outboundshipmentsService.Edit(outboundShipment); } else { OutboundCarrierManifestsPost outboundCarrierManifestsPost = new OutboundCarrierManifestsPost(); outboundCarrierManifestsPost.ixFacility = outboundShipment.ixFacility; outboundCarrierManifestsPost.ixCarrier = outboundShipment.ixCarrier; outboundCarrierManifestsPost.ixPickupInventoryLocation = _shipping.getTrailerDoorSuggestion(outboundShipment.ixFacility); outboundCarrierManifestsPost.ixStatus = _commonLookUps.getStatuses().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault(); outboundCarrierManifestsPost.dtScheduledPickupAt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day) + _outboundshipmentsService.CarriersDb().Where(c => c.ixCarrier == outboundShipment.ixCarrier).Select(c => c.dtScheduledPickupTime).FirstOrDefault(); outboundCarrierManifestsPost.UserName = pickbatchesPost.UserName; var ixOutboundCarrierManifest = _outboundcarriermanifestsService.Create(outboundCarrierManifestsPost).Result; outboundShipment.ixOutboundCarrierManifest = ixOutboundCarrierManifest; outboundShipment.UserName = pickbatchesPost.UserName; _outboundshipmentsService.Edit(outboundShipment); } } ); } //Custom Code End return(Task.CompletedTask); }
public Task <Int64> Create(ReceivingPost receivingPost) { // Additional validations // Pre-process //Custom Code Start | Added Code Block //If the handling unit does not exist we create it if (!HandlingUnitsDb().Where(x => x.sHandlingUnit == receivingPost.sReceipt.Trim()).Any()) { HandlingUnitsPost handlingUnitsPost = new HandlingUnitsPost(); handlingUnitsPost.sHandlingUnit = receivingPost.sReceipt; handlingUnitsPost.ixHandlingUnitType = receivingPost.ixHandlingUnitType ?? 0; handlingUnitsPost.UserName = receivingPost.UserName; receivingPost.ixHandlingUnit = _handlingunitsService.Create(handlingUnitsPost).Result; } else { receivingPost.ixHandlingUnit = HandlingUnitsDb().Where(x => x.sHandlingUnit == receivingPost.sReceipt.Trim()).Select(x => x.ixHandlingUnit).FirstOrDefault(); } InventoryUnitsPost inventoryUnit = new InventoryUnitsPost(); var inboundOrder = _inboundordersService.GetPost(receivingPost.ixInboundOrder); inventoryUnit.ixFacility = inboundOrder.ixFacility; inventoryUnit.ixCompany = inboundOrder.ixCompany; inventoryUnit.ixMaterial = receivingPost.ixMaterial; inventoryUnit.ixInventoryState = receivingPost.ixInventoryState; inventoryUnit.ixHandlingUnit = receivingPost.ixHandlingUnit; inventoryUnit.ixInventoryLocation = receivingPost.ixInventoryLocation; inventoryUnit.sSerialNumber = receivingPost.sSerialNumber; inventoryUnit.sBatchNumber = receivingPost.sBatchNumber; inventoryUnit.dtExpireAt = receivingPost.dtExpireAt; inventoryUnit.UserName = receivingPost.UserName; if ((inventoryUnit.sSerialNumber ?? "").Trim() != "") { //We create an iu inventoryUnit.nBaseUnitQuantity = receivingPost.nBaseUnitQuantityReceived; _inventoryunitsService.Create(inventoryUnit, _ixInventoryUnitTransactionContext); } else if (_inventoryunitsService.IndexDb().Where(x => x.ixFacility == inventoryUnit.ixFacility && x.ixCompany == inventoryUnit.ixCompany && x.ixMaterial == inventoryUnit.ixMaterial && x.ixInventoryState == inventoryUnit.ixInventoryState && x.ixHandlingUnit == inventoryUnit.ixHandlingUnit && x.ixInventoryLocation == inventoryUnit.ixInventoryLocation && x.sBatchNumber == inventoryUnit.sBatchNumber && x.dtExpireAt == inventoryUnit.dtExpireAt && x.ixStatus == 5 ).Select(x => x.ixInventoryUnit).Any() ) { //We edit the iu inventoryUnit.ixInventoryUnit = _inventoryunitsService.IndexDb().Where(x => x.ixFacility == inventoryUnit.ixFacility && x.ixCompany == inventoryUnit.ixCompany && x.ixMaterial == inventoryUnit.ixMaterial && x.ixInventoryState == inventoryUnit.ixInventoryState && x.ixHandlingUnit == inventoryUnit.ixHandlingUnit && x.ixInventoryLocation == inventoryUnit.ixInventoryLocation && x.sBatchNumber == inventoryUnit.sBatchNumber && x.dtExpireAt == inventoryUnit.dtExpireAt && x.ixStatus == 5 ).Select(x => x.ixInventoryUnit).FirstOrDefault(); inventoryUnit.nBaseUnitQuantity = _inventoryunitsService.GetPost(inventoryUnit.ixInventoryUnit).nBaseUnitQuantity + receivingPost.nBaseUnitQuantityReceived; _inventoryunitsService.Edit(inventoryUnit, _ixInventoryUnitTransactionContext); } else { //We create an iu inventoryUnit.nBaseUnitQuantity = receivingPost.nBaseUnitQuantityReceived; _inventoryunitsService.Create(inventoryUnit, _ixInventoryUnitTransactionContext); } //Custom Code End // Process this._receivingRepository.RegisterCreate(receivingPost); try { this._receivingRepository.Commit(); } catch (Exception ex) { this._receivingRepository.Rollback(); // Log exception throw; } // Post-process //Custom Code Start | Added Code Block //Now we update the inbound order lines - for now we apply entire qty to the matching line var _ixInboundOrderLine = _inboundorderlinesService.IndexDb().Where(x => x.ixInboundOrder == receivingPost.ixInboundOrder && x.ixMaterial == receivingPost.ixMaterial).Select(x => x.ixInboundOrderLine).FirstOrDefault(); var inboundOrderLine = _inboundorderlinesService.GetPost(_ixInboundOrderLine); inboundOrderLine.nBaseUnitQuantityReceived += receivingPost.nBaseUnitQuantityReceived; inboundOrderLine.UserName = receivingPost.UserName; if ((inboundOrderLine.nBaseUnitQuantityExpected - inboundOrderLine.nBaseUnitQuantityReceived) == 0) { inboundOrderLine.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Complete").Select(x => x.ixStatus).FirstOrDefault(); } _inboundorderlinesService.Edit(inboundOrderLine); //If there are no open qtys we set the inbound order/line status to complete if (_inboundorderlinesService.IndexDb().Where(x => x.ixInboundOrder == receivingPost.ixInboundOrder).Select(x => x.nBaseUnitQuantityExpected - x.nBaseUnitQuantityReceived).Sum() == 0) { var inboundorder = _inboundordersService.GetPost(receivingPost.ixInboundOrder); inboundorder.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Complete").Select(x => x.ixStatus).FirstOrDefault(); _inboundordersService.Edit(inboundorder); } //Custom Code End return(Task.FromResult(receivingPost.ixReceipt)); }
//Custom Code Start | Replaced Code Block //Replaced Code Block Start //public CreateGetPickBatchesDialog(string id, IGetPickBatchesService getpickbatchesService, GetPickBatchesPost getpickbatchesPost, BotSpielUserStateAccessors statePropertyAccessor) //Replaced Code Block End public CreateGetPickBatchesDialog(string id, GetPickBatchesPost getpickbatchesPost, BotSpielUserStateAccessors statePropertyAccessor , IPickBatchesService pickbatchesService , CommonLookUps commonLookUps ) //Custom Code End : base(id) { InitialDialogId = Id; _botSpielUserStateAccessors = statePropertyAccessor ?? throw new System.ArgumentNullException("state accessor can't be null"); //Custom Code Start | Removed Block //_getpickbatchesService = getpickbatchesService; //Custom Code End _getpickbatchesPost = getpickbatchesPost; //Custom Code Start | Added Code Block _pickbatchesService = pickbatchesService; _commonLookUps = commonLookUps; PromptValidator <string> pickBatchPickValidator = async(promptContext, cancellationToken) => { var value = promptContext.Recognized.Value.Trim().ToLower(); if (!_pickbatchesService.IndexDb().Where(x => x.sPickBatch.Trim().ToLower() == value && x.ixStatus != _commonLookUps.getStatuses().Where(s => s.sStatus == "Complete").Select(s => s.ixStatus).FirstOrDefault()).Any()) { await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The pick batch {value} does not exist or is already complete. Please enter a different value or exit."), cancellationToken); return(false); } else { if (_pickbatchesService.IndexDb().Where(x => x.sPickBatch.Trim().ToLower() == value && x.ixStatus == _commonLookUps.getStatuses().Where(s => s.sStatus == "Started").Select(s => s.ixStatus).FirstOrDefault() && !x.bMultiResource).Any()) { await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The pick batch {value} has already been started and is flagged for a single picker. Please enter a different value or exit."), cancellationToken); return(false); } else if (_pickbatchesService.IndexDb().Where(x => x.sPickBatch.Trim().ToLower() == value && x.ixStatus == _commonLookUps.getStatuses().Where(s => s.sStatus == "Inactive").Select(s => s.ixStatus).FirstOrDefault()).Any()) { await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The pick batch {value} has not been activated. Please activate or enter a different value or exit."), cancellationToken); return(false); } return(true); } }; //Custom Code End // Define the prompts used in the Dialog. //Custom Code Start | Replaced Code Block //Replaced Code Block Start //AddDialog(new TextPrompt(GetPickBatchPromptId)); //Replaced Code Block End AddDialog(new TextPrompt(GetPickBatchPromptId, pickBatchPickValidator)); //Custom Code End // Define the conversation flow for the Dialog. WaterfallStep[] steps = new WaterfallStep[] { GetPickBatchPrompt, donePrompt, }; AddDialog(new WaterfallDialog(Id, steps)); }
public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) { // use state accessor to extract the didBotWelcomeUser flag var didBotWelcomeUser = await _botSpielUserStateAccessors.DidBotWelcomeUser.GetAsync(turnContext, () => false); var currentBotUserData = await _botSpielUserStateAccessors.BotUserDataAccessor.GetAsync(turnContext, () => _botUserData); string conCat = ""; List <string> existInEntities = new List <string>(); bool DeleteOK = true; if (turnContext.Activity.Type == ActivityTypes.Message) { // Establish dialog state from the conversation state. DialogContext dc = await _dialogs.CreateContextAsync(turnContext, cancellationToken); //Custom Code Start | Added Code Block if (turnContext.Activity.Text.ToLowerInvariant() == "cancel") { await dc.CancelAllDialogsAsync(cancellationToken); } //Custom Code End // Continue any current dialog. DialogTurnResult dialogTurnResult = await dc.ContinueDialogAsync(); // Process the result of any complete dialog. if (dialogTurnResult.Status is DialogTurnStatus.Complete) { switch (dialogTurnResult.Result) { case BotUserEntityContext botUserEntityContext: if (botUserEntityContext.module != "Choose an area") { // Store the results of the root dialog. currentBotUserData.botUserEntityContext = botUserEntityContext; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); await dc.PromptAsync(ConfirmPromptId, new PromptOptions { Prompt = MessageFactory.Text($"Please confirm that you want to {botUserEntityContext.entityIntent} {botUserEntityContext.entity}. Is that correct?") }, cancellationToken); } else { await turnContext.SendActivityAsync("OK, Let's choose a different area.", cancellationToken : cancellationToken); await dc.BeginDialogAsync(RootDialogId, null, cancellationToken); } break; case bool botYesNo: if (botYesNo) { switch (currentBotUserData.botUserEntityContext.entity) { case "PickBatchPicking": if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { //Custom Code Start | Replaced Code Block //Replaced Code Block Start //await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, null, cancellationToken); //Replaced Code Block End await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, new PickBatchPickingPost(), cancellationToken); //Custom Code End } break; case "PutAwayHandlingUnits": if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { await dc.BeginDialogAsync(CreatePutAwayHandlingUnitsDialogId, null, cancellationToken); } break; case "SetUpExecutionParameters": if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { await dc.BeginDialogAsync(CreateSetUpExecutionParametersDialogId, null, cancellationToken); } break; case "DropInventoryUnits": if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { await dc.BeginDialogAsync(CreateDropInventoryUnitsDialogId, null, cancellationToken); } break; default: // We shouldn't get here. break; } } else { await turnContext.SendActivityAsync(MessageFactory.Text("OK, let's try again."), cancellationToken); await dc.BeginDialogAsync(RootDialogId, null, cancellationToken); } break; case GetPickBatchesPost getpickbatchesPost: if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { //Custom Code Start | Removed Block //ixGetPickBatch = await _getpickbatchesService.Create(getpickbatchesPost); //await turnContext.SendActivityAsync(MessageFactory.Text($"The GetPickBatch {ixGetPickBatch} was created"), cancellationToken); //currentBotUserData.ixGetPickBatch = ixGetPickBatch; //Custom Code End await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken); //Custom Code Start | Added Code Block //We can now set the pick batch status to started var pickbatch = _pickbatchesService.GetPost(_pickbatchesService.IndexDb().Where(x => x.sPickBatch == getpickbatchesPost.sGetPickBatch).Select(x => x.ixPickBatch).FirstOrDefault()); pickbatch.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Started").Select(x => x.ixStatus).FirstOrDefault(); pickbatch.UserName = dc.Context.Activity.Conversation.Id; await _pickbatchesService.Edit(pickbatch); _pickbatchpickingPost.sPickBatchPick = getpickbatchesPost.sGetPickBatch; await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, _pickbatchpickingPost, cancellationToken); //Custom Code End } break; case PickBatchPickingPost pickbatchpickingPost: if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { ixPickBatchPick = await _pickbatchpickingService.Create(pickbatchpickingPost); //Custom Code Start | Removed Block //await turnContext.SendActivityAsync(MessageFactory.Text($"The PickBatchPick {ixPickBatchPick} was created"), cancellationToken); //Custom Code End //Custom Code Start | Added Code Block //We check if the batch is complete if (!_picking.isPickBatchComplete(pickbatchpickingPost.ixPickBatch)) { currentBotUserData.ixPickBatchPick = ixPickBatchPick; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, pickbatchpickingPost, cancellationToken); } else { currentBotUserData.ixPickBatchPick = 0; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken); //We can now set the pick batch status to complete var pickbatch = _pickbatchesService.GetPost(pickbatchpickingPost.ixPickBatch); pickbatch.ixStatus = _commonLookUps.getStatuses().Where(x => x.sStatus == "Complete").Select(x => x.ixStatus).FirstOrDefault(); pickbatch.UserName = dc.Context.Activity.Conversation.Id; await _pickbatchesService.Edit(pickbatch); //We begin the drop cycle await dc.BeginDialogAsync(CreateDropInventoryUnitsDialogId, pickbatchpickingPost, cancellationToken); } //Custom Code End } break; case PutAwayHandlingUnitsPost putawayhandlingunitsPost: if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { ixPutAwayHandlingUnit = await _putawayhandlingunitsService.Create(putawayhandlingunitsPost); //Custom Code Start | Removed Block //await turnContext.SendActivityAsync(MessageFactory.Text($"The PutAwayHandlingUnit {ixPutAwayHandlingUnit} was created"), cancellationToken); //Custom Code End currentBotUserData.ixPutAwayHandlingUnit = ixPutAwayHandlingUnit; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); //Custom Code Start | Replaced Code Block //Replaced Code Block Start //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken); //Replaced Code Block End await dc.BeginDialogAsync(CreatePutAwayHandlingUnitsDialogId, null, cancellationToken); //Custom Code End } break; case SetUpExecutionParametersPost setupexecutionparametersPost: if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { //Custom Code Start | Removed Block //ixSetUpExecutionParameter = await _setupexecutionparametersService.Create(setupexecutionparametersPost); //await turnContext.SendActivityAsync(MessageFactory.Text($"The SetUpExecutionParameter {ixSetUpExecutionParameter} was created"), cancellationToken); //currentBotUserData.ixSetUpExecutionParameter = ixSetUpExecutionParameter; //Custom Code End //Custom Code Start | Added Code Block currentBotUserData.ixFacility = setupexecutionparametersPost.ixFacility; currentBotUserData.ixCompany = setupexecutionparametersPost.ixCompany; currentBotUserData.ixFacilityWorkArea = setupexecutionparametersPost.ixFacilityWorkArea; //We check if the user location exists - if not we create it if (_userManager.Users.Where(x => x.UserName == dc.Context.Activity.Conversation.Id).Any()) { if (!_inventorylocationsService.IndexDb().Where(x => x.sInventoryLocation.ToLower().Trim() == dc.Context.Activity.Conversation.Id.ToLower().Trim()).Any()) { InventoryLocationsPost inventoryLocationsPost = new InventoryLocationsPost(); inventoryLocationsPost.sInventoryLocation = dc.Context.Activity.Conversation.Id.ToLower().Trim(); inventoryLocationsPost.ixLocationFunction = _locationfunctionsService.IndexDb().Where(x => x.sLocationFunctionCode == "PE").Select(x => x.ixLocationFunction).FirstOrDefault(); inventoryLocationsPost.ixFacility = currentBotUserData.ixFacility; inventoryLocationsPost.ixFacilityFloor = _inventorylocationsService.FacilityFloorsDb().Select(x => x.ixFacilityFloor).FirstOrDefault(); inventoryLocationsPost.ixFacilityZone = _inventorylocationsService.FacilityZonesDb().Select(x => x.ixFacilityZone).FirstOrDefault(); inventoryLocationsPost.ixFacilityWorkArea = _inventorylocationsService.FacilityWorkAreasDb().Select(x => x.ixFacilityWorkArea).FirstOrDefault(); inventoryLocationsPost.ixFacilityAisleFace = _inventorylocationsService.FacilityAisleFacesDb().Select(x => x.ixFacilityAisleFace).FirstOrDefault(); inventoryLocationsPost.nSequence = 0; inventoryLocationsPost.bTrackUtilisation = false; currentBotUserData.ixInventoryLocation = await _inventorylocationsService.Create(inventoryLocationsPost); } else { currentBotUserData.ixInventoryLocation = _inventorylocationsService.IndexDb().Where(x => x.sInventoryLocation.ToLower().Trim() == dc.Context.Activity.Conversation.Id.ToLower().Trim()).Select(x => x.ixInventoryLocation).FirstOrDefault(); var inventoryLocationsPost = _inventorylocationsService.GetPost(currentBotUserData.ixInventoryLocation); inventoryLocationsPost.ixFacility = currentBotUserData.ixFacility; await _inventorylocationsService.Edit(inventoryLocationsPost); } } //Custom Code End await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); //Custom Code Start | Removed Block //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken); //Custom Code End //Custom Code Start | Added Code Block await turnContext.SendActivityAsync(MessageFactory.Text($"The setup parameters have been updated. Say/type putaway, pick or cancel."), cancellationToken); //Custom Code End } break; case DropInventoryUnitsPost dropinventoryunitsPost: if (currentBotUserData.botUserEntityContext.entityIntent == "Create") { //Custom Code Start | Removed Block //ixDropInventoryUnit = await _dropinventoryunitsService.Create(dropinventoryunitsPost); //await turnContext.SendActivityAsync(MessageFactory.Text($"The DropInventoryUnit {ixDropInventoryUnit} was created"), cancellationToken); //currentBotUserData.ixDropInventoryUnit = ixDropInventoryUnit; //await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); //await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); //await dc.BeginDialogAsync(RootDialogId, currentBotUserData.botUserEntityContext, cancellationToken); //Custom Code End await dc.BeginDialogAsync(CreateGetPickBatchesDialogId, null, cancellationToken); } break; default: // We shouldn't get here. break; } } // Proactively send a welcome message to a personal chat the first time // (and only the first time) a user initiates a personal chat. //Custom Code Start | Replaced Code Block //Replaced Code Block Start //if (didBotWelcomeUser == false) //Replaced Code Block End if (true == false) //Custom Code End { // Update user state flag to reflect bot handled first user interaction. await _botSpielUserStateAccessors.DidBotWelcomeUser.SetAsync(turnContext, true); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); // the channel should sends the user name in the 'From' object var userName = turnContext.Activity.From.Name; // We give the user the opportunity to say or request something using natural language and funnel through recognizer await turnContext.SendActivityAsync($"What would like to do? You can say things like ... or help me.", cancellationToken : cancellationToken); } //Custom Code Start | Added Code Block else if (!currentBotUserData.bIsInitialSetUpParametersSet) { currentBotUserData.bIsInitialSetUpParametersSet = true; currentBotUserData.botUserEntityContext.module = "Execution"; currentBotUserData.botUserEntityContext.entity = "SetUpExecutionParameters"; currentBotUserData.botUserEntityContext.entityIntent = "Create"; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); await dc.BeginDialogAsync(CreateSetUpExecutionParametersDialogId, null, cancellationToken); } //Custom Code End else if ((dialogTurnResult.Status is DialogTurnStatus.Empty) || turnContext.Activity.Text.ToLowerInvariant() == "putaway" || turnContext.Activity.Text.ToLowerInvariant() == "cancel") { var text = turnContext.Activity.Text.ToLowerInvariant(); // Now attempt to infer the context (NLP) // Placeholder for code to added switch (text) { //Custom Code Start | Removed Block //case "help me": // await turnContext.SendActivityAsync($"You said: {text}.", cancellationToken: cancellationToken); // break; //Custom Code End //Custom Code Start | Added Code Block case "putaway": currentBotUserData.botUserEntityContext.module = "Execution"; currentBotUserData.botUserEntityContext.entity = "PutAwayHandlingUnits"; currentBotUserData.botUserEntityContext.entityIntent = "Create"; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); await dc.BeginDialogAsync(CreatePutAwayHandlingUnitsDialogId, null, cancellationToken); break; case "pick": currentBotUserData.botUserEntityContext.module = "Execution"; currentBotUserData.botUserEntityContext.entity = "PickBatchPicking"; currentBotUserData.botUserEntityContext.entityIntent = "Create"; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(turnContext, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); //await dc.BeginDialogAsync(CreatePickBatchPickingDialogId, new PickBatchPickingPost(), cancellationToken); await dc.BeginDialogAsync(CreateGetPickBatchesDialogId, null, cancellationToken); break; case "cancel": await dc.CancelAllDialogsAsync(cancellationToken); break; //Custom Code End default: if (dc.ActiveDialog == null && (dialogTurnResult.Status is DialogTurnStatus.Complete || dialogTurnResult.Status is DialogTurnStatus.Empty || dialogTurnResult.Status is DialogTurnStatus.Cancelled)) { await turnContext.SendActivityAsync("I do not understand, let's try something different.", cancellationToken : cancellationToken); await dc.BeginDialogAsync(RootDialogId, null, cancellationToken); } break; } } } else if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate) { if (turnContext.Activity.MembersAdded.Any()) { // Iterate over all new members added to the conversation foreach (var member in turnContext.Activity.MembersAdded) { if (member.Id != turnContext.Activity.Recipient.Id) { await turnContext.SendActivityAsync($"Hi there - {member.Name}. {WelcomeMessage}", cancellationToken : cancellationToken); } } } } else { // Default behaviour for all other type of activities. await turnContext.SendActivityAsync($"{turnContext.Activity.Type} activity detected"); } // save any state changes made to your state objects. await _botSpielUserStateAccessors.UserState.SaveChangesAsync(turnContext); await _botSpielUserStateAccessors.ConversationState.SaveChangesAsync(turnContext); }
private async Task <DialogTurnResult> donePrompt( WaterfallStepContext step, CancellationToken cancellationToken = default(CancellationToken)) { var sDropInventoryUnit = (string)step.Result; ((DropInventoryUnitsPost)step.Values[DialogKey]).sDropInventoryUnit = sDropInventoryUnit; //Custom Code Start | Added Code Block var currentBotUserData = await _botSpielUserStateAccessors.BotUserDataAccessor.GetAsync(step.Context, () => _botUserData); var ixInventoryLocationDrop = _inventorylocationsService.IndexDb().Where(x => x.sInventoryLocation.Trim().ToLower() == sDropInventoryUnit.Trim().ToLower() && x.ixFacility == currentBotUserData.ixFacility).Select(x => x.ixInventoryLocation).FirstOrDefault(); //We drop all the inventory on the user //We now create and execute the move queue for the drop List <Int64> moveQueues = new List <long>(); var handlingUnitsToDrop = _movequeuesService.InventoryUnitsDb().Where(x => x.ixInventoryLocation == currentBotUserData.ixInventoryLocation && x.nBaseUnitQuantity > 0 && x.ixStatus == _commonLookUps.getStatuses().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault() && x.ixHandlingUnit > 0 ).Select(x => x.ixHandlingUnit).Distinct().ToList(); if (handlingUnitsToDrop.Count() > 0) { var moveQueueType = _commonLookUps.getMoveQueueTypes().Where(mqt => mqt.sMoveQueueType == "Consolidated Pickup - Consolidated Drop").Select(mqt => mqt.ixMoveQueueType).FirstOrDefault(); var moveQueueContext = _commonLookUps.getMoveQueueContexts().Where(mqc => mqc.sMoveQueueContext == "Picking").Select(mqc => mqc.ixMoveQueueContext).FirstOrDefault(); var statusActive = _commonLookUps.getStatuses().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault(); var statusComplete = _commonLookUps.getStatuses().Where(s => s.sStatus == "Complete").Select(s => s.ixStatus).FirstOrDefault(); handlingUnitsToDrop.ForEach(x => { var moveQueuePostDrop = new MoveQueuesPost(); moveQueuePostDrop.ixMoveQueueType = moveQueueType; moveQueuePostDrop.ixMoveQueueContext = moveQueueContext; moveQueuePostDrop.ixSourceInventoryLocation = currentBotUserData.ixInventoryLocation; moveQueuePostDrop.ixTargetInventoryLocation = ixInventoryLocationDrop; moveQueuePostDrop.ixSourceHandlingUnit = x; moveQueuePostDrop.ixTargetHandlingUnit = x; moveQueuePostDrop.sPreferredResource = step.Context.Activity.Conversation.Id; moveQueuePostDrop.nBaseUnitQuantity = 0; moveQueuePostDrop.dtStartedAt = DateTime.Now; moveQueuePostDrop.ixStatus = statusActive; moveQueuePostDrop.UserName = step.Context.Activity.Conversation.Id; moveQueues.Add(_movequeuesService.Create(moveQueuePostDrop).Result); } ); moveQueues.ForEach(x => { var moveQueueDrop = _movequeuesService.GetPost(x); moveQueueDrop.dtCompletedAt = DateTime.Now; moveQueueDrop.ixStatus = statusComplete; moveQueueDrop.UserName = step.Context.Activity.Conversation.Id; _movequeuesService.Edit(moveQueueDrop); } ); } //Custom Code End return(await step.EndDialogAsync( (DropInventoryUnitsPost)step.Values[DialogKey], cancellationToken)); }