Ejemplo n.º 1
0
        private void DayViewModelUpdated(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
        {
            // Keep if any of it's properties update we need to update
            switch (propertyChangedEventArgs.PropertyName)
            {
            case nameof(Calories):
            case nameof(FatTotal):
            case nameof(Cholesterol):
            case nameof(Sodium):
            case nameof(CarbohydrateTotal):
            case nameof(Protein):
                CallUpdate();
                return;

            case "Hour":
            case "Min":
                planViewModel.SavePlan();
                return;
            }
        }
Ejemplo n.º 2
0
        public PlanDayViewModel(string dayName, MainViewModel mainViewModel, PlanViewModel planViewModel)
        {
            this.DayName       = dayName;
            this.mainViewModel = mainViewModel;
            this.planViewModel = planViewModel;

            Meals = new ObservableCollection <PlanMealViewModel>();
            Meals.CollectionChanged += (sender, args) => {
                if (args.OldItems != null)
                {
                    foreach (PlanMealViewModel viewModel in args.OldItems)
                    {
                        viewModel.PropertyChanged -= DayViewModelUpdated;
                    }
                }

                if (args.NewItems != null)
                {
                    foreach (PlanMealViewModel viewModel in args.NewItems)
                    {
                        viewModel.PropertyChanged += DayViewModelUpdated;
                    }
                }

                planViewModel.SavePlan();
            };

            Rules = new ObservableCollection <IRule>();
            Rules.Add(new FatGoalRule(this, mainViewModel.Settings));
            Rules.Add(new ProteinGoalRule(this, mainViewModel.Settings));

            OtherDays = new ObservableCollection <PlanDayViewModel>();
            planViewModel.Days.CollectionChanged += (sender, args) =>
            {
                AddDays();
            };
            AddDays();
        }