private void OkToDeleteCustomerMessageSink(Boolean okToDeleteCustomer)
 {
     if (okToDeleteCustomer)
     {
         try
         {
             if (DataAccess.DataService.DeleteCustomer(CurrentCustomer.CustomerId.DataValue))
             {
                 //now we need to tell SearchCustomersViewModel to refresh its list of
                 //customers as we deleted the customer that was selected
                 CurrentCustomer = null;
                 matchedCustomersCollectionView.MoveCurrentToPosition(-1);
                 DoSearchCommand.Execute(null);
                 messageBoxService.ShowInformation("Sucessfully deleted the Customer");
             }
             else
             {
                 messageBoxService.ShowError("There was a problem deleting the Customer");
             }
         }
         catch
         {
             messageBoxService.ShowError("There was a problem deleting the Customer");
         }
     }
     else
     {
         messageBoxService.ShowError("Can't delete Customer as it is currently being edited");
     }
 }
Exemple #2
0
        internal void OnSearchHistorySelected(SearchHistory item)
        {
            SearchText.Value     = item.Keyword;
            SelectedTarget.Value = TargetListItems.Single(x => x == item.Target);

            DoSearchCommand.Execute();
        }
Exemple #3
0
 public SearchPopupViewModel(Workspace workspace, Options options, MouseHandler mouseHandler, DoSearchCommand searchCommand) : base(workspace, options, mouseHandler)
 {
     _searchCommand     = searchCommand;
     TitleVisible       = true;
     Title              = "Search";
     HideInputAtStartup = false;
     SetHeaderIconByKey("appbar_magnify");
 }
        public SearchPageViewModel(
            Models.NiconicoSession niconicoSession,
            SearchProvider searchProvider,
            Services.PageManager pageManager
            )
            : base(pageManager)
        {
            NiconicoSession = niconicoSession;
            SearchProvider = searchProvider;

            HashSet<string> HistoryKeyword = new HashSet<string>();
            foreach (var item in Database.SearchHistoryDb.GetAll().OrderByDescending(x => x.LastUpdated))
            {
                if (HistoryKeyword.Contains(item.Keyword))
                {
                    continue;
                }

                SearchHistoryItems.Add(new SearchHistoryListItem(item, this));
                HistoryKeyword.Add(item.Keyword);
            }

            SearchText = new ReactiveProperty<string>(_LastKeyword)
                .AddTo(_CompositeDisposable);

            TargetListItems = new List<SearchTarget>()
            {
                SearchTarget.Keyword,
                SearchTarget.Tag,
                SearchTarget.Niconama,
                SearchTarget.Mylist,
                SearchTarget.Community,
            };

            SelectedTarget = new ReactiveProperty<SearchTarget>(_LastSelectedTarget)
                .AddTo(_CompositeDisposable);

            SearchOptionVM = new ReactiveProperty<SearchOptionViewModelBase>();
            SearchOptionVMDict = new Dictionary<SearchTarget, SearchOptionViewModelBase>();

            SelectedTarget.Subscribe(x =>
            {
                RaiseSearchTargetFlags();

                var keyword = SearchOptionVM.Value?.Keyword ?? "";
                SearchOptionViewModelBase searchOptionVM = null;
                if (SearchOptionVMDict.ContainsKey(x))
                {
                    searchOptionVM = SearchOptionVMDict[x];
                }
                else
                {
                    searchOptionVM = SearchOptioniViewModelHelper.CreateFromTarget(x);
                    SearchOptionVMDict.Add(x, searchOptionVM);
                }

                searchOptionVM.Keyword = keyword;

                SearchOptionVM.Value = searchOptionVM;

            });



            DoSearchCommand =
                SearchText.Select(x => !String.IsNullOrEmpty(x))
                .ToReactiveCommand()
                .AddTo(_CompositeDisposable);

            SearchText.Subscribe(x =>
            {
                Debug.WriteLine($"検索:{x}");
            });


            DoSearchCommand.CanExecuteChangedAsObservable()
                .Subscribe(x =>
                {
                    Debug.WriteLine(DoSearchCommand.CanExecute());
                });
            DoSearchCommand.Subscribe(_ =>
            {
                if (SearchText.Value.Length == 0) { return; }

                // Note: Keywordの管理はSearchPage側で行うべき?
                SearchOptionVM.Value.Keyword = SearchText.Value;

                var searchOption = SearchOptionVM.Value.MakePayload();

                // 検索結果を表示
                PageManager.Search(searchOption);

                var searched = Database.SearchHistoryDb.Searched(SearchText.Value, SelectedTarget.Value);

                var oldSearchHistory = SearchHistoryItems.FirstOrDefault(x => x.Keyword == SearchText.Value);
                if (oldSearchHistory != null)
                {
                    SearchHistoryItems.Remove(oldSearchHistory);
                }
                SearchHistoryItems.Insert(0, new SearchHistoryListItem(searched, this));

            })
            .AddTo(_CompositeDisposable);
        }
Exemple #5
0
        public override async Task OnNavigatedToAsync(INavigationParameters parameters)
        {
            IsNavigationFailed.Value     = false;
            NavigationFailedReason.Value = null;

            try
            {
                string keyword = null;
                if (parameters.TryGetValue("keyword", out keyword))
                {
                    keyword = Uri.UnescapeDataString(keyword);
                }


                SearchTarget target = SearchTarget.Keyword;
                if (parameters.TryGetValue("service", out string modeString))
                {
                    Enum.TryParse <SearchTarget>(modeString, out target);
                }
                else if (parameters.TryGetValue("service", out target))
                {
                }

                var pageName = target switch
                {
                    SearchTarget.Keyword => nameof(SearchResultKeywordPage),
                    SearchTarget.Tag => nameof(SearchResultTagPage),
                    SearchTarget.Niconama => nameof(SearchResultLivePage),
                    _ => null
                };

                if (pageName != null && keyword != null)
                {
                    var result = await NavigationService.NavigateAsync(pageName, ("keyword", keyword));

                    if (!result.IsSuccess)
                    {
                        throw result.Exception;
                    }
                }

                SearchText.Value     = keyword;
                SelectedTarget.Value = target;

                _LastSelectedTarget = target;
                _LastKeyword        = keyword;

                DoSearchCommand.Throttle(TimeSpan.FromMilliseconds(50), _scheduler).Subscribe(_ =>
                {
                    //await Task.Delay(50);

                    if (SearchText.Value?.Length == 0)
                    {
                        return;
                    }

                    if (_LastSelectedTarget == SelectedTarget.Value && _LastKeyword == SearchText.Value)
                    {
                        return;
                    }

                    // 検索結果を表示
                    PageManager.Search(SelectedTarget.Value, SearchText.Value);

                    var searched = _searchHistoryRepository.Searched(SearchText.Value, SelectedTarget.Value);

                    var oldSearchHistory = SearchHistoryItems.FirstOrDefault(x => x.Keyword == SearchText.Value);
                    if (oldSearchHistory != null)
                    {
                        SearchHistoryItems.Remove(oldSearchHistory);
                    }
                    SearchHistoryItems.Insert(0, new SearchHistoryListItemViewModel(searched, this));
                })
                .AddTo(_navigationDisposables);
            }
            catch (Exception e)
            {
                IsNavigationFailed.Value = true;
#if DEBUG
                NavigationFailedReason.Value = e.Message;
#endif
                Debug.WriteLine(e.ToString());
            }

            await base.OnNavigatedToAsync(parameters);
        }
Exemple #6
0
        public SearchPageViewModel(HohoemaApp hohoemaApp, PageManager pageManager, Views.Service.MylistRegistrationDialogService mylistDialogService)
            : base(hohoemaApp, pageManager)
        {
            _MylistDialogService = mylistDialogService;

            SearchText = new ReactiveProperty <string>("")
                         .AddTo(_CompositeDisposable);

            TargetListItems = new List <SearchTarget>()
            {
                SearchTarget.Keyword,
                SearchTarget.Tag,
                SearchTarget.Mylist,
                SearchTarget.Community,
                SearchTarget.Niconama,
            };

            SelectedTarget = new ReactiveProperty <SearchTarget>(TargetListItems[0])
                             .AddTo(_CompositeDisposable);

            SearchOptionVM     = new ReactiveProperty <SearchOptionViewModelBase>();
            SearchOptionVMDict = new Dictionary <SearchTarget, SearchOptionViewModelBase>();

            SelectedTarget.Subscribe(x =>
            {
                RaiseSearchTargetFlags();

                var keyword = SearchOptionVM.Value?.Keyword ?? "";
                SearchOptionViewModelBase searchOptionVM = null;
                if (SearchOptionVMDict.ContainsKey(x))
                {
                    searchOptionVM = SearchOptionVMDict[x];
                }
                else
                {
                    searchOptionVM = SearchOptioniViewModelHelper.CreateFromTarget(x);
                    SearchOptionVMDict.Add(x, searchOptionVM);
                }

                searchOptionVM.Keyword = keyword;

                SearchOptionVM.Value = searchOptionVM;
            });



            DoSearchCommand =
                SearchText.Select(x => !String.IsNullOrEmpty(x))
                .ToReactiveCommand()
                .AddTo(_CompositeDisposable);

            SearchText.Subscribe(x =>
            {
                Debug.WriteLine($"検索:{x}");
            });


            DoSearchCommand.CanExecuteChangedAsObservable()
            .Subscribe(x =>
            {
                Debug.WriteLine(DoSearchCommand.CanExecute());
            });
            DoSearchCommand.Subscribe(_ =>
            {
                if (SearchText.Value.Length == 0)
                {
                    return;
                }

                // Note: Keywordの管理はSearchPage側で行うべき?
                SearchOptionVM.Value.Keyword = SearchText.Value;

                var searchOption = SearchOptionVM.Value.MakePayload();

                // 検索結果を表示
                PageManager.Search(searchOption);
            })
            .AddTo(_CompositeDisposable);
        }