Ejemplo n.º 1
0
        public async Task <DialogTurnResult> GetAttributionsAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var fundName         = (string)stepContext.Result;
            var attributionModel = (FundAttributionModel)stepContext.Values[FundAttributionModelValue];

            //save given fund name (if any) to the model
            if (fundName != null)
            {
                fundName = fundName.Trim().ToLower();

                //if selected choice was "Mid cap fund" etc, we must add PI to the front. (does not apply to PI Fund)
                if (fundName != Common.PIFundNames[Common.PIFundIndexInNamesList].ToLower())
                {
                    fundName = "PI " + fundName;
                }

                attributionModel.FundName = fundName;
            }

            //get fund contributors or detractors
            var fundAttributions = APIService.GetFundAttributions(attributionModel).Result;

            //format it in a header -> subtitle -> data
            var placeholder = attributionModel.ContributorsOrDetractors == 0 ? "contributors" : "detractors";
            var response    = ChannelFormattingService.FormatHeaderSubtitleAndList(stepContext.Context,
                                                                                   $"{attributionModel.FundTicker} top {placeholder}:", fundAttributions);

            await stepContext.Context.SendActivityAsync(response, null, null, cancellationToken);

            return(await stepContext.EndDialogAsync(null, cancellationToken));
        }
        private async Task <DialogTurnResult> GetSectorWeightingsAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var fundName    = (string)stepContext.Result;
            var sectorModel = (FundSectorWeightsModel)stepContext.Values[FundSectorModelValue];

            //if a fund was selected from the previous step, save it to the model.
            if (fundName != null)
            {
                fundName = fundName.Trim().ToLower();

                if (fundName != "all funds" && fundName != Common.PIFundNames[Common.PIFundIndexInNamesList].ToLower())
                {
                    fundName = "PI " + fundName;
                }

                sectorModel.AddFund(fundName);
            }

            //if the funds requested contains the fixed income fund, tell the user that no sector weightings exist and remove it.
            if (sectorModel.Funds.Any(s => s == "PRFIX"))
            {
                await stepContext.Context.SendActivityAsync(ChannelFormattingService.FormatSimpleMessage(stepContext.Context, "The PI Fixed Income Fund does not contain sector weightings"));

                sectorModel.Funds.RemoveAll(s => s == "PRFIX");
                stepContext.Values[FundSectorModelValue] = sectorModel;

                //if the fixed income fund was the only fund requested, end the dialog.
                if (sectorModel.Funds.Count == 0)
                {
                    return(await stepContext.EndDialogAsync(null, cancellationToken));
                }
            }

            //get the fund sector weights
            var fundSectorWeights = APIService.GetFundSectorWeights(sectorModel).Result;

            //format the sector weights in header -> subtitles -> list.
            var response = ChannelFormattingService.FormatHeaderSubtitleAndList(stepContext.Context,
                                                                                $"{CultureInfo.InvariantCulture.TextInfo.ToTitleCase(sectorModel.Sector)} sector weights", fundSectorWeights);

            await stepContext.Context.SendActivityAsync(response, null, null, cancellationToken);

            return(await stepContext.EndDialogAsync(null, cancellationToken));
        }
Ejemplo n.º 3
0
        private async Task <DialogTurnResult> GetHoldingsStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var fundName     = ((string)stepContext.Result);
            var holdingModel = (FundHoldingsModel)stepContext.Values[FundHoldingModelValue];

            //if a fund name was selected from the previous step, save it to the model
            if (fundName != null)
            {
                fundName = fundName.Trim().ToLower();

                if (fundName == "all funds")
                {
                    holdingModel.AllFunds = true;
                }
                else if (fundName != Common.PIFundNames[Common.PIFundIndexInNamesList].ToLower())
                {
                    fundName = "PI " + fundName;
                }

                holdingModel.FundName.Add(fundName);
                stepContext.Values[FundHoldingModelValue] = holdingModel;
            }

            //get all holdings
            var allHoldings = await APIService.GetFundHoldingsAttributes(holdingModel);

            //if none were found,the company is not a holding in the requested funds.
            if (allHoldings == null)
            {
                await stepContext.Context.SendActivityAsync(ChannelFormattingService.FormatSimpleMessage(stepContext.Context, $"{CultureInfo.InvariantCulture.TextInfo.ToTitleCase(holdingModel.Company)} is not a holding in the requested fund"));

                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }

            //format the holdings in a header -> subititle -> list
            var response = ChannelFormattingService.FormatHeaderSubtitleAndList(stepContext.Context,
                                                                                $"{CultureInfo.InvariantCulture.TextInfo.ToTitleCase(holdingModel.Company)}" + " holding information:", allHoldings);

            await stepContext.Context.SendActivityAsync(response, null, null, cancellationToken);

            return(await stepContext.EndDialogAsync(null, cancellationToken));
        }