Example #1
0
        public void DeleteTask()
        { // TODO: Untestable, rewrite for unit testing.
            var selectedTaskName = ActiveForm.GetCurrentSelectedTaskName();

            if (selectedTaskName == null)
            {
                messageBoxFactory.ShowMessageBox(
                    EMessageBox.Standard,
                    Resources.NoRowSelectedErrorMessage,
                    Settings.Default.AppName,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                return;
            }

            var result = messageBoxFactory.ShowMessageBox(
                EMessageBox.Standard,
                Resources.ConfirmTaskDeleteMessage,
                Settings.Default.AppName,
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                // Remove selected task from display and memory:
                var selectedTask = QueryTask(selectedTaskName);
                ActiveForm.DeleteTaskFromDisplay(selectedTask);
                foreach (var category in Categories)
                {
                    // Look for category of task:
                    if (category.Name == selectedTask.Category)
                    {
                        category.Tasks.Remove(selectedTask);
                        return;
                    }
                }
            }
        }