Beispiel #1
0
        private void InitializeItemsViewModel()
        {
            Title              = "Your Locations List";
            LocationInfos      = new ObservableCollection <LocationInfo>();
            LoadItemsCommand   = new Command(async() => await ExecuteLoadItemsCommand());
            DeleteItemsCommand = new Command(async location => await ExecuteDeleteLocationCommand(location));

            MessagingCenter.Subscribe <SearchPage, LocationInfo>(this, "AddItem", async(obj, item) =>
            {
                if (LocationInfos.Any(element => element.Key.Equals(item.Key)))
                {
                    return;
                }
                var weather      = await WeatherApiClient.GetCurrentWeather(item.Key);
                item.WeatherInfo = weather;
                LocationInfos.Add(item);
                await LocationService.AddItemAsync(item);
            });
        }
Beispiel #2
0
 async Task ExecuteLoadItemsCommand()
 {
     await ExecuteCommand(async() =>
     {
         var items = await LocationService.GetItemsAsync();
         foreach (var locationInfo in items)
         {
             var weather = await WeatherApiClient.GetCurrentWeather(locationInfo.Key);
             if (weather != null)
             {
                 locationInfo.WeatherInfo = weather;
             }
         }
         if (items != null)
         {
             LocationInfos.Clear();
             foreach (var item in items)
             {
                 LocationInfos.Add(item);
             }
         }
     }
                          );
 }