Ejemplo n.º 1
0
        public void Execute(object parameter)
        {
            var userProfileDialog = new UserProfileDialog
               {
                   Title = "Edit Profile",
                   Buttons = new Button[] { } //TODO-VKY: This will be removed when NuGet fix "ModernDialog ShowDialog always return false".
               };

            if (_mainWindowViewModel.SelectedUser != null)
            {
                userProfileDialog.UserProfile.FirstName = _mainWindowViewModel.SelectedUser.FirstName;
                userProfileDialog.UserProfile.LastName = _mainWindowViewModel.SelectedUser.LastName;
                userProfileDialog.UserProfile.Email = _mainWindowViewModel.SelectedUser.Email;
                userProfileDialog.Title = "Edit Profile" + "-" + _mainWindowViewModel.SelectedUser.FirstName;
            }

            // userProfileDialog.Buttons = new Button[] { userProfileDialog.OkButton, userProfileDialog.CancelButton };

            if (userProfileDialog.ShowDialog() != true) return;

            AddNewUserCommand addNewUserCommand = userProfileDialog.UserProfile;
            Response<User> response = CommandExecutor.Execute(addNewUserCommand);

            if (response.HasErrors)
                UserInteraction.ShowError("New user cannot be added.", response);
            else
            {
                _mainWindowViewModel.GetAllUsersCommand.Execute(true);
                _mainWindowViewModel.SetSelectedUser();
            }
        }
Ejemplo n.º 2
0
        public void Execute(object parameter)
        {
            var userProfileDialog = new UserProfileDialog
               {
                   Title = "Edit Profile",
                   Buttons = new Button[] { } //TODO-VKY: This will be removed when NuGet fix "ModernDialog ShowDialog always return false".
               };

            if (_mainWindowViewModel.SelectedUser != null)
            {
                userProfileDialog.UserProfile.FirstName = _mainWindowViewModel.SelectedUser.FirstName;
                userProfileDialog.UserProfile.LastName = _mainWindowViewModel.SelectedUser.LastName;
                userProfileDialog.UserProfile.Email = _mainWindowViewModel.SelectedUser.Email;
                userProfileDialog.Title = "Edit Profile" + "-" + _mainWindowViewModel.SelectedUser.FirstName;
            }

            // userProfileDialog.Buttons = new Button[] { userProfileDialog.OkButton, userProfileDialog.CancelButton };

            if (userProfileDialog.ShowDialog() != true) return;

            AddNewUserCommand addNewUserCommand = userProfileDialog.UserProfile;
            Response<User> response = CommandExecutor.Execute(addNewUserCommand);

            if (response.HasErrors)
                UserInteraction.ShowError("New user cannot be added.", response);
            else
            {
                var cache = ObjectFactory.Container.GetInstance<IQueryResultCache<GetUsersQuery, User[]>>();
                cache.InvalidateCacheFor(query => true); // Just a "test" since we don't have any other real tests :-(
                cache.InvalidatCacheForAllQueries();

                _mainWindowViewModel.GetAllUsersCommand.Execute(true);
                _mainWindowViewModel.SetSelectedUser();
            }
        }
Ejemplo n.º 3
0
        public ActiveLeadDialog(
            UserProfileDialog userProfileDialog,
            FinanceDialog financeDialog,
            VehicleProfileDialog vehicleProfileDialog,
            ValueTradeInDialog valueTradeInDialog,
            SimpleInventoryDialog inventoryDialog,
            ICardFactory <BasicDetails> profileFactory,
            ICardFactory <FinancingDetails> financeFactory,
            ICardFactory <TradeInDetails> tradeinFactory,
            ICardFactory <VehicleProfileDetails> vehicleFactory,
            ADSBotServices botServices)
            : base(nameof(ActiveLeadDialog))
        {
            Services = botServices;

            var rootDialog = new AdaptiveDialog(nameof(AdaptiveDialog))
            {
                Generator = new TemplateEngineLanguageGenerator(),
                Triggers  = new List <OnCondition>()
                {
                    new OnCustomEvent(Constants.Event_Help)
                    {
                        Actions = new List <Dialog>()
                        {
                            new SetProperty()
                            {
                                Property = "conversation.seen_help",
                                Value    = "true"
                            },
                            new ChoiceInput()
                            {
                                Prompt = new ActivityTemplate("I want to provide you with the best service possible! " +
                                                              "Just select one of the easy-click options below, or " +
                                                              "type a request directly into the text box."),
                                AlwaysPrompt = true,
                                Property     = "conversation.interest",
                                Choices      = new ChoiceSet(Constants.HelpOptions.Select(o => new Choice(o)).ToList())
                            },
                            new IfCondition()
                            {
                                Condition = "conversation.interest != null",
                                Actions   = new List <Dialog>()
                                {
                                    new EmitEvent(Constants.Event_Interest)
                                }
                            },
                        }
                    },
                    new OnCustomEvent(Constants.Event_Interest)
                    {
                        Condition = "conversation.interest != null",
                        Actions   = new List <Dialog>()
                        {
                            new IfCondition()
                            {
                                Condition = "user.UserProfile.IsRegistered",
                                Actions   = new List <Dialog>()
                                {
                                    new SwitchCondition()
                                    {
                                        Condition = "conversation.interest",
                                        Cases     = new List <Case>()
                                        {
                                            new Case()
                                            {
                                                Value   = Constants.INTEREST_Financing,
                                                Actions = new List <Dialog>()
                                                {
                                                    new EmitEvent(Constants.Event_Card, "'financing'")
                                                }
                                            },
                                            new Case()
                                            {
                                                Value   = Constants.INTEREST_Identify,
                                                Actions = new List <Dialog>()
                                                {
                                                    new EmitEvent(Constants.Event_Card, "'vehicle'")
                                                }
                                            },
                                            new Case()
                                            {
                                                Value   = Constants.INTEREST_TradeIn,
                                                Actions = new List <Dialog>()
                                                {
                                                    new EmitEvent(Constants.Event_Card, "'tradein'")
                                                }
                                            },
                                            new Case()
                                            {
                                                Value   = Constants.INTEREST_Inventory,
                                                Actions = new List <Dialog>()
                                                {
                                                    new EmitEvent(Constants.Event_Card, "'inventory'")
                                                }
                                            }
                                        }
                                    }
                                },
                                ElseActions = new List <Dialog>()
                                {
                                    new SetProperty()
                                    {
                                        Property = "conversation.residual_interest",
                                        Value    = "conversation.interest"
                                    },
                                    new DeleteProperty()
                                    {
                                        Property = "conversation.interest"
                                    },
                                    new EmitEvent(Constants.Event_Card, "'profile'")
                                }
                            },
                            //Delete the property so we don't loop forever
                            new DeleteProperty()
                            {
                                Property = "conversation.interest"
                            }
                        }
                    },
                    new OnCustomEvent(Constants.Event_Cancel)
                    {
                        Actions = new List <Dialog>()
                        {
                            //  when the user cancels we need to check where they were so that we can transition smoothly.
                            //  what if they weren't in a dialog? What if they've typed 'cancel' twice in a row?
                            new EmitEvent(Constants.Event_Help, bubble: true),
                            new CancelAllDialogs(),
                        }
                    },
                    new OnCustomEvent(Constants.Event_Card)
                    {
                        Actions = new List <Dialog>()
                        {
                            new SetProperty()
                            {
                                Property = "conversation.busy",
                                Value    = "true"
                            },
                            new SwitchCondition()
                            {
                                Condition = "toLower(turn.dialogEvent.value)",
                                Cases     = new List <Case>()
                                {
                                    //Just copied from below as a quick fix, ideally this would all be in the financing dialog itself.
                                    new Case("profile")
                                    {
                                        Actions = new List <Dialog>()
                                        {
                                            new BeginDialog(userProfileDialog.Id)
                                        }
                                    },
                                    new Case("financing")
                                    {
                                        Actions = new List <Dialog>()
                                        {
                                            new BeginDialog(financeDialog.Id)
                                        }
                                    },
                                    new Case("vehicle")
                                    {
                                        Actions = new List <Dialog>()
                                        {
                                            new BeginDialog(vehicleProfileDialog.Id)
                                        }
                                    },
                                    new Case("tradein")
                                    {
                                        Actions = new List <Dialog>()
                                        {
                                            new BeginDialog(valueTradeInDialog.Id)
                                        }
                                    },
                                    new Case("inventory")
                                    {
                                        Actions = new List <Dialog>()
                                        {
                                            new BeginDialog(inventoryDialog.Id)
                                        }
                                    },
                                },
                                Default = new List <Dialog>()
                                {
                                    new SendActivity("I'm sorry, I can't handle that request yet. :("),
                                    new EmitEvent(Constants.Event_Help, bubble: true)
                                }
                            },
                            new SetProperty()
                            {
                                Property = "conversation.busy",
                                Value    = "false"
                            },
                            new IfCondition()
                            {
                                Condition = "conversation.residual_interest != null",
                                Actions   = new List <Dialog>()
                                {
                                    new SetProperty()
                                    {
                                        Property = "conversation.interest",
                                        Value    = "conversation.residual_interest"
                                    },
                                    new DeleteProperty()
                                    {
                                        Property = "conversation.residual_interest"
                                    },
                                    new EmitEvent(Constants.Event_Interest)
                                },
                                ElseActions = new List <Dialog>()
                                {
                                    new DeleteProperty()
                                    {
                                        Property = "conversation.interest"
                                    },
                                    new EmitEvent(Constants.Event_Help)
                                }
                            },
                        }
                    },

                    new OnBeginDialog()
                    {
                        Actions = new List <Dialog>()
                        {
#if DEBUG
                            new TraceActivity()
                            {
                                Name = "OnBeginDialog"
                            },
#endif
                            new CodeAction(async(context, _) => {
                                await Services.SetUserProfileAsync(await Services.GetUserProfileAsync(context.Context), context);
                                return(new DialogTurnResult(DialogTurnStatus.Complete));
                            }),
                            new EmitEvent(Constants.Event_Help),
                        }
                    },
                    new OnMessageActivity()
                    {
                        Actions = new List <Dialog>()
                        {
#if DEBUG
                            new TraceActivity("OnMessageActivity")
                            {
                                Name = "OnMessageActivity"
                            },
#endif
                            new CodeAction(async(context, _) => {
                                await Services.SetUserProfileAsync(await Services.GetUserProfileAsync(context.Context), context);
                                return(new DialogTurnResult(DialogTurnStatus.Complete));
                            }),
                            new CodeAction(PrimaryHandler)
                        }
                    }
                }
            };

            CardFactories.Add(profileFactory);
            CardFactories.Add(financeFactory);
            CardFactories.Add(tradeinFactory);
            CardFactories.Add(vehicleFactory);

            AddDialog(rootDialog);

            AddDialog(userProfileDialog);
            AddDialog(financeDialog);
            AddDialog(vehicleProfileDialog);
            AddDialog(valueTradeInDialog);
            AddDialog(inventoryDialog);
        }