Exemplo n.º 1
0
        /// <summary>
        /// Executes the operation and adds it to the operation history.
        /// Modifies the task indicated by the index range to the new
        /// parameters in this operation. If a parameter is left empty or null,
        /// that parameter will remain unchanged in the new task.
        /// </summary>
        /// <param name="taskList">List of task this operation will operate on.</param>
        /// <param name="storageIO">Storage controller that will be used to store neccessary data.</param>
        /// <returns>Response indicating the result of the operation execution.</returns>
        public override Response Execute(List<Task> taskList, Storage storageIO)
        {
            SetMembers(taskList, storageIO);

            Response response = null;

            // No index, do a search instead
            if (!hasIndex && !isAll)
            {
                SetMembers(taskList, storageIO);
                List<Task> searchResults = SearchForTasks(taskName, false, startTime, endTime, searchType);
                response = DisplaySearchResults(searchResults, taskName, startTime, endTime, searchType);
            }
            else
            {
                response = CheckIfIndexesAreValid(startIndex, endIndex);
                if (response != null) return response;

                if (MultipleTasksSelected())
                    return new Response(Result.INVALID_TASK, sortType, this.GetType());

                oldTask = currentListedTasks[startIndex];

                // copy over taskName from indexed task if didn't specify a name
                if (!IsValidString(taskName))
                    taskName = oldTask.TaskName;
                // copy over date/times from indexed task if didn't specify time
                else if (startTime == null && endTime == null)
                    oldTask.CopyDateTimes(ref startTime, ref endTime, ref isSpecific);

                newTask = Task.CreateNewTask(taskName, startTime, endTime, isSpecific);

                response = ModifyTask(oldTask, newTask);
            }

            if (response.IsSuccessful())
            {
                AddToOperationHistory();
            }

            return response;
        }