public async Task ExecuteLoadSeedDataCommand() { if (IsBusy) { return; } _dataClient = DependencyService.Get <IUserFoodDataService>(); _chartDataService = DependencyService.Get <IChartDataService>(); IsBusy = true; Foods = (await _dataClient.GetFoodsAsync()).ToObservableCollection(); CalorieItems = (await _chartDataService.GetWeeklyCaloriesDataPointsAsync(Foods)).ToObservableCollection(); var total = 0.0; int days = 0; foreach (var item in CalorieItems) { if (item.Value > 0) { total += item.Value; days++; } Debug.WriteLine("datecreated {0} Calories {1} Target {2}", item.Name, item.Value, item.Size); } AverageCalories = (total / days); IsBusy = false; IsInitialized = true; }
public DiaryDashboardChartViewModel(INavigation navigation = null) : base(navigation) { _DataClient = DependencyService.Get <IUserFoodDataService>(); _ChartDataService = DependencyService.Get <IChartDataService>(); Foods = new ObservableCollection <FoodItem>(); WeeklyCaloriesChartDataPoints = new ObservableCollection <ChartDataPoint>(); IsInitialized = false; }
public FoodDetailViewModel(INavigation navigation = null, FoodItem food = null) { if (navigation == null) { throw new ArgumentNullException("navigation", "An instance of INavigation must be passed to the FoodDetailViewModel constructor"); } AppNavigation = navigation; if (food == null) { Food = new FoodItem(); this.Title = TextResources.Foods_NewFood; } else { Food = food; this.Title = food.Name.Replace(',', ' ').Substring(0, 20); } _DataClient = DependencyService.Get <IUserFoodDataService>(); }
public DiaryDashboardFoodsViewModel(Command pushTabbedFoodPageCommand, INavigation navigation = null) : base(navigation) { PushTabbedFoodPageCommand = pushTabbedFoodPageCommand; _DataClient = DependencyService.Get <IUserFoodDataService>(); Foods = new ObservableCollection <FoodItem>(); MessagingCenter.Subscribe <FoodItem>(this, MessagingServiceConstants.SAVE_FOOD, (food) => { var index = Foods.IndexOf(food); if (index >= 0) { Foods[index] = food; } else { Foods.Add(food); } Foods = new ObservableCollection <FoodItem>(Foods.OrderBy(n => n.Name)); }); IsInitialized = false; }
public ChartDataService() { _userFoodDatabase = DependencyService.Get <IUserFoodDataService>(); }