public override void GetPagedTasks(int pageNumber)
        {
            for (int i = (AllGoals.Count - 1); i >= 0; i--)
            {
                GoalViewModel goalVm = AllGoals[i];
                this.AllGoals.Remove(goalVm);
                goalVm.Dispose();
            }

            List <GoalViewModel> all =
                (from goal in _goalData.GetGoals(FilterTerm, SelectedSortColumn, pageNumber)
                 select new GoalViewModel(goal, _goalData, _projectData, _taskData)).ToList();

            foreach (GoalViewModel gvm in all)
            {
                gvm.PropertyChanged += this.OnGoalViewModelPropertyChanged;
            }

            for (int i = 0; i < all.Count; i++)
            {
                this.AllGoals.Add(all[i]);
            }

            FirstRecordNumber = AllGoals.Count > 0 ? (Constants.RecordsPerPage * (pageNumber - 1)) + 1 : 0;
            LastRecordNumber  = AllGoals.Count > 0 ? FirstRecordNumber + AllGoals.Count - 1 : 0;
            TotalRecordCount  = _goalData.GetGoalsCount(FilterTerm);
        }
        void RefreshGoalsAfterModification()
        {
            bool goalSelected = false;

            GoalViewModel origSelectedGoal = AllGoals.Where(t => t.IsSelected == true).FirstOrDefault();

            RefreshPage();
            if (origSelectedGoal != null)
            {
                GoalViewModel newSelectedGoal = AllGoals.Where(t => t.GoalId == origSelectedGoal.GoalId).FirstOrDefault();
                if (newSelectedGoal != null)
                {
                    newSelectedGoal.IsSelected = true;
                    goalSelected = true;
                }
            }

            if (!goalSelected)
            {
                GoalViewModel firstGoal = AllGoals.FirstOrDefault();
                if (firstGoal != null)
                {
                    firstGoal.IsSelected = true;
                }
            }
        }
        /// <summary>
        /// Launches the new goal window.
        /// </summary>
        public void CreateGoal()
        {
            GoalView window = new GoalView();

            using (var viewModel = new GoalViewModel(Goal.CreateNewGoal(), _goalData, _projectData, _taskData))
            {
                this.ShowWorkspaceAsDialog(window, viewModel);
            }
        }
        /// <summary>
        /// Deletes the selected goal.
        /// </summary>
        public void DeleteGoal()
        {
            GoalViewModel selectedGoalVM = AllGoals.FirstOrDefault(g => g.IsSelected == true);

            if (selectedGoalVM != null && WPFMessageBox.Show(Properties.Resources.Delete_Confirm, Properties.Resources.Goals_Delete_Confirm, WPFMessageBoxButtons.YesNo, WPFMessageBoxImage.Question) == WPFMessageBoxResult.Yes)
            {
                _goalData.DeleteGoal(_goalData.GetGoalByGoalId(selectedGoalVM.GoalId), _projectData, _taskData);
                selectedGoalVM.Dispose();
            }
        }
        /// <summary>
        /// Launches the edit goal window.
        /// </summary>
        public void EditGoal()
        {
            GoalView window = new GoalView();

            GoalViewModel selectedGoalVM = AllGoals.FirstOrDefault(g => g.IsSelected == true);

            using (var viewModel = new GoalViewModel(_goalData.GetGoalByGoalId(selectedGoalVM.GoalId), _goalData, _projectData, _taskData))
            {
                this.ShowWorkspaceAsDialog(window, viewModel);
            }
        }
        public AllGoalsViewModel(GoalData goalData, ProjectData projectData, TaskData taskData)
        {
            if (goalData == null)
            {
                throw new ArgumentNullException("goalData");
            }

            if (projectData == null)
            {
                throw new ArgumentNullException("projectData");
            }

            if (taskData == null)
            {
                throw new ArgumentNullException("taskData");
            }

            base.DisplayName  = Properties.Resources.Goals_DisplayName;
            base.DisplayImage = "pack://application:,,,/TaskConqueror;Component/Assets/Images/goal.png";

            _goalData    = goalData;
            _projectData = projectData;
            _taskData    = taskData;

            // Subscribe for notifications of when a new goal is saved.
            _goalData.GoalAdded   += this.OnGoalAdded;
            _goalData.GoalUpdated += this.OnGoalUpdated;
            _goalData.GoalDeleted += this.OnGoalDeleted;

            // Populate the AllGoals collection with GoalViewModels.
            this.AllGoals = new ObservableCollection <GoalViewModel>();
            this.AllGoals.CollectionChanged += this.OnCollectionChanged;

            this.PageFirst();

            SortColumns.Add(new SortableProperty()
            {
                Description = "Title", Name = "Title"
            });
            SortColumns.Add(new SortableProperty()
            {
                Description = "Status", Name = "StatusId"
            });
            SortColumns.Add(new SortableProperty()
            {
                Description = "Category", Name = "CategoryId"
            });
            SortColumns.Add(new SortableProperty()
            {
                Description = "Date Created", Name = "CreatedDate"
            });
            SortColumns.Add(new SortableProperty()
            {
                Description = "Date Completed", Name = "CompletedDate"
            });

            SelectedSortColumn = SortColumns.FirstOrDefault();

            // select the first goal
            GoalViewModel firstGoal = AllGoals.FirstOrDefault();

            if (firstGoal != null)
            {
                firstGoal.IsSelected = true;
            }
        }