public ActionResult Create([Bind("ixInventoryLocation,sInventoryLocation,ixLocationFunction,ixFacility,ixCompany,ixFacilityFloor,ixFacilityZone,ixFacilityWorkArea,ixFacilityAisleFace,sLevel,sBay,sSlot,ixInventoryLocationSize,nSequence,nXOffset,ixXOffsetUnit,nYOffset,ixYOffsetUnit,nZOffset,ixZOffsetUnit,sLatitude,sLongitude,bTrackUtilisation,nUtilisationPercent,nQueuedUtilisationPercent")] InventoryLocationsPost inventorylocations) { if (ModelState.IsValid) { inventorylocations.UserName = User.Identity.Name; //Custom Code Start | Replaced Code Block //Replaced Code Block Start //_inventorylocationsService.Create(inventorylocations); //return RedirectToAction("Index"); //Replaced Code Block End var ixInventoryLocation = _inventorylocationsService.Create(inventorylocations).Result; return(RedirectToAction("Edit", new { id = ixInventoryLocation })); //Custom Code End } ViewBag.ixCompany = new SelectList(_inventorylocationsService.selectCompanies().Select(x => new { x.ixCompany, x.sCompany }), "ixCompany", "sCompany"); ViewBag.ixFacility = new SelectList(_inventorylocationsService.selectFacilities().Select(x => new { x.ixFacility, x.sFacility }), "ixFacility", "sFacility"); ViewBag.ixFacilityAisleFace = new SelectList(_inventorylocationsService.selectFacilityAisleFaces().Select(x => new { x.ixFacilityAisleFace, x.sFacilityAisleFace }), "ixFacilityAisleFace", "sFacilityAisleFace"); ViewBag.ixFacilityFloor = new SelectList(_inventorylocationsService.selectFacilityFloors().Select(x => new { x.ixFacilityFloor, x.sFacilityFloor }), "ixFacilityFloor", "sFacilityFloor"); ViewBag.ixFacilityWorkArea = new SelectList(_inventorylocationsService.selectFacilityWorkAreas().Select(x => new { x.ixFacilityWorkArea, x.sFacilityWorkArea }), "ixFacilityWorkArea", "sFacilityWorkArea"); ViewBag.ixFacilityZone = new SelectList(_inventorylocationsService.selectFacilityZones().Select(x => new { x.ixFacilityZone, x.sFacilityZone }), "ixFacilityZone", "sFacilityZone"); ViewBag.ixInventoryLocationSize = new SelectList(_inventorylocationsService.selectInventoryLocationSizes().Select(x => new { x.ixInventoryLocationSize, x.sInventoryLocationSize }), "ixInventoryLocationSize", "sInventoryLocationSize"); ViewBag.ixLocationFunction = new SelectList(_inventorylocationsService.selectLocationFunctions().Select(x => new { x.ixLocationFunction, x.sLocationFunction }), "ixLocationFunction", "sLocationFunction"); ViewBag.ixXOffsetUnit = new SelectList(_inventorylocationsService.selectUnitsOfMeasurement().Select(x => new { x.ixUnitOfMeasurement, x.sUnitOfMeasurement }), "ixUnitOfMeasurement", "sUnitOfMeasurement"); ViewBag.ixYOffsetUnit = new SelectList(_inventorylocationsService.selectUnitsOfMeasurement().Select(x => new { x.ixUnitOfMeasurement, x.sUnitOfMeasurement }), "ixUnitOfMeasurement", "sUnitOfMeasurement"); ViewBag.ixZOffsetUnit = new SelectList(_inventorylocationsService.selectUnitsOfMeasurement().Select(x => new { x.ixUnitOfMeasurement, x.sUnitOfMeasurement }), "ixUnitOfMeasurement", "sUnitOfMeasurement"); return(View(inventorylocations)); }
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); }