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
48 changes: 48 additions & 0 deletions domain-model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Calculator Project

# User Stories



-I want to add tasks to my todo list.

-I want to see all the tasks in my todo list.

-I want to change the status of a task between incomplete and complete.

-I want to be able to get only the complete tasks.

-I want to be able to get only the incomplete tasks.

-I want to search for a task and receive a message that says it wasn't found if it doesn't exist.

-I want to remove tasks from my list.

-I want to see all the tasks in my list ordered alphabetically in ascending order.

-I want to see all the tasks in my list ordered alphabetically in descending order.

-I want to be able to get a task by a unique ID.

-I want to update the name of a task by providing its ID and a new name.

-I want to be able to change the status of a task by providing its ID.

-I want to be able to see the date and time that I created each task.



| Classes | Methods/Properties | Scenario | Outputs |
|-----------------|----------------------------------------------------|---------------------------------|------------------
|ToDoList.cs |AddTask(string task) |add task to task list |an extra task in the task list
|ToDoList.cs |ShowList() |shows all tasks in list |presentation of all the tasks in the list
|ToDoList.cs |changeStatus(string task) |change to(complete/incomplete) |
|ToDoList.cs |GetCompletedTasks() |finds complete tasks complete tasks
|ToDoList.cs |GetIncompletedTasks() |finds incomplete tasks |incomplete tasks
|ToDoList.cs |SearchTask(string task) |checks if task exists |message if it does not exist
|ToDoList.cs |RemoveTask(string task) |removes a given task |
|ToDoList.cs |SortAlphabeticalAscendingO() |orders alphabetically(ascending) |tasks in ascending alphabetical order
|ToDoList.cs |SortAlphabeticalDescendingO() |orders alphabetically(descending)|tasks in descending alphabetical order
|ToDoListExtension.cs |GetTaskById(int id) |returns a task by giving an id |
|ToDoListExtension.cs |UpdateName(int id, string name) |changes name of the task with the given id |
|ToDoListExtension.cs |UpdateStatusById(int id) |updates status on the task with the given id|
177 changes: 176 additions & 1 deletion tdd-todo-list.CSharp.Main/Extension.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,187 @@
using System;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;



namespace tdd_todo_list.CSharp.Main
{
public class TodoListExtension
{
List<ToDoTask> todolist = new List<ToDoTask>();
int idcounter = 0;
public string AddTask(string name)
{
ToDoTask task = new ToDoTask();
task.Name = name;
task.Id = idcounter++;
todolist.Add(task);
return todolist.Last().Name;



}

public string ChangeStatus(string name)

{

ToDoTask? task = todolist.Find(x => x.Name == name);
if (task != null)
{
if (task.Status == "incomplete")
{
task.Status = "complete";
return task.Status;

}
else
{
task.Status = "incomplete";
return task.Status;



}
}
return "did not exist in list";


}

public List<ToDoTask> GetCompletedList()
{
List<ToDoTask> completedList = new List<ToDoTask>();

foreach (ToDoTask task in todolist)
{
if (task.Status == "complete")
{
completedList.Add(task);

}
}
return completedList;
}

public List<ToDoTask> GetIncompletedList()
{
List<ToDoTask> incompletedList = new List<ToDoTask>();

foreach (ToDoTask task in todolist)
{
if (task.Status == "incomplete")
{
incompletedList.Add(task);

}
}
return incompletedList;
}


public int ListSize()
{
return todolist.Count;
}

public string RemoveTask(string taskname)
{
ToDoTask? taskToRemove = todolist.Find(task => task.Name == taskname);
if (taskToRemove != null)
{
todolist.Remove(taskToRemove);
return taskToRemove.Name;
}
return "fantes ikke i listen";
}

public string SearchTask(string taskname)
{

ToDoTask? task = todolist.Find(x => x.Name == taskname);
if (task != null)
{
return task.Name;

}
return "this task does not exist";
}

public string ShowList()

{
string allTasks = "";
foreach (ToDoTask task in todolist)
{

allTasks += " " + task.Name + ": " + task.Status + "\n";

}
Console.WriteLine(allTasks);



return allTasks;

}

public List<ToDoTask> SortAlphabetical()

{
List<ToDoTask> sorted = todolist.OrderBy(x => x.Name).ToList();
return sorted;
}

public List<ToDoTask> SortAlphabeticalDescending()
{
List<ToDoTask> sorted = todolist.OrderByDescending(x => x.Name).ToList();
return sorted;
}
public string getTaskById(int id)
{
ToDoTask? task = todolist.Find(x => x.Id == id);
foreach (ToDoTask todo in todolist)
{
Console.WriteLine(todo.Id);
}

if (task != null)
{
return task.Name;
}
return "this id does not exist!";

}

public void UpdateName(int id, string name)
{
ToDoTask? task = todolist.Find(x => x.Id == id);
if (task!= null)
{
task.Name = name;
}


}
public String UpdateStatusById(int id)
{
ToDoTask? task = todolist.Find(x => x.Id == id);
if (task != null)
{
ChangeStatus(task.Name);
return task.Status;
}
return "the id does not exist";

}




}
}
133 changes: 133 additions & 0 deletions tdd-todo-list.CSharp.Main/ToDoList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,143 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace tdd_todo_list.CSharp.Main
{
public class TodoList

{
List<ToDoTask> todolist = new List<ToDoTask>();

public string AddTask(string name)
{
ToDoTask task = new ToDoTask();
task.Name = name;
todolist.Add(task);

return todolist.Last().Name;



}

public string ChangeStatus(string name)

{

ToDoTask? task = todolist.Find(x => x.Name == name);
if (task != null) {
if (task.Status == "incomplete")
{
task.Status = "complete";
return task.Status;

}
else
{
task.Status = "incomplete";
return task.Status;



}
}
return "did not exist in list";


}

public List<ToDoTask> GetCompletedList()
{
List<ToDoTask> completedList = new List<ToDoTask>();

foreach (ToDoTask task in todolist)
{
if (task.Status == "complete")
{
completedList.Add(task);

}
}
return completedList;
}

public List<ToDoTask> GetIncompletedList()
{
List<ToDoTask> incompletedList = new List<ToDoTask>();

foreach (ToDoTask task in todolist)
{
if (task.Status == "incomplete")
{
incompletedList.Add(task);

}
}
return incompletedList;
}



public int ListSize()
{
return todolist.Count;
}

public string RemoveTask(string taskname)
{
ToDoTask? taskToRemove = todolist.Find(task => task.Name == taskname);
if (taskToRemove != null)
{
todolist.Remove(taskToRemove);
return taskToRemove.Name;
}
return "fantes ikke i listen";
}

public string SearchTask(string taskname)
{

ToDoTask? task = todolist.Find(x => x.Name == taskname);
if (task != null)
{
return task.Name;

}
return "this task does not exist";
}

public string ShowList()

{
string allTasks = "";
foreach (ToDoTask task in todolist)
{

allTasks += " " +task.Name +": " + task.Status+ "\n";

}
Console.WriteLine(allTasks);



return allTasks;

}

public List<ToDoTask> SortAlphabetical()

{
List<ToDoTask> sorted = todolist.OrderBy(x => x.Name).ToList();
return sorted;
}

public List<ToDoTask> SortAlphabeticalDescending()
{
List<ToDoTask> sorted = todolist.OrderByDescending(x => x.Name).ToList();
return sorted;
}

}
}
Loading
Loading