/// <summary> /// Creates a new task /// </summary> /// <param name="text">The text of this task</param> /// <param name="size">The size complexity of this task</param> /// <param name="value">The business value of this task</param> /// <param name="owner">The user who owns this task</param> /// <param name="type">The type of this task</param> /// <param name="state">The state of this task</param> /// <returns>True if creating the task succeeds, false otherwise</returns> public bool CreateTask(string text, int size, int value, UserView owner, TaskType type, TaskState state, Nullable<DateTime> completionDate) { if (!_isLoggedIn || CurrStory == null) { throw new InvalidOperationException("User must be logged in"); } else if (owner == null && state != TaskState.Unassigned) // Giving an unassigned task any state but unassigned is not allowed { throw new InvalidOperationException("A task without an owner must be marked Unassigned"); } else if (!EnumValues.businessValue.Contains(value) || !EnumValues.sizeComplexity.Contains(size)) { throw new ArgumentOutOfRangeException("Invalid complexity value"); } else if ((state == TaskState.Completed && !completionDate.HasValue) || (state != TaskState.Completed && completionDate.HasValue)) { throw new InvalidOperationException("A task has a completion date iff it is completed"); } else if (text == null) { throw new ArgumentNullException("Arguments to AddTask must not be null"); } bool result = _dataModel.CreateTask(text, size, value, owner == null ? null : new int?(owner.UserID), type.ConvertToBinary(), state.ConvertToBinary(), CurrStory.StoryID, completionDate); updateTasksForStory(); updateTasksForUser(); return result; }
/// <summary> /// Updates the current task /// </summary> /// <param name="text">The text of this task</param> /// <param name="size">The size complexity of this task</param> /// <param name="value">The business value of this task</param> /// <param name="owner">The user who owns this task</param> /// <param name="type">The type of this task</param> /// <param name="state">The state of this task</param> /// <param name="completion">The date this task was completed</param> /// <returns>True if the changes succeed, false otherwise</returns> public bool ChangeCurrTask(string text, int size, int value, UserView owner, TaskType type, TaskState state, Nullable<DateTime> completion) { if (!_isLoggedIn || CurrTask == null) { throw new InvalidOperationException("User must be logged in"); } else if (owner == null && state != TaskState.Unassigned) // Giving an unassigned task any state but unassigned is not allowed { throw new InvalidOperationException("A task without an owner must be marked Unassigned"); } else if (!EnumValues.businessValue.Contains(value) || !EnumValues.sizeComplexity.Contains(size)) { throw new ArgumentOutOfRangeException("Invalid complexity value"); } else if (text == null) { throw new ArgumentNullException("Arguments to AddTask must not be null"); } bool result = _dataModel.ChangeTask(CurrTask.TaskID, text, size, value, owner == null ? null : new int?(owner.UserID), type.ConvertToBinary(), state.ConvertToBinary(), completion); if (result) { updateTasksForStory(); updateTasksForUser(); CurrTask = new TaskView(_dataModel.GetTaskByID(CurrTask.TaskID)); } return result; }