コード例 #1
0
        public async Task ChangeName(IDialogContext context, LuisResult result)
        {
            List <EntityRecommendation> nameEntities = null;

            if (result.TryFindEntities("Name", out nameEntities))
            {
                var name     = "";
                var nameList = nameEntities.ConcatEntities(" ").Split(' ').ToList <string>();
                nameList.ForEach(str =>
                {
                    name += string.Concat(str[0].ToString().ToUpper(), str.Substring(1), " ");
                });
                name = name.Trim();

                // attempt to save applicant info
                var a = await ApplicantFactory.GetApplicantByContext(context);

                a.Name = name;
                await ApplicantFactory.PersistApplicant(a);

                await context.PostAsync(string.Format(Resources.msgIWillCallYou, name));

                context.Done <string>(null);
            }
            else
            {
                // prompt for the user's name
                PromptDialog.Text(context, ResumeAfterNameChangeAsync, Resources.msgWhatShouldICallYou);
            }
        }