public Int64 getTrailerDoorSuggestion(Int64 ixFacility) { List <InventoryLocationsPost> putAwaySuggestions = new List <InventoryLocationsPost>(); //Receiving RC //Reserve Storage RV //Let Down Storage LD //Forward Pick Storage FP //Consolidation CN //Shipping SH //Staging ST //Trailer Doors TR //Person PE var allowedLocationFunctions = _locationfunctionsService.IndexDb().Where(x => x.sLocationFunctionCode == "CN" || x.sLocationFunctionCode == "SH" || x.sLocationFunctionCode == "ST" || x.sLocationFunctionCode == "TR" ).Select(x => x.ixLocationFunction).ToList(); //We implemenent a basic strategy we see if we a trailer door not currently assigned to a carrier manifest - if not we get the TR with the lowest sequence number var allocatedTrailerDoors = _outboundcarriermanifestsService.IndexDb().Where(x => x.ixStatus == _commonLookUps.getStatuses().Where(s => s.sStatus == "Active").Select(s => s.ixStatus).FirstOrDefault()).Select(x => x.ixPickupInventoryLocation).Distinct().ToList(); if (_inventorylocationsService.IndexDb().Where(x => x.ixFacility == ixFacility && x.LocationFunctions.sLocationFunctionCode == "TR" && !allocatedTrailerDoors.Contains(x.ixInventoryLocation) ).Any() ) { return(_inventorylocationsService.IndexDb().Where(x => x.ixFacility == ixFacility && x.LocationFunctions.sLocationFunctionCode == "TR" && !allocatedTrailerDoors.Contains(x.ixInventoryLocation) ).Select(x => x.ixInventoryLocation).FirstOrDefault()); } else { return(_inventorylocationsService.IndexDb().Where(x => x.ixFacility == ixFacility && x.LocationFunctions.sLocationFunctionCode == "TR" ).Select(x => x.ixInventoryLocation).FirstOrDefault()); } }
//Custom Code Start | Replaced Code Block //Replaced Code Block Start //public CreateDropInventoryUnitsDialog(string id, IDropInventoryUnitsService dropinventoryunitsService, DropInventoryUnitsPost dropinventoryunitsPost, BotSpielUserStateAccessors statePropertyAccessor) //Replaced Code Block End public CreateDropInventoryUnitsDialog(string id, IDropInventoryUnitsService dropinventoryunitsService, DropInventoryUnitsPost dropinventoryunitsPost, BotSpielUserStateAccessors statePropertyAccessor, Shipping shipping, IInventoryLocationsService inventorylocationsService, CommonLookUps commonLookUps, IMoveQueuesService movequeuesService) //Custom Code End : base(id) { InitialDialogId = Id; _botSpielUserStateAccessors = statePropertyAccessor ?? throw new System.ArgumentNullException("state accessor can't be null"); _dropinventoryunitsService = dropinventoryunitsService; _dropinventoryunitsPost = dropinventoryunitsPost; //Custom Code Start | Added Code Block _shipping = shipping; _inventorylocationsService = inventorylocationsService; _commonLookUps = commonLookUps; _movequeuesService = movequeuesService; //Custom Code End //Custom Code Start | Added Code Block PromptValidator <string> inventoryDropLocationValidator = async(promptContext, cancellationToken) => { var value = promptContext.Recognized.Value.Trim().ToLower(); var currentBotUserData = await _botSpielUserStateAccessors.BotUserDataAccessor.GetAsync(promptContext.Context, () => _botUserData); if (!_inventorylocationsService.IndexDb().Where(x => x.sInventoryLocation.Trim().ToLower() == value && x.ixFacility == currentBotUserData.ixFacility).Any()) { await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The inventory location {value} does not exist in the facility. Please enter a different value or exit."), cancellationToken); return(false); } //else //{ // if (currentBotUserData.sPutAwaySuggestion.Trim().ToLower() != value) // { // await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The inventory location {value} does not match the suggested location {currentBotUserData.sPutAwaySuggestion}. Please enter a different value or exit."), cancellationToken); // return false; // } // return true; //} return(true); }; //Custom Code End // Define the prompts used in the Dialog. AddDialog(new TextPrompt(DropInventoryUnitPromptId, inventoryDropLocationValidator)); // Define the conversation flow for the Dialog. WaterfallStep[] steps = new WaterfallStep[] { DropInventoryUnitPrompt, donePrompt, }; AddDialog(new WaterfallDialog(Id, steps)); }
public Int64 getPutAwaySuggestion(Int64 ixHandlingUnit, Int64 ixCompany, Int64 ixFacility, Int64 ixInventoryLocationUser) { var inventoryLocationUserPost = _inventorylocationsService.GetPost(ixInventoryLocationUser); List <InventoryLocationsPost> putAwaySuggestions = new List <InventoryLocationsPost>(); //Receiving RC //Reserve Storage RV //Let Down Storage LD //Forward Pick Storage FP //Consolidation CN //Shipping SH //Staging ST //Trailer Doors TR //Person PE var allowedLocationFunctions = _locationfunctionsService.IndexDb().Where(x => x.sLocationFunctionCode == "RV" || x.sLocationFunctionCode == "LD" || x.sLocationFunctionCode == "FP" ).Select(x => x.ixLocationFunction).ToList(); //We implement Proximity in bay to slotted location THEN Location type THEN Closest + Defaults var inventoryUnitsOnHandlingUnit = _inventoryunitsService.IndexDb().Where(x => x.ixHandlingUnit == ixHandlingUnit).ToList(); var materials = inventoryUnitsOnHandlingUnit.GroupBy(x => x.ixMaterial) .Select(y => new { ixMaterial = y.Key, nTotalBaseUnits = y.Sum(u => u.nBaseUnitQuantity) } ).ToList(); var ixMaterialDominant = materials.OrderByDescending(x => x.nTotalBaseUnits).Select(x => x.ixMaterial).FirstOrDefault(); var slottedLocations = _inventorylocationsslottingService.IndexDb().Where(x => x.ixMaterial == ixMaterialDominant && x.InventoryLocations.ixFacility == ixFacility).ToList(); if (slottedLocations.Count() > 0) //We have slotted locations { var locationsslotted = _inventorylocationsService.IndexDbPost().Where(x => slottedLocations.Select(y => y.ixInventoryLocation).Contains(x.ixInventoryLocation)).ToList(); //var slottedlocationsPost = locationsslotted.Select(l => _inventorylocationsService.GetPost(l.ixInventoryLocation)).ToList(); putAwaySuggestions = locationsslotted.Where(x => _volumeAndWeight.handlingUnitWillFitLocation(ixHandlingUnit, inventoryUnitsOnHandlingUnit, x)).ToList(); if (putAwaySuggestions.Count() > 0) { //We now apply the defaults - we look for the location with the most inventory var inventoryInSlottedLocations = _inventoryunitsService.IndexDbPost().Where(x => x.ixFacility == ixFacility && x.ixCompany == ixCompany && putAwaySuggestions.Select(s => s.ixInventoryLocation).Contains(x.ixInventoryLocation)).ToList(); if (inventoryInSlottedLocations.Count() > 0) { var ixInventoryLocationSuggestion = inventoryInSlottedLocations.GroupBy(x => x.ixInventoryLocation) .Select(y => new { ixInventoryLocation = y.Key, nTotalBaseUnits = y.Sum(u => u.nBaseUnitQuantity) } ) .OrderByDescending(z => z.nTotalBaseUnits) .Select(s => s.ixInventoryLocation).FirstOrDefault(); return(ixInventoryLocationSuggestion); } else { return(putAwaySuggestions.Select(x => x.ixInventoryLocation).FirstOrDefault()); } } //else //Now we look for locations in the slotted locations bays closest to the slotted location (To be implemented) //{ //} } //Now we attempt to consolidate the inventory var existingInventoryLocations = _inventoryunitsService.IndexDb().Where(x => x.ixFacility == ixFacility && x.ixCompany == ixCompany && x.ixMaterial == ixMaterialDominant && allowedLocationFunctions.Contains(x.InventoryLocations.ixLocationFunction)).ToList(); var existingInventoryLocationsPost = existingInventoryLocations.Select(l => _inventorylocationsService.GetPost(l.ixInventoryLocation)).Distinct().ToList(); putAwaySuggestions = existingInventoryLocationsPost.Where(x => _volumeAndWeight.handlingUnitWillFitLocation(ixHandlingUnit, inventoryUnitsOnHandlingUnit, x)).ToList(); if (putAwaySuggestions.Count() > 0) //We have locations with existing inventory that fits. { //We now apply the defaults - we look for the location with the most inventory var existinginventoryInLocations = _inventoryunitsService.IndexDb().Where(x => putAwaySuggestions.Select(s => s.ixInventoryLocation).Contains(x.ixInventoryLocation)).ToList(); if (existinginventoryInLocations.Count() > 0) { var ixInventoryLocationSuggestion = existinginventoryInLocations.GroupBy(x => x.ixInventoryLocation) .Select(y => new { ixInventoryLocation = y.Key, nTotalBaseUnits = y.Sum(u => u.nBaseUnitQuantity) } ) .OrderByDescending(z => z.nTotalBaseUnits) .Select(s => s.ixInventoryLocation).FirstOrDefault(); return(ixInventoryLocationSuggestion); } else { return(putAwaySuggestions.Select(x => x.ixInventoryLocation).FirstOrDefault()); } } //Now we look for empty locations by function (LD and RV) and proximity to the user (To be refined for performance) var userLocation = _inventorylocationsService.GetPost(ixInventoryLocationUser); var ldLocactionsInFacility = _inventorylocationsService.IndexDb().Where(x => x.ixFacility == ixFacility && x.LocationFunctions.sLocationFunctionCode == "LD").ToList(); var ldLocactionsInFacilityWithInventory = _inventoryunitsService.IndexDb().Where(x => x.ixFacility == ixFacility && x.ixCompany == ixCompany && x.InventoryLocations.LocationFunctions.sLocationFunctionCode == "LD").ToList(); var ldLocactionsInFacilityEmpty = ldLocactionsInFacility.Select(x => x.ixInventoryLocation).Except(ldLocactionsInFacilityWithInventory.Select(x => x.ixInventoryLocation)).ToList(); var ldLocactionsInFacilityEmptyPost = ldLocactionsInFacilityEmpty.Select(l => _inventorylocationsService.GetPost(l)).Distinct().ToList(); putAwaySuggestions = ldLocactionsInFacilityEmptyPost.Where(x => _volumeAndWeight.handlingUnitWillFitLocation(ixHandlingUnit, inventoryUnitsOnHandlingUnit, x)).ToList(); if (putAwaySuggestions.Count() > 0) //We have LD empty locations that fits. { var ixInventoryLocationSuggestion = putAwaySuggestions.Select(x => new { x.ixInventoryLocation, nProximity = Math.Abs(x.nSequence - inventoryLocationUserPost.nSequence) }).OrderBy(x => x.nProximity).Select(x => x.ixInventoryLocation).FirstOrDefault(); return(ixInventoryLocationSuggestion); } var rvLocactionsInFacility = _inventorylocationsService.IndexDb().Where(x => x.ixFacility == ixFacility && x.LocationFunctions.sLocationFunctionCode == "RV").ToList(); var rvLocactionsInFacilityWithInventory = _inventoryunitsService.IndexDb().Where(x => x.ixFacility == ixFacility && x.ixCompany == ixCompany && x.InventoryLocations.LocationFunctions.sLocationFunctionCode == "RV").ToList(); var rvLocactionsInFacilityEmpty = rvLocactionsInFacility.Select(x => x.ixInventoryLocation).Except(ldLocactionsInFacilityWithInventory.Select(x => x.ixInventoryLocation)).ToList(); var rvLocactionsInFacilityEmptyPost = rvLocactionsInFacilityEmpty.Select(l => _inventorylocationsService.GetPost(l)).Distinct().ToList(); putAwaySuggestions = rvLocactionsInFacilityEmptyPost.Where(x => _volumeAndWeight.handlingUnitWillFitLocation(ixHandlingUnit, inventoryUnitsOnHandlingUnit, x)).ToList(); if (putAwaySuggestions.Count() > 0) //We have RV empty locations that fits. { var ixInventoryLocationSuggestion = putAwaySuggestions.Select(x => new { x.ixInventoryLocation, nProximity = Math.Abs(x.nSequence - inventoryLocationUserPost.nSequence) }).OrderBy(x => x.nProximity).Select(x => x.ixInventoryLocation).FirstOrDefault(); return(ixInventoryLocationSuggestion); } return(0); }
//Custom Code Start | Replaced Code Block //Replaced Code Block Start //public CreatePutAwayHandlingUnitsDialog(string id, IPutAwayHandlingUnitsService putawayhandlingunitsService, PutAwayHandlingUnitsPost putawayhandlingunitsPost, BotSpielUserStateAccessors statePropertyAccessor) //Replaced Code Block End public CreatePutAwayHandlingUnitsDialog(string id , IPutAwayHandlingUnitsService putawayhandlingunitsService , PutAwayHandlingUnitsPost putawayhandlingunitsPost , BotSpielUserStateAccessors statePropertyAccessor , IHandlingUnitsService handlingunitsService , PutAway putAway , BotUserData botUserData , IInventoryLocationsService inventorylocationsService , IMoveQueueTypesService movequeuetypesService , IMoveQueueContextsService movequeuecontextsService , IInventoryUnitsService inventoryunitsService , IStatusesService statusesService , IMoveQueuesService movequeuesService ) //Custom Code End : base(id) { InitialDialogId = Id; _botSpielUserStateAccessors = statePropertyAccessor ?? throw new System.ArgumentNullException("state accessor can't be null"); _putawayhandlingunitsService = putawayhandlingunitsService; _putawayhandlingunitsPost = putawayhandlingunitsPost; //Custom Code Start | Added Code Block _handlingunitsService = handlingunitsService; _putAway = putAway; _botUserData = botUserData; _inventorylocationsService = inventorylocationsService; _movequeuetypesService = movequeuetypesService; _movequeuecontextsService = movequeuecontextsService; _inventoryunitsService = inventoryunitsService; _statusesService = statusesService; _movequeuesService = movequeuesService; PromptValidator <string> putAwayHandlingUnitValidator = async(promptContext, cancellationToken) => { var value = promptContext.Recognized.Value.Trim().ToLower(); if (!_handlingunitsService.IndexDb().Where(x => x.sHandlingUnit.Trim().ToLower() == value).Any()) { await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The handling unit {value} does not exist. Please enter a different value or exit."), cancellationToken); return(false); } else { return(true); } }; PromptValidator <string> inventoryDropLocationValidator = async(promptContext, cancellationToken) => { var value = promptContext.Recognized.Value.Trim().ToLower(); var currentBotUserData = await _botSpielUserStateAccessors.BotUserDataAccessor.GetAsync(promptContext.Context, () => _botUserData); if (!_inventorylocationsService.IndexDb().Where(x => x.sInventoryLocation.Trim().ToLower() == value && x.ixFacility == currentBotUserData.ixFacility).Any() && currentBotUserData.sPutAwaySuggestion == "No Suggestion") { await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The inventory location {value} does not exist in the facility. Please enter a different value or exit."), cancellationToken); return(false); } else { if (currentBotUserData.sPutAwaySuggestion.Trim().ToLower() != value) { await promptContext.Context.SendActivityAsync(MessageFactory.Text($"The inventory location {value} does not match the suggested location {currentBotUserData.sPutAwaySuggestion}. Please 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(PutAwayHandlingUnitPromptId)); //Replaced Code Block End AddDialog(new TextPrompt(PutAwayHandlingUnitPromptId, putAwayHandlingUnitValidator)); //Custom Code End AddDialog(new TextPrompt(InventoryDropLocationPromptId, inventoryDropLocationValidator)); // Define the conversation flow for the Dialog. WaterfallStep[] steps = new WaterfallStep[] { PutAwayHandlingUnitPrompt, InventoryDropLocationPrompt, donePrompt, }; AddDialog(new WaterfallDialog(Id, steps)); }
private async Task <DialogTurnResult> InventoryDropLocationPrompt( WaterfallStepContext step, CancellationToken cancellationToken = default(CancellationToken)) { var sPutAwayHandlingUnit = (string)step.Result; ((PutAwayHandlingUnitsPost)step.Values[DialogKey]).sPutAwayHandlingUnit = sPutAwayHandlingUnit; //Custom Code Start | Added Code Block var currentBotUserData = await _botSpielUserStateAccessors.BotUserDataAccessor.GetAsync(step.Context, () => _botUserData); var ixHandlingUnit = _handlingunitsService.IndexDb().Where(x => x.sHandlingUnit.Trim().ToLower() == sPutAwayHandlingUnit).Select(x => x.ixHandlingUnit).FirstOrDefault(); ((PutAwayHandlingUnitsPost)step.Values[DialogKey]).ixHandlingUnit = ixHandlingUnit; //We now create and execute the move queue for the pickup MoveQueuesPost moveQueuePost = new MoveQueuesPost(); moveQueuePost.ixMoveQueueType = _movequeuetypesService.IndexDb().Where(x => x.sMoveQueueType == "Consolidated Pickup - Consolidated Drop").Select(x => x.ixMoveQueueType).FirstOrDefault(); moveQueuePost.ixMoveQueueContext = _movequeuecontextsService.IndexDb().Where(x => x.sMoveQueueContext == "Putaway").Select(x => x.ixMoveQueueContext).FirstOrDefault(); moveQueuePost.ixSourceInventoryLocation = _inventoryunitsService.IndexDbPost().Where(x => x.ixHandlingUnit == ixHandlingUnit).Select(x => x.ixInventoryLocation).FirstOrDefault(); moveQueuePost.ixTargetInventoryLocation = currentBotUserData.ixInventoryLocation; moveQueuePost.ixSourceHandlingUnit = ixHandlingUnit; moveQueuePost.ixTargetHandlingUnit = ixHandlingUnit; moveQueuePost.sPreferredResource = step.Context.Activity.Conversation.Id; moveQueuePost.nBaseUnitQuantity = 0; moveQueuePost.dtStartedAt = DateTime.Now; moveQueuePost.ixStatus = _statusesService.IndexDb().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 = _statusesService.IndexDb().Where(x => x.sStatus == "Complete").Select(x => x.ixStatus).FirstOrDefault(); moveQueuePickUp.UserName = moveQueuePost.UserName; await _movequeuesService.Edit(moveQueuePickUp); var ixInventoryLocationSuggestion = _putAway.getPutAwaySuggestion(ixHandlingUnit, currentBotUserData.ixCompany, currentBotUserData.ixFacility, currentBotUserData.ixInventoryLocation); string sPutAwaySuggestion = ""; if (_inventorylocationsService.IndexDb().Where(x => x.ixInventoryLocation == ixInventoryLocationSuggestion).Any()) { sPutAwaySuggestion = _inventorylocationsService.IndexDb().Where(x => x.ixInventoryLocation == ixInventoryLocationSuggestion).Select(x => x.sInventoryLocation).FirstOrDefault(); //We now create the move queue for the drop MoveQueuesPost moveQueuePostDrop = new MoveQueuesPost(); moveQueuePostDrop.ixMoveQueueType = moveQueuePost.ixMoveQueueType; moveQueuePostDrop.ixMoveQueueContext = moveQueuePost.ixMoveQueueContext; moveQueuePostDrop.ixSourceInventoryLocation = currentBotUserData.ixInventoryLocation; moveQueuePostDrop.ixTargetInventoryLocation = ixInventoryLocationSuggestion; moveQueuePostDrop.ixSourceHandlingUnit = ixHandlingUnit; moveQueuePostDrop.ixTargetHandlingUnit = ixHandlingUnit; moveQueuePostDrop.sPreferredResource = step.Context.Activity.Conversation.Id; moveQueuePostDrop.nBaseUnitQuantity = 0; moveQueuePostDrop.dtStartedAt = DateTime.Now; moveQueuePostDrop.ixStatus = _statusesService.IndexDb().Where(x => x.sStatus == "Active").Select(x => x.ixStatus).FirstOrDefault(); moveQueuePostDrop.UserName = step.Context.Activity.Conversation.Id; var ixMoveQueueDrop = await _movequeuesService.Create(moveQueuePostDrop); step.Values[MoveQueuePostDropKey] = moveQueuePostDrop; } else { sPutAwaySuggestion = "No Suggestion"; } step.Values[PutAwaySuggestionKey] = sPutAwaySuggestion; currentBotUserData.sPutAwaySuggestion = sPutAwaySuggestion; await _botSpielUserStateAccessors.BotUserDataAccessor.SetAsync(step.Context, currentBotUserData, cancellationToken); await _botSpielUserStateAccessors.UserState.SaveChangesAsync(step.Context); //Custom Code End return(await step.PromptAsync( InventoryDropLocationPromptId, new PromptOptions { Prompt = MessageFactory.Text($"The suggested drop location is {sPutAwaySuggestion}.{Environment.NewLine} Please enter/scan the Inventory Drop Location."), RetryPrompt = MessageFactory.Text("I didn't understand. Please try again."), }, cancellationToken)); }
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)); }