private void loadWeekGoalsToProperties(WeekGoals wg)//loads the WeekGoals- wg to the properties(to the screen) { if (wg != null) { GoalsMonthComponentsListProperty = new ObservableCollection <string>() { wg.GoalCalories.ToString(), wg.GoalFats.ToString(), wg.GoalCarbs.ToString(), wg.GoalProteins.ToString() }; GoalsMonthColumnsProperty = new ObservableCollection <KeyValuePair <string, int> >() { new KeyValuePair <string, int>("Calories", wg.GoalCalories), new KeyValuePair <string, int>("Fats", wg.GoalFats), new KeyValuePair <string, int>("Carbs", wg.GoalCarbs), new KeyValuePair <string, int>("Proteins", wg.GoalCalories) }; } else//clear { GoalsMonthComponentsListProperty = new ObservableCollection <string>() { "0", "0", "0", "0" }; GoalsMonthColumnsProperty = new ObservableCollection <KeyValuePair <string, int> >() { new KeyValuePair <string, int>("Calories", 0), new KeyValuePair <string, int>("Fats", 0), new KeyValuePair <string, int>("Carbs", 0), new KeyValuePair <string, int>("Proteins", 0) }; } }
public void setGoals(WeekGoals weekGoals) { if (bl.getWeekGoals(weekGoals.EmailAddress, weekGoals.SundayDate) != null) { bl.updateWeekGoals(weekGoals); } else { bl.addWeekGoals(weekGoals); } }
private void OnSelectedSundayPropertyChanged(DateTime sunday) { WeekGoals wg = Model.getMonthGoals(EmailAddressProperty, sunday); loadWeekGoalsToProperties(wg);//load week goals of sunday's week of the user if it setted, else it clears the properties with 0 dailyFoodLst = Model.getDailyFoodMonthList(EmailAddressProperty, sunday); IsCheckedAllChartsLinesProperty = false; IsCheckedAllChartsLinesProperty = true; sumTotalComponents(); }
public bool addWeekGoals(WeekGoals weekGoals) { try { using (var db = new FoodContext()) { db.WeekGoals.Add(weekGoals); db.SaveChanges(); } return(true); } catch (Exception e) { return(false); } }
//when the selected week is changed the button will be not enabled if the selected week has already passed, //and if the data base has information about the selected week it will load this to the screen private void OnSelectedSundayPropertyChanged(DateTime sunday) { WeekGoals wg = Model.getWeekGoals(EmailAddressProperty, sunday); loadWeekGoalsToProperties(wg); //load week goals of sunday's week of the user if it setted, else it clears the properties with 0 if ((DateTime.Today.AddDays(0 - (int)DateTime.Today.DayOfWeek)).CompareTo(sunday) > 0) //the selected week has already passed //therefore user can't set the goals { IsEnabledProperty = false; } else//the selected week has not passed yet { IsEnabledProperty = true; } }
private void loadWeekGoalsToProperties(WeekGoals wg)//loads the WeekGoals- wg to the properties(to the screen) { if (wg != null) { this.CaloriesProperty = wg.GoalCalories.ToString(); this.CarbsProperty = wg.GoalCarbs.ToString(); this.FatsProperty = wg.GoalFats.ToString(); this.ProteinsProperty = wg.GoalProteins.ToString(); } else//clear { this.CaloriesProperty = "0"; this.CarbsProperty = "0"; this.FatsProperty = "0"; this.ProteinsProperty = "0"; } }
public WeekGoals getMonthGoals(string emailAddress, DateTime sunday) { WeekGoals result = new WeekGoals() { GoalCalories = 0, GoalCarbs = 0, GoalFats = 0, GoalProteins = 0 }; WeekGoals tmp; for (int i = 0; i < 4; i++) { tmp = myBL.getWeekGoals(emailAddress, sunday.AddDays(7 * i)); if (tmp != null) { result.GoalCalories += tmp.GoalCalories; result.GoalFats += tmp.GoalFats; result.GoalCarbs += tmp.GoalCarbs; result.GoalProteins += tmp.GoalProteins; } } return(result); }
public bool updateWeekGoals(WeekGoals weekGoals) { try { using (var myDb = new FoodContext()) { var weekGoalsTemp = myDb.WeekGoals.SingleOrDefault(d => d.EmailAddress.Equals(weekGoals.EmailAddress) && (d.SundayDate.Day == weekGoals.SundayDate.Day) && (d.SundayDate.Year == weekGoals.SundayDate.Year) && (d.SundayDate.Month == weekGoals.SundayDate.Month)); if (weekGoalsTemp != null) { myDb.Entry(weekGoalsTemp).CurrentValues.SetValues(weekGoals); myDb.SaveChanges(); } } return(true); } catch (Exception e) { return(false); } }
public bool updateWeekGoals(WeekGoals weekGoals) { return(myDal.updateWeekGoals(weekGoals)); }
public bool addWeekGoals(WeekGoals weekGoals) { return(myDal.addWeekGoals(weekGoals)); }