Exemple #1
0
        private async Task <DialogTurnResult> ValidateUserStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var choice     = (FoundChoice)stepContext.Result;
            var permission = choice.Value.GetValueFromDescription <PermissionLevels>();

            var prestashopId = stepContext.GetValue <int>("id");

            //If the user already asked for permission
            if (await UserController.CheckForUserProfileAsync(prestashopId))
            {
                await UserController.ValidateUserAsync(prestashopId, (int)permission);

                await NotifyController.NotifyValidation(prestashopId);
            }
            //If we're validating the user ahead of his first login
            else
            {
                var profile = new Models.UserProfile()
                {
                    Permission   = (int)permission,
                    PrestashopId = prestashopId,
                    Validated    = true
                };

                await UserController.AddUserAsync(profile);
            }

            await stepContext.Context.SendActivityAsync(MessageFactory.Text(
                                                            "A new user has been added. He can now login and start using Greta!"), cancellationToken);

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