예제 #1
0
        async Task LoadData()
        {
            Characters = new ObservableCollection <CharacterViewModel>();
            List <HPCharacter> hpCharacters = new List <HPCharacter>();

            if (UseLocalStorage)
            {
                hpCharacters = string.IsNullOrWhiteSpace(SearchText)
                    ? await App.Context.GetItemsAsync <HPCharacter>()
                    : await App.Context.FilterItemsAsync <HPCharacter>("HPCharacter", $"name LIKE '%{SearchText}%'");
            }
            else
            {
                var service = new RESTService();
                var result  = await service.GetCharacters();

                hpCharacters = result;
            }

            Device.BeginInvokeOnMainThread(() =>
            {
                foreach (var item in hpCharacters)
                {
                    Characters.Add(new CharacterViewModel(item));
                }
            });
        }