private void CreateExerciseLogEntry(FitnessTrackerPlus.Web.Data.Exercise exercise) { ExerciseLogEntry entry = new ExerciseLogEntry(); // Setup new exercise log entry with selected date, exercise and current user entry.exercise_id = exercise.id; entry.entry_date = Globals.SelectedDate; entry.user_id = Globals.CurrentUser.id; context.ExerciseLogEntries.Add(entry); context.SubmitChanges((ChangesSubmitted) => { if (!ChangesSubmitted.HasError) { if (exercise.ExerciseType.type_name == "Cardio") { CardioData.Load(); } else if (exercise.ExerciseType.type_name == "Weight Training") { WeightTrainingData.Load(); } else { ActivityData.Load(); } } }, null); }
private void DeleteSelected_Click(object sender, RoutedEventArgs e) { List <ExerciseLogEntry> entries = new List <ExerciseLogEntry>(); // First check the cardio grid, then weight training and activities foreach (ExerciseLogEntry entry in context.ExerciseLogEntries) { CheckBox selectItem = null; if (entry.Exercise.ExerciseType.type_name == "Cardio") { CardioLogGrid.SelectedItem = entry; selectItem = CardioLogGrid.Columns[CardioLogGrid.Columns.Count - 1].GetCellContent(CardioLogGrid.SelectedItem) as CheckBox; } else if (entry.Exercise.ExerciseType.type_name == "Weight Training") { WeightTrainingLogGrid.SelectedItem = entry; selectItem = WeightTrainingLogGrid.Columns[WeightTrainingLogGrid.Columns.Count - 1].GetCellContent(WeightTrainingLogGrid.SelectedItem) as CheckBox; } else { ActivityLogGrid.SelectedItem = entry; selectItem = ActivityLogGrid.Columns[ActivityLogGrid.Columns.Count - 1].GetCellContent(ActivityLogGrid.SelectedItem) as CheckBox; } if (selectItem != null) { if (selectItem.IsChecked == true) { entries.Add(entry); } } } foreach (ExerciseLogEntry entry in entries) { context.ExerciseLogEntries.Remove(entry); } context.SubmitChanges((EntriesRemoved) => { ProgressBar.Visibility = Visibility.Collapsed; CardioData.Load(); WeightTrainingData.Load(); ActivityData.Load(); }, null); }