From e223d8ee7074ad6b6acadcb98e6a0bebdb86557b Mon Sep 17 00:00:00 2001 From: Eduard Bissell Date: Tue, 21 May 2024 16:27:21 +0100 Subject: [PATCH 1/7] feat: add TodoItem Class --- Todo-Challenge/Todo-Challenge/TodoItem.cs | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Todo-Challenge/Todo-Challenge/TodoItem.cs diff --git a/Todo-Challenge/Todo-Challenge/TodoItem.cs b/Todo-Challenge/Todo-Challenge/TodoItem.cs new file mode 100644 index 0000000..ab6d6de --- /dev/null +++ b/Todo-Challenge/Todo-Challenge/TodoItem.cs @@ -0,0 +1,8 @@ +namespace Todo_Challenge; + +public class TodoItem(int itemId, string itemDescription, bool itemComplete) +{ + public int id = itemId; + public bool complete = itemComplete; + public string description = itemDescription; +} From 0c33b2d643595e8e6f2b56b0beab627070905c03 Mon Sep 17 00:00:00 2001 From: Eduard Bissell Date: Tue, 21 May 2024 16:27:39 +0100 Subject: [PATCH 2/7] feat: add create and view commands --- Todo-Challenge/Todo-Challenge/Program.cs | 64 +++++++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/Todo-Challenge/Todo-Challenge/Program.cs b/Todo-Challenge/Todo-Challenge/Program.cs index 3751555..f2ed1bb 100644 --- a/Todo-Challenge/Todo-Challenge/Program.cs +++ b/Todo-Challenge/Todo-Challenge/Program.cs @@ -1,2 +1,62 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using Todo_Challenge; + +class Program +{ + static void Main() + { + + int lastId = 1; + List itemList = [new(1, "feed the ducks", false)]; + + while (true) + { + Console.WriteLine("Available commands:\ncreate\nview\nremove {id}\ncomplete {id}\n\n"); + + switch (Console.ReadLine()) + { + case "create": + Console.WriteLine("Enter task description:\n"); + string? descriptionInput = Console.ReadLine(); + + string description; + if (descriptionInput == null) + { + description = ""; + } + else + { + description = descriptionInput; + } + + Console.WriteLine("Set as complete?[y/n]:\n"); + string? completeInput = Console.ReadLine(); + + var complete = completeInput switch + { + "y" => true, + "n" => false, + _ => false, + }; + TodoItem newItem = new(lastId++, description, complete); + + itemList.Add(newItem); + + Console.WriteLine("New item added\n\n"); + + break; + + case "view": + foreach (var item in itemList) + { + Console.WriteLine($"Id: {item.id}, Description: {item.description}, Complete: {item.complete}"); + } + Console.WriteLine("\n\n"); + break; + + default: + Console.WriteLine("Invalid command\n\n"); + break; + } + } + } +} \ No newline at end of file From 521aaecff1237a03c646bfc1955a9885a83ca37e Mon Sep 17 00:00:00 2001 From: Eduard Bissell Date: Tue, 21 May 2024 16:42:57 +0100 Subject: [PATCH 3/7] feat: add remove command --- Todo-Challenge/Todo-Challenge/Program.cs | 26 +++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Todo-Challenge/Todo-Challenge/Program.cs b/Todo-Challenge/Todo-Challenge/Program.cs index f2ed1bb..82cb0d1 100644 --- a/Todo-Challenge/Todo-Challenge/Program.cs +++ b/Todo-Challenge/Todo-Challenge/Program.cs @@ -10,7 +10,7 @@ static void Main() while (true) { - Console.WriteLine("Available commands:\ncreate\nview\nremove {id}\ncomplete {id}\n\n"); + Console.WriteLine("Available commands:\ncreate\nview\nremove\ncomplete {id}\n\n"); switch (Console.ReadLine()) { @@ -53,6 +53,30 @@ static void Main() Console.WriteLine("\n\n"); break; + case "remove": + Console.WriteLine("Enter id to remove"); + string? idInput = Console.ReadLine(); + + if (int.TryParse(idInput, out int id)) + { + TodoItem foundItem = itemList.Find(item => item.id == id); + + if (foundItem != null) + { + itemList.Remove(foundItem); + Console.WriteLine("item removed\n"); + } + else + { + Console.WriteLine($"No item with id: {id} was found.\n"); + } + } + else + { + Console.WriteLine($"Invalid id\n"); + } + break; + default: Console.WriteLine("Invalid command\n\n"); break; From 6814be08ef9ac0295fe0967d6340a056d3cb735e Mon Sep 17 00:00:00 2001 From: Eduard Bissell Date: Tue, 21 May 2024 16:50:33 +0100 Subject: [PATCH 4/7] refactor: rename vars --- Todo-Challenge/Todo-Challenge/Program.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Todo-Challenge/Todo-Challenge/Program.cs b/Todo-Challenge/Todo-Challenge/Program.cs index 82cb0d1..a67acfe 100644 --- a/Todo-Challenge/Todo-Challenge/Program.cs +++ b/Todo-Challenge/Todo-Challenge/Program.cs @@ -1,4 +1,4 @@ -using Todo_Challenge; +using Todo_Challenge; class Program { @@ -10,7 +10,7 @@ static void Main() while (true) { - Console.WriteLine("Available commands:\ncreate\nview\nremove\ncomplete {id}\n\n"); + Console.WriteLine("Available commands:\ncreate\nview\nremove\ncomplete\n\n"); switch (Console.ReadLine()) { @@ -55,11 +55,11 @@ static void Main() case "remove": Console.WriteLine("Enter id to remove"); - string? idInput = Console.ReadLine(); + string? idRemoveInput = Console.ReadLine(); - if (int.TryParse(idInput, out int id)) + if (int.TryParse(idRemoveInput, out int idRemove)) { - TodoItem foundItem = itemList.Find(item => item.id == id); + TodoItem foundItem = itemList.Find(item => item.id == idRemove); if (foundItem != null) { @@ -68,7 +68,7 @@ static void Main() } else { - Console.WriteLine($"No item with id: {id} was found.\n"); + Console.WriteLine($"No item with id: {idRemove} was found.\n"); } } else From 7c134158e63b76acd857461e3b828ce0701ccfe5 Mon Sep 17 00:00:00 2001 From: Eduard Bissell Date: Tue, 21 May 2024 16:51:09 +0100 Subject: [PATCH 5/7] feat: add complete command --- Todo-Challenge/Todo-Challenge/Program.cs | 27 +++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Todo-Challenge/Todo-Challenge/Program.cs b/Todo-Challenge/Todo-Challenge/Program.cs index a67acfe..efd42c3 100644 --- a/Todo-Challenge/Todo-Challenge/Program.cs +++ b/Todo-Challenge/Todo-Challenge/Program.cs @@ -1,4 +1,4 @@ -using Todo_Challenge; +using Todo_Challenge; class Program { @@ -77,6 +77,31 @@ static void Main() } break; + case "complete": + Console.WriteLine("Enter id to complete"); + string? idCompleteInput = Console.ReadLine(); + + if (int.TryParse(idCompleteInput, out int idComplete)) + { + TodoItem foundItem = itemList.Find(item => item.id == idComplete); + + if (foundItem != null) + { + foundItem.complete = true; + Console.WriteLine("item completed\n"); + } + else + { + Console.WriteLine($"No item with id: {idComplete} was found.\n"); + } + } + else + { + Console.WriteLine($"Invalid id\n"); + } + + break; + default: Console.WriteLine("Invalid command\n\n"); break; From b394048807fdd3cc87d7d67418074565dff299d3 Mon Sep 17 00:00:00 2001 From: Eduard Bissell Date: Tue, 21 May 2024 16:57:26 +0100 Subject: [PATCH 6/7] feat: made complete toggle --- Todo-Challenge/Todo-Challenge/Program.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Todo-Challenge/Todo-Challenge/Program.cs b/Todo-Challenge/Todo-Challenge/Program.cs index efd42c3..6a9b4c4 100644 --- a/Todo-Challenge/Todo-Challenge/Program.cs +++ b/Todo-Challenge/Todo-Challenge/Program.cs @@ -87,8 +87,20 @@ static void Main() if (foundItem != null) { - foundItem.complete = true; - Console.WriteLine("item completed\n"); + Console.WriteLine($"Item completeness is set to {foundItem.complete}. Set item to {!foundItem.complete}?[y/n]"); + string? toggleCompleteConfirmation = Console.ReadLine(); + + if (toggleCompleteConfirmation == "y") + { + foundItem.complete = !foundItem.complete; + Console.WriteLine($"item completeness is now {foundItem.complete}\n"); + } + else + { + Console.WriteLine("Command aborted"); + break; + } + } else { From 44718b93bf3c63acfdffddd460c4cd69b33e2a71 Mon Sep 17 00:00:00 2001 From: Eduard Bissell Date: Tue, 21 May 2024 16:58:26 +0100 Subject: [PATCH 7/7] fix: correct id incrementing --- Todo-Challenge/Todo-Challenge/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Todo-Challenge/Todo-Challenge/Program.cs b/Todo-Challenge/Todo-Challenge/Program.cs index 6a9b4c4..64dc24e 100644 --- a/Todo-Challenge/Todo-Challenge/Program.cs +++ b/Todo-Challenge/Todo-Challenge/Program.cs @@ -37,7 +37,7 @@ static void Main() "n" => false, _ => false, }; - TodoItem newItem = new(lastId++, description, complete); + TodoItem newItem = new(++lastId, description, complete); itemList.Add(newItem);