Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Core requirements.

| Classes | Methods | Scenario | Output |
|----------|--------------------------------|----------------------------------------------------------|--------|
| ToDoList | Add(string task) | Add task to list | void |
| ToDoList | GetAll | Print all tasks in list | List |
| Task | ChangeStatus(int id) | Changes the status between incomplete and complete | bool |
| ToDoList | GetCompleted | Shows only the completed tasks | List |
| ToDoList | GetIncomplete | Shows only the incomplete tasks | List |
| ToDoList | SearchTask(string task) | Searches for task and gives status on found or not found | bool |
| ToDoList | Remove(string task) | removes task from list | void |
| ToDoList | ShowAlpAscending | see all in alphabetical ascending order | List |
| ToDoList | ShowAlpDecending | see all in alphabetical descending order | List |
| Task | SetPriority(int priority) | sets the priority for the task | bool |
| ToDoList | ShowByPriority | see all sorted by priority, highest to lowest | List |

Extension requirement:

| Classes | Methods | Scenario | Output |
|----------|-------------------------------------|------------------------------------------------------------|-----------|
| ToDoList | GetTaskById(int id) | get task by in number | task |
| Task | SetId(int id) | Set id number for task | bool |
| ToDoList | UpdataName(int id, string newName) | Update task name by id and new name | bool |
| ToDoList | ChangeStatus(int id, string status) | change the status of a task by providing id and new status | bool |
| Task | GetTimeCreated(int id) | get the date and time a task was created | Time/Date |
| Task | GetTimeCompleted(int id) | get the date and time a task war completed | Time/Date |
| ToDoList | LongestTime | show which task took the longest to complete | task |
| ToDoList | ShortestTime | show which task took the shortest to complete | task |
| ToDoList | LongerThanFiveToComplete | show which task took linger than 5 days to complete | task |
| ToDoList | CategoriseTasks(string category) | categorise tasks (study, work, admin) | bool |
| ToDoList | ListByCategory | show all tasks sorted by category | List |
199 changes: 198 additions & 1 deletion tdd-todo-list.CSharp.Main/ToDoList.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,209 @@
using System;
using NUnit.Framework.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace tdd_todo_list.CSharp.Main
{

public enum Priority
{
Low,
Medium,
High
}

public class TaskItem
{

private string _taskName;
//flase = incomplete, true = complete
private bool _status = false;
//set to low as a default
private Priority _priority = Priority.Low;
private string _category;

Check warning on line 28 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

The field 'TaskItem._category' is never used

Check warning on line 28 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

The field 'TaskItem._category' is never used

Check warning on line 28 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

The field 'TaskItem._category' is never used

Check warning on line 28 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

The field 'TaskItem._category' is never used



public TaskItem(string taskName)

Check warning on line 32 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_category' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 32 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_category' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 32 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_category' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 32 in tdd-todo-list.CSharp.Main/ToDoList.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field '_category' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
{
_taskName = taskName;
}




public string TaskName { get { return _taskName; } set { _taskName = value; } }

public bool Status { get { return _status; } set { _status = value; } }

public Priority Priority { get { return _priority; } set { _priority = value; } }



//public Guid Id { get; set; } = Guid.NewGuid();
//public Category Category { get { return _category; } set { _category = value; } }

}






public class TodoList
{
public List<TaskItem> _tasks = new List<TaskItem>();


public void Add(string taskName)
{
TaskItem taskAdd = new TaskItem(taskName);
_tasks.Add(taskAdd);
}


public void RemoveTask(string task)
{
foreach (var item in _tasks)
{
if (item.TaskName == task)
{
_tasks.RemoveAt(_tasks.IndexOf(item));
break;
}
}
}

public List<TaskItem> GetAll()
{
return _tasks;
}

public void ChangeStatus(string task, bool status)
{
foreach (var item in _tasks)
{
if (item.TaskName == task)
{
item.Status = status;
break;
}
}
}

public List<TaskItem> GetCompleted()
{
List<TaskItem> result = new List<TaskItem>();
foreach (var item in _tasks)
{
if (item.Status)
{
result.Add(item);
}
}
return result;
}

public List<TaskItem> GetIncomplete()
{
List<TaskItem> result = new List<TaskItem>();
foreach (var item in _tasks)
{
if (!item.Status)
{
result.Add(item);
}
}
return result;

}


public bool SearchTask(string task)
{
foreach (var item in _tasks)
{
if (item.TaskName == task)
{
return true;

}
else
{
Console.WriteLine($"{task} is not in the list");
return false;
}
}
return false;
}


public TodoList ShowAlpAscending()
{
TodoList result = new TodoList();
List<string> taskNames = new List<string>();

foreach (var item in _tasks)
{
taskNames.Add(item.TaskName);
}

taskNames.Sort();

foreach (var item in taskNames)
{
result.Add(item);
}
return result;
}


public TodoList ShowAlpDecending()
{
TodoList result = new TodoList();
List<string> taskNames = new List<string>();

foreach (var item in _tasks)
{
taskNames.Add(item.TaskName);
}

taskNames.Sort();
taskNames.Reverse();

foreach (var item in taskNames)
{
result.Add(item);
}
return result;
}

public bool SetPriority(string name, Priority priority)
{
foreach (var item in _tasks)
{
if (item.TaskName == name)
{
item.Priority = priority;
return true;
}
}
return false;
}


public List<TaskItem> ShowByPriority()
{
return _tasks.OrderBy(task => task.Priority).ToList();
}




}
}
Loading
Loading