示例#1
0
 private void btn_Update_Click(object sender, RoutedEventArgs e)
 {
     if (tbk_LastUpdate.Text != System.DateTime.Today.ToString("M/dd/yyyy"))
     {
         try
         {
             JHUDataService.UpdateDatabase();
         }
         finally
         {
             dtg_World.ItemsSource = WorldGridsViewModel.GenerateData();
             tbk_LastUpdate.Text   = System.DateTime.Today.ToString("M/dd/yyyy");
         }
     }
     else
     {
         MessageBox.Show("Already Up to date");
     }
 }
示例#2
0
        /*
         * public bool? IsAllItemsSelected
         * {
         *  get
         *  {
         *      var selected = _items.Select(item => item.IsSelected).Distinct().ToList();
         *      return selected.Count == 1 ? selected.Single() : (bool?)null;
         *  }
         *  set
         *  {
         *      if (value.HasValue)
         *      {
         *          SelectAll(value.Value, Items);
         *          OnPropertyChanged();
         *      }
         *  }
         * }
         *
         * private static void SelectAll(bool select, IEnumerable<RegionGridsViewModel> models)
         * {
         *  foreach (var model in models)
         *  {
         *      model.IsSelected = select;
         *  }
         * }
         */



        public static ObservableCollection <RegionGridsViewModel> GenerateData()
        {
            CoronaWatchContext context = new CoronaWatchContext();

            if (context.ReportDBs.Count() == 0)
            {
                JHUDataService.UpdateDatabase();
            }

            List <Region> regions = JHUDataService.FetchDatabase();
            ObservableCollection <RegionGridsViewModel> regionGrids = new ObservableCollection <RegionGridsViewModel>();

            foreach (Region reg in regions)
            {
                RegionGridsViewModel regGrid = new RegionGridsViewModel(reg);
                regionGrids.Add(regGrid);
            }

            _lastUpdate = Convert.ToDateTime(context.ReportDBs.OrderByDescending(r => r.Date).FirstOrDefault().Date);
            return(regionGrids);
        }