private void ShowEditRosterDialog() { var dialogViewModel = new EditRosterViewModel(AllExerciseItems); List <ExerciseItem> temp = AllExerciseItems.ToList(); bool?success = dialogService.ShowDialog <EditRosterView>(this, dialogViewModel); if (success == true) { ExerciseItemsToDo.Clear(); foreach (var rosterItem in dialogViewModel.RosterItems) { ExerciseItem exerciseItem = temp.FirstOrDefault(x => x.GUIDID == rosterItem.GUIDID); exerciseItem.IsUsedInRoster = rosterItem.IsUsedInRoster; dataStore.UpdateIsUsedInRoster(exerciseItem); RaisePropertyChangedEvent("IsUsedInRoster"); if (!temp.Contains(exerciseItem)) { exerciseItem.DueTime = DateTime.Now; } if (exerciseItem.IsUsedInRoster) { ExerciseItemsToDo.Add(exerciseItem); } } RebuildList(); } else //revert it to the way it was { } }
private void LoadExerciseList() { try { //Need to fix the data store to cope when there are new columns added to existing db AllExerciseItems = dataStore.LoadAllExerciseItems(); foreach (ExerciseItem item in AllExerciseItems) { item.MarkExerciseCompletedChanged += OnMarkExerciseCompletedChanged; //attach all the handlers regardless. it should make things a bit easier later on item.DeleteExercise += OnDeleteExercise; item.EditExericse += OnEditExercise; if (item.IsUsedInRoster) { ExerciseItemsToDo.Add(item); } } RebuildList(); OnUpdateTimerTick(null, null); //first time fire to update everything on load } catch (Exception ex) { if (ex is System.IO.DirectoryNotFoundException || ex is System.IO.FileNotFoundException) { Debug.WriteLine("No Exercise Item List found in: " + rootProgramDirectory); } else { throw; } } }
private void RebuildList() { List <ExerciseItem> temp = ExerciseItemsToDo.OrderBy(x => x.DueTime).ToList(); ExerciseItemsToDo.Clear(); foreach (var item in temp) { ExerciseItemsToDo.Add(item); } }
private void ShowCreateExerciseDialog() { var dialogViewModel = new CreateExerciseViewModel(); bool?success = dialogService.ShowDialog <CreateExerciseView>(this, dialogViewModel); DateTime today = DateTime.Today; if (success == true) { if (dialogViewModel.ItemToAdd.IsDailyRecurrence) { dialogViewModel.ItemToAdd.DueTime = today; } else if (dialogViewModel.ItemToAdd.IsWeeklyRecurrence) { // The (... + 7) % 7 ensures we end up with a value in the range [0, 6] int requiredDueDay = ((int)dialogViewModel.ItemToAdd.WeeklyRecurrenceDay - (int)today.DayOfWeek + 7) % 7; dialogViewModel.ItemToAdd.DueTime = today.AddDays(requiredDueDay); } else if (dialogViewModel.ItemToAdd.IsMonthlyRecurrence) { int requiredDueMonth = ((int)dialogViewModel.ItemToAdd.MonthlyRecurrenceDay - (int)today.Month + DateTime.DaysInMonth(today.Year, today.Month)) % DateTime.DaysInMonth(today.Year, today.Month); dialogViewModel.ItemToAdd.DueTime = today.AddDays(requiredDueMonth + 1); //dont ask me why i need a plus 1. I dont know } AllExerciseItems.Add(dialogViewModel.ItemToAdd); dataStore.AddExercise(dialogViewModel.ItemToAdd); SaveExerciseList(); if (dialogViewModel.ItemToAdd.IsUsedInRoster) { dialogViewModel.ItemToAdd.MarkExerciseCompletedChanged += OnMarkExerciseCompletedChanged; //check that you dont need to explicitly unsub when this item is removed dialogViewModel.ItemToAdd.EditExericse += OnEditExercise; dialogViewModel.ItemToAdd.DeleteExercise += OnDeleteExercise; ExerciseItemsToDo.Add(dialogViewModel.ItemToAdd); OnUpdateTimerTick(null, null); } } RebuildList(); }