private void ActionDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (ActionDataGrid.SelectedItem == null)
     {
         selectedAction = null;
         //ProjectFunctions.ToggleFavouriteButton(false);
     }
     else
     {
         selectedAction = ActionDataGrid.SelectedItem as ActionProxy;
         bool notesExist = (selectedAction != null && selectedAction.Notes != null && selectedAction.Notes != "");
         if (editing)
         {
             ShowNotesButtonText.Text = notesExist? "Edit Notes" : "Add Notes";
         }
         else
         {
             ShowNotesButton.IsEnabled = notesExist;
         }
         if (!projectSelected)
         {
             Globals.SelectedProjectProxy = ProjectFunctions.GetProjectProxy(selectedAction.Project.ID);
             ProjectFunctions.ToggleFavouriteButton(true);
         }
     }
     ProjectButton.IsEnabled = (projectSelected || selectedAction != null);
 }
        // ---------------------------------------------------------- //
        // -------------------- Data Management --------------------- //
        // ---------------------------------------------------------- //

        // ------------- Data retrieval ------------- //


        private void refreshActionsGrid()
        {
            try
            {
                if (!pageLoaded)
                {
                    return;
                }
                Globals.LoadingActions = true;
                ActionProxy currentAction = selectedAction ?? null;
                ShowNotesButton.IsEnabled = true;
                NotesBox.Visibility       = Visibility.Hidden;

                int clientID  = Globals.SelectedClientProxy.ID;
                int projectID = projectSelected ? Globals.SelectedProjectProxy.ProjectID : 0;
                projectTeamStaffIDs = projectSelected ? ProjectFunctions.GetInternalTeam(projectID).Select(git => git.StaffID).ToList() : null;
                bool inTeam = (projectSelected && projectTeamStaffIDs.Contains(Globals.MyStaffID));
                bool isOld  = Globals.SelectedProjectProxy.IsOld;
                ProjectFunctions.ActionCounter = 0;
                ProjectCodeColumn.Visibility   = projectSelected ? Visibility.Collapsed : Visibility.Visible;

                ProjectFunctions.SetActionsList(clientID, Globals.SelectedStatusFilter, projectID, fromDate, toDate, Globals.SelectedOwner, completedNumber);

                if (canEdit && projectSelected && !isOld && inTeam)
                {
                    bool setUp = setUpEditing(projectID);
                    if (!setUp)
                    {
                        return;
                    }
                }
                else
                {
                    setUpReadOnly(inTeam, isOld);
                }
                toggleHeaderStyles();

                LoggedByColumn.ItemsSource = ProjectFunctions.LoggedByList;
                StageColumn.ItemsSource    = stageList;
                OwnerColumn.ItemsSource    = ProjectFunctions.OwnerList;

                ActionDataGrid.ItemsSource = ProjectFunctions.ActionList;
                if (currentAction != null && currentAction.ID > 0 && ProjectFunctions.ActionList.Exists(al => al.ID == currentAction.ID))
                {
                    ActionDataGrid.SelectedItem = ProjectFunctions.ActionList.FirstOrDefault(al => al.ID == currentAction.ID);
                    ActionDataGrid.ScrollIntoView(ActionDataGrid.SelectedItem);
                }
                Globals.LoadingActions = firstRefresh = false;
            }
            catch (Exception generalException) { MessageFunctions.Error("Error populating the actions data grid", generalException); }
        }