diff --git a/SimplifiedTodo/Crud.cs b/SimplifiedTodo/Crud.cs new file mode 100644 index 00000000..8045de8d --- /dev/null +++ b/SimplifiedTodo/Crud.cs @@ -0,0 +1,271 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; + +namespace SimplifiedTodo +{ + internal class Crud + { + private static ToDoDBContext Context; + + public Crud(ToDoDBContext c) + { + Context = c; + } + + public void Run() + { + while (true) + { + //make a choice and loop while the choice is invalid + Console.Write("c.r.u.d (or e for exit): "); + string request = Console.ReadLine(); + if (request == "e") + { + break; + } + switch (request) + { + case "c": + CreateItem(); + break; + case "r": + ReadItem(); + break; + case "u": + UpdateItem(); + break; + case "d": + DeleteItem(); + break; + + default: + Console.Clear(); + Console.WriteLine("Invalid selection."); + Thread.Sleep(500); + Console.Clear(); + break; + } + } + } + public static void CreateItem() + { + ToDo entry = new ToDo(); + Console.Clear(); + Console.Write("Enter a title"); + entry.Title = Console.ReadLine(); + Console.Write("Enter Reminder"); + entry.Content = Console.ReadLine(); + entry.CreateDate = DateTime.Now; + Context.ToDos.Add(entry); + Context.SaveChanges(); + } + public static void ReadItem() + { + string input = ""; + while (input == "") + { + Console.Clear(); + Console.WriteLine("Enter an id or a range of id's seperated by a \"-\" (example \"1-7\") or a for all"); + Console.Write(": "); + input = Console.ReadLine(); + + if (input == "") + { + Console.Clear(); + Console.WriteLine("Invalid Entry"); + Thread.Sleep(500); + } + + if (input.Contains("-") || int.TryParse(input, out int num) || input == "a") + { + + } + else + { + input = ""; + Console.Clear(); + Console.WriteLine("Invalid Entry"); + Thread.Sleep(500); + } + } + ToDo entry; + if (input.Contains("-")) + { + Console.WriteLine("This functionality is under construction"); + } + else if (input == "a") + { + List todosList = Context.ToDos.ToList(); + foreach (var item in todosList) + { + Console.WriteLine("*****************************************************************************************************************"); + Console.Write("Title: "); + Console.WriteLine(item.Title); + Console.Write("Created: "); + Console.WriteLine(item.CreateDate); + Console.Write("Content: "); + Console.WriteLine(item.Content); + if (item.Completed) + { + if (item.Sucess) + { + Console.WriteLine("Status: Completed Successfully"); + } + else + { + Console.WriteLine("Status: Abandoned"); + } + } + else + { + Console.WriteLine("Status: In Progress"); + } + } + Console.WriteLine("*****************************************************************************************************************"); + } + else + { + entry = Context.ToDos.Find(Convert.ToInt32(input)); + var find = Context.ToDos.Find(Convert.ToInt32(input)); + if (find != null) + { + Console.WriteLine("*****************************************************************************************************************"); + Console.Write("Title: "); + Console.WriteLine(entry.Title); + Console.Write("Created: "); + Console.WriteLine(entry.CreateDate); + Console.Write("Content: "); + Console.WriteLine(entry.Content); + if (entry.Completed) + { + if (entry.Sucess) + { + Console.WriteLine("Status: Completed Successfully"); + } + else + { + Console.WriteLine("Status: Abandoned"); + } + } + else + { + Console.WriteLine("Status: In Progress"); + } + Console.WriteLine("*****************************************************************************************************************"); + } + else + { + Console.WriteLine("invalid selection"); + } + Console.ReadLine(); + } + + } + public static void UpdateItem() + { + string input = ""; + while (input == "") + { + Console.Write("Enter item Id: "); + input = Console.ReadLine(); + } + var find = Context.ToDos.Find(Convert.ToInt32(input)); + if (find != null) + { + string modifyWhat = ""; + while (modifyWhat != "t" && modifyWhat != "c" && modifyWhat != "s" && modifyWhat != "a" && modifyWhat != "e") + { + Console.WriteLine("*****************************************************************************************************************"); + Console.Write("Title: "); + Console.WriteLine(find.Title); + Console.Write("Created: "); + Console.WriteLine(find.CreateDate); + Console.Write("Content: "); + Console.WriteLine(find.Content); + if (find.Completed) + { + if (find.Sucess) + { + Console.WriteLine("Status: Completed Successfully"); + } + else + { + Console.WriteLine("Status: Abandoned"); + } + } + else + { + Console.WriteLine("Status: In Progress"); + } + Console.WriteLine("*****************************************************************************************************************"); + Console.WriteLine(); + Console.Write("Modify Entry"); + Console.Write("t = Title c = Content s = successful a = abandon e = Exit: "); + modifyWhat = Console.ReadLine(); + } + if (modifyWhat == "t") + { + string userInput = ""; + while (userInput == "") + { + Console.Clear(); + Console.Write("Enter new Title: "); + userInput = Console.ReadLine(); + } + find.Title = userInput; + } + else if (modifyWhat == "c") + { + string userInput = ""; + while (userInput != "") + { + Console.Clear(); + Console.Write("Enter new Content: "); + userInput = Console.ReadLine(); + } + + find.Content = userInput; + } + else if (modifyWhat == "s") + { + find.Completed = true; + } + else if (modifyWhat == "a") + { + find.Completed = true; + find.Sucess = false; + } + Context.SaveChanges(); + } + } + public static void DeleteItem() + { + string input = ""; + while (input == "") + { + Console.Clear(); + Console.WriteLine("Enter an id of item to remove"); + Console.Write(": "); + input = Console.ReadLine(); + + if (input == "") + { + Console.Clear(); + Console.WriteLine("Invalid Entry"); + Thread.Sleep(500); + } + else + { + var find = Context.ToDos.Find(Convert.ToInt32(input)); + if (find != null) + { + Context.ToDos.Remove(find); + } + Context.SaveChanges(); + } + } + } + } +} diff --git a/SimplifiedTodo/Program.cs b/SimplifiedTodo/Program.cs new file mode 100644 index 00000000..43e74099 --- /dev/null +++ b/SimplifiedTodo/Program.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Threading; + +namespace SimplifiedTodo +{ + class Program + { + static void Main(string[] args) + { + DbContextOptionsBuilder builder = new DbContextOptionsBuilder(); + builder.UseSqlServer("Server=(localdb)\\MSSQLLocalDb;Database=ToDoDB;Trusted_Connection=true"); + DbContextOptions opts = builder.Options; + ToDoDBContext context = new ToDoDBContext(opts); + context.Database.EnsureCreated(); + + Crud crud = new Crud(context); + crud.Run(); + } + } +} \ No newline at end of file diff --git a/SimplifiedTodo/SimplifiedTodo.csproj b/SimplifiedTodo/SimplifiedTodo.csproj new file mode 100644 index 00000000..d3bd01fa --- /dev/null +++ b/SimplifiedTodo/SimplifiedTodo.csproj @@ -0,0 +1,13 @@ + + + + Exe + netcoreapp2.2 + + + + + + + + diff --git a/SimplifiedTodo/ToDo.cs b/SimplifiedTodo/ToDo.cs new file mode 100644 index 00000000..da671ec4 --- /dev/null +++ b/SimplifiedTodo/ToDo.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace SimplifiedTodo +{ + public class ToDo + { + public string Content { get; set; } + public DateTime CreateDate { get; set; } + public string Title { get; set; } + public bool Completed { get; set; } + public bool Sucess { get; set; } = true; + public int Id { get; set; } + } +} diff --git a/SimplifiedTodo/ToDoDBContext.cs b/SimplifiedTodo/ToDoDBContext.cs new file mode 100644 index 00000000..449639b2 --- /dev/null +++ b/SimplifiedTodo/ToDoDBContext.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Text; + +namespace SimplifiedTodo +{ + public class ToDoDBContext : DbContext + { + public ToDoDBContext(DbContextOptions options) : base(options) + { + + } + public DbSet ToDos { get; set; } + } +} + diff --git a/ToDo/.vs/ToDoApp/v15/.suo b/ToDo/.vs/ToDoApp/v15/.suo new file mode 100644 index 00000000..5ca63076 Binary files /dev/null and b/ToDo/.vs/ToDoApp/v15/.suo differ diff --git a/ToDo/.vs/ToDoApp/v15/Server/sqlite3/db.lock b/ToDo/.vs/ToDoApp/v15/Server/sqlite3/db.lock new file mode 100644 index 00000000..e69de29b diff --git a/ToDo/.vs/ToDoApp/v15/Server/sqlite3/storage.ide b/ToDo/.vs/ToDoApp/v15/Server/sqlite3/storage.ide new file mode 100644 index 00000000..52c3d77e Binary files /dev/null and b/ToDo/.vs/ToDoApp/v15/Server/sqlite3/storage.ide differ diff --git a/ToDo/ToDoApp.sln b/ToDo/ToDoApp.sln new file mode 100644 index 00000000..7a2c1787 --- /dev/null +++ b/ToDo/ToDoApp.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.421 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ToDoApp", "ToDoApp\ToDoApp.csproj", "{8E9F0BE5-B8D8-4B25-AEC8-5DB03C96AD38}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8E9F0BE5-B8D8-4B25-AEC8-5DB03C96AD38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E9F0BE5-B8D8-4B25-AEC8-5DB03C96AD38}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E9F0BE5-B8D8-4B25-AEC8-5DB03C96AD38}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E9F0BE5-B8D8-4B25-AEC8-5DB03C96AD38}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {5A43835A-1011-4684-8549-3E48B102432F} + EndGlobalSection +EndGlobal diff --git a/ToDo/ToDoApp/Database/AddEntry.cs b/ToDo/ToDoApp/Database/AddEntry.cs new file mode 100644 index 00000000..975573c5 --- /dev/null +++ b/ToDo/ToDoApp/Database/AddEntry.cs @@ -0,0 +1,12 @@ +using System; + +namespace ToDoApp +{ + internal class AddEntry + { + public void NewTask() + { + //take in a list of values varify them and put them in the DB + } + } +} \ No newline at end of file diff --git a/ToDo/ToDoApp/Database/DeleteEntry.cs b/ToDo/ToDoApp/Database/DeleteEntry.cs new file mode 100644 index 00000000..4077d7ba --- /dev/null +++ b/ToDo/ToDoApp/Database/DeleteEntry.cs @@ -0,0 +1,11 @@ +namespace ToDoApp +{ + internal class DeleteEntry + { + + public void RemoveTask() + { + //take in a task# and move it to completed in the database under IsCompleted + } + } +} \ No newline at end of file diff --git a/ToDo/ToDoApp/Database/NewDatabase.cs b/ToDo/ToDoApp/Database/NewDatabase.cs new file mode 100644 index 00000000..a83cb4b9 --- /dev/null +++ b/ToDo/ToDoApp/Database/NewDatabase.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore; + +namespace ToDoApp +{ + internal class NewDatabase + { + ToDoDbContext Context; + + public void CreateTheDB() + { + DbContextOptionsBuilder builder = new DbContextOptionsBuilder(); + builder.UseSqlServer("Server=(localdb)\\MSSQLLocalDb;Database=BlogDB;Trusted_Connection=true"); + DbContextOptions opts = builder.Options; + ToDoDbContext context = new ToDoDbContext(opts); + Context = context; + } + public ToDoDbContext GetDb() + { + return Context; + } + } +} \ No newline at end of file diff --git a/ToDo/ToDoApp/Database/ToDoDbContext.cs b/ToDo/ToDoApp/Database/ToDoDbContext.cs new file mode 100644 index 00000000..58158a7a --- /dev/null +++ b/ToDo/ToDoApp/Database/ToDoDbContext.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Text; + +namespace ToDoApp +{ + class ToDoDbContext : DbContext + { + public ToDoDbContext(DbContextOptions options) : base(options) + { + + } + public DbSet ToDos { get; set; } + } +} + diff --git a/ToDo/ToDoApp/Display/DisplayController.cs b/ToDo/ToDoApp/Display/DisplayController.cs new file mode 100644 index 00000000..990afd62 --- /dev/null +++ b/ToDo/ToDoApp/Display/DisplayController.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; + +namespace ToDoApp +{ + internal class DisplayController + { + private int index = 0; + + public DisplayController(int indexStart) + { + index = indexStart; + } + + public string MenuController(List items) + { + //return menu item or current index + ConsoleKeyInfo userInput = Console.ReadKey(); + string returnMe = ""; + if (userInput.Key == ConsoleKey.DownArrow) + { + index = index == items.Count - 1 ? 0 : index + 1; + returnMe = index.ToString(); + } + else if (userInput.Key == ConsoleKey.UpArrow) + { + index = index <= 0 ? items.Count - 1 : index - 1; + returnMe = index.ToString(); + } + else if (userInput.Key == ConsoleKey.Enter) + { + returnMe = items[index]; + } + Console.Clear(); + return returnMe; + } + + } +} \ No newline at end of file diff --git a/ToDo/ToDoApp/Program.cs b/ToDo/ToDoApp/Program.cs new file mode 100644 index 00000000..03a79b72 --- /dev/null +++ b/ToDo/ToDoApp/Program.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore; +using System; + +namespace ToDoApp +{ + class Program + { + static void Main(string[] args) + { + NewDatabase newToDoDb = new NewDatabase(); + + ToDoLoop toDoLoop = new ToDoLoop(newToDoDb.GetDb()); + toDoLoop.Run(); + + //stop program from closing + Console.ReadLine(); + } + } +} diff --git a/ToDo/ToDoApp/ToDo.cs b/ToDo/ToDoApp/ToDo.cs new file mode 100644 index 00000000..47a68605 --- /dev/null +++ b/ToDo/ToDoApp/ToDo.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ToDoApp +{ + class ToDo + { + public int Id { get; set; } + public string Title { get; set; } + public string Description { get; set; } + public bool IsCompleted { get; set; } + public DateTime DueDate { get; set; } + } +} diff --git a/ToDo/ToDoApp/ToDoApp.csproj b/ToDo/ToDoApp/ToDoApp.csproj new file mode 100644 index 00000000..dd255df9 --- /dev/null +++ b/ToDo/ToDoApp/ToDoApp.csproj @@ -0,0 +1,17 @@ + + + + Exe + netcoreapp2.2 + + + + + + + + + + + + diff --git a/ToDo/ToDoApp/ToDoLoop.cs b/ToDo/ToDoApp/ToDoLoop.cs new file mode 100644 index 00000000..1ba2dcfa --- /dev/null +++ b/ToDo/ToDoApp/ToDoLoop.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using ToDoApp.Display; + +namespace ToDoApp +{ + internal class ToDoLoop + { + ToDoDbContext DataBase; + + public ToDoLoop(ToDoDbContext db) + { + DataBase = db; + } + + public void Run() + { + string request = ""; + int index = 0; + while (true) + { + while (request != "" || request != "a" || request != "d" || request != "v" || request != "e") + { + List options = new List { "Add Entry", "Update Entry", "Delete Entry", "View Entry", "Exit" }; + DisplayVertical display = new DisplayVertical(options, index); + request = display.SelectTask(); + request = request.Substring(0, 1).ToLower(); + + if (request == "e") + { + break; + } + + ModifyTask task = new ModifyTask(); + switch (request) + { + case "a": + index = 0; + task.AddTask(index, DataBase); + break; + case "u": + index = 0; + task.UpdateTask(index, DataBase); + break; + case "d": + index = 0; + task.RemoveTask(index, DataBase); + break; + case "v": + index = 0; + task.ViewTask(index, DataBase); + break; + default: + break; + } + } + if (request == "e") + { + break; + } + }//finish them + } + } +} \ No newline at end of file