Example #1
0
        private async Task <int> TryShowUser(ITurnContext turnContext, DialogStateProperties state, bool showMultiple = false)
        {
            var users = await _personStore.Search(state[EmployeeNameKey].ToString());

            if (users.Count() > 1 && state.ContainsKey(DepartmentKey))
            {
                users = users.Where(a => state[DepartmentKey].ToString().Normalize() == a.Area.Normalize());
            }

            if (!showMultiple)
            {
                if (users.Count() == 1)
                {
                    await SendCard(turnContext, users.First(), state[IntentKey].ToString());

                    await _personInternStateAccessor.DeleteAsync(turnContext);

                    await _dialogStateProperties.DeleteAsync(turnContext);
                }
            }
            else
            {
                foreach (var user in users)
                {
                    await SendCard(turnContext, user, state[IntentKey].ToString());
                }
            }

            return(users.Count());
        }
Example #2
0
        private async Task <DialogTurnResult> Initialize(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var state = new DialogStateProperties();

            var turnProperties = await _onTurnPropertyAccessor.GetAsync(stepContext.Context, () => new OnTurnProperty());

            var decomposedIntent = turnProperties.Intent.Split('-');

            state.Add(IntentKey, decomposedIntent[2]);

            var turnEntities = turnProperties.Entities;

            var name = turnEntities.FirstOrDefault(
                a => a.EntityName == EmployeeNameKey &&
                a.Value != null &&
                a.Value.ToString() != string.Empty);

            if (name != null)
            {
                var nameValue = ((JArray)name.Value).First().ToString();
                state.Add(EmployeeNameKey, nameValue);
            }

            var department = turnEntities.FirstOrDefault(
                a => a.EntityName == DepartmentKey &&
                a.Value != null &&
                a.ToString() != string.Empty);

            if (department != null)
            {
                var departmentValue = ((JArray)department.Value).First().ToString();
                state.Add(DepartmentKey, departmentValue);
            }

            await _dialogStateProperties.SetAsync(stepContext.Context, state);

            return(await stepContext.NextAsync());
        }