public void GetEntityResolutions(LuisResult luisResult, FundSectorWeightsModel sectorModel) { var entities = luisResult.ConnectedServiceResult.Entities; if (entities != null) { foreach (EntityModel entity in entities) { switch (entity.Type) { //found a fund case FundName: var fund = Common.GetResolutionFromEntity(entity); if (fund.Trim().Length == 5) { sectorModel.AddFund(Common.tickersToFundName[fund.Trim().ToUpper()]); } else { sectorModel.AddFund(fund); } break; //found a sector case SectorType: sectorModel.Sector = Common.GetResolutionFromEntity(entity); break; default: break; } } } }
private async Task <DialogTurnResult> ParseGivenParametersAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var luisResult = (LuisResult)stepContext.Options; var sectorModel = new FundSectorWeightsModel(); sectorModel.Funds = new List <string>(); //find fund names and sector GetEntityResolutions(luisResult, sectorModel); stepContext.Values[FundSectorModelValue] = sectorModel; //if no sector was given if (string.IsNullOrEmpty(sectorModel.Sector)) { await stepContext.Context.SendActivityAsync(ChannelFormattingService.FormatSimpleMessage(stepContext.Context, "Please select a valid sector to view weighting information")); return(await stepContext.EndDialogAsync(null, cancellationToken)); } //if no funds were given, prompt the user to select a fund. else if (sectorModel.Funds.Count == 0) { var choices = Common.PIFundNames.ToList(); choices.Insert(0, "All funds"); var suggestedActions = SuggestedActionGenerator.GenerateSuggestedActions(choices); var reply = MessageFactory.Text(ChannelFormattingService.FormatSimpleMessage(stepContext.Context, $"Which fund would you like to see " + $"{CultureInfo.InvariantCulture.TextInfo.ToTitleCase(sectorModel.Sector)} sector weightings for?")); var retryReply = MessageFactory.Text(ChannelFormattingService.FormatSimpleMessage(stepContext.Context, "Please select a valid choice")); reply.SuggestedActions = suggestedActions; retryReply.SuggestedActions = suggestedActions; return(await stepContext.PromptAsync($"{nameof(FundSectorWeightsDialog)}.fundName", new PromptOptions { Prompt = reply, RetryPrompt = retryReply }, cancellationToken)); } return(await stepContext.NextAsync(null, cancellationToken)); }