From bae134600b0eeead3a057bbcff4b374ec6cc1cee Mon Sep 17 00:00:00 2001 From: Forrest-Flowers Date: Sun, 9 Dec 2018 10:19:14 -0600 Subject: [PATCH 1/3] Skeleton Draft --- Checkpoint3/Program.cs | 75 ++++++++++++++++++++++++++++++++++ Checkpoint3/checkpoint3.csproj | 8 ++++ 2 files changed, 83 insertions(+) create mode 100644 Checkpoint3/Program.cs create mode 100644 Checkpoint3/checkpoint3.csproj diff --git a/Checkpoint3/Program.cs b/Checkpoint3/Program.cs new file mode 100644 index 00000000..ed31f03b --- /dev/null +++ b/Checkpoint3/Program.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; + +namespace checkpoint3 +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Welcome"); + } + } + + public class UserSays + { + public UserSays() + { + Console.WriteLine(""); + Console.WriteLine(""); + Console.WriteLine(""); + Console.WriteLine(""); + Console.WriteLine(""); + } + } + + public class Todo + { + public static int id; + public string task { get; set; } + public bool isComplete { get; set; } + public List tags { get; set; } + + public Todo(int id, string task) + { + + } + + } + + //Controller + public interface ITodo + { + + } + + public class ToDoDAO + { + //Creates a new Todo object. + public static void Add() + { + + } + //Takes an existing Todo object and allows you to edit it. + public static void Update() + { + + } + //Lists all Todo objects. + public static void GetAll() + { + + } + //Removes on Todo object by id + public static void Remove() + { + + } + //Fetches one Todo object from database. + public static GetTodo() + { + + } + } +} + diff --git a/Checkpoint3/checkpoint3.csproj b/Checkpoint3/checkpoint3.csproj new file mode 100644 index 00000000..23df6047 --- /dev/null +++ b/Checkpoint3/checkpoint3.csproj @@ -0,0 +1,8 @@ + + + + Exe + netcoreapp2.1 + + + From 5470f7278bbe5d1a73e8ecb240c5260e7fd51b67 Mon Sep 17 00:00:00 2001 From: Forrest-Flowers Date: Mon, 17 Dec 2018 15:30:23 -0600 Subject: [PATCH 2/3] Done. Extremely minimalist and lacks controller, but otherwise foolproof --- Database/Database.cs | 222 ++++++++++++++++++++++++++++++++++----- Database/Database.csproj | 1 + Database/database.db | Bin 49152 -> 0 bytes Database/todo.db | Bin 0 -> 12288 bytes 4 files changed, 195 insertions(+), 28 deletions(-) delete mode 100644 Database/database.db create mode 100644 Database/todo.db diff --git a/Database/Database.cs b/Database/Database.cs index 588082e7..1c47727a 100644 --- a/Database/Database.cs +++ b/Database/Database.cs @@ -1,49 +1,215 @@ using System; using System.Collections.Generic; -using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; using System.Linq; +using System.Threading; -namespace Database{ +namespace Database +{ class Program { - static SqliteConnectionStringBuilder connectionStringBuilder = new SqliteConnectionStringBuilder(); - static List> results = new List>(); - static void Main(string[] args) { - connectionStringBuilder.DataSource = "./database.db"; - SqliteDataReader reader = RunQuery(@" - SELECT * FROM items; - "); - PrintResults(reader); + DAO theDao = new DAO(); + List theList = theDao.list(); + string userInput = " "; + string id; + string yesNo; + + Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~"); + Console.WriteLine("-------TO DO APP-------"); + Console.WriteLine("--By: Forrest Flowers--"); + Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~"); + Thread.Sleep(1500); + while (userInput != "exit") + { + + Console.WriteLine("Please enter 'add', 'remove', 'list','update' 'list done' or 'exit'"); + userInput = Console.ReadLine().ToLower(); + if (userInput == "add") + { + Console.WriteLine("Do you want to add a task?"); + yesNo = Console.ReadLine(); + + if (yesNo == "yes" || yesNo == "y") + { + Console.WriteLine("Enter a task:"); + string task = Console.ReadLine(); + theDao.add(task); + theDao.save(); + } + else + { + Console.WriteLine("Returning to menu..."); + } + } + else if (userInput == "list") + { + foreach (Todo item in theDao.list()) + { + Console.WriteLine(item); + } + } + /* -Make sure you actually want to add something. + -Enter the Id to lookup. + -Calls the GetTodo method + -Use it to grab the Todo with that Id + -Put the Todo in remove method. + */ + else if (userInput == "remove") + { + Console.WriteLine("Do you want to delete an entry?(Y/N)"); + yesNo = Console.ReadLine().ToLower(); + if (yesNo == "yes" || yesNo == "y") + { + Console.WriteLine("Enter the id of the task you want to remove."); + id = Console.ReadLine(); + Todo removeItem = theDao.GetTodo(id); + theDao.remove(removeItem); + theDao.save(); + + Console.WriteLine("Deleted!"); + } + else + { + Console.WriteLine("Gotcha, returning to menu..."); + } + } + else if (userInput == "update") + { + Console.WriteLine("Do you want to mark a task as complete? (Y/N)"); + yesNo = Console.ReadLine().ToLower(); + if (yesNo == "yes" || yesNo == "y") + { + Console.WriteLine("Enter the id of a task to mark as complete"); + id = Console.ReadLine(); + Todo markAsDone = theDao.GetTodo(id); + markAsDone.Status = true; + theDao.save(); + } + else + { + Console.WriteLine("Gotcha, returning to menu..."); + } + } + else if (userInput == "list done") + { + foreach (Todo item in theDao.listDone()) + { + Console.WriteLine(item); + } + } + else if (userInput == "exit") + { + break; + } + else + { + Console.WriteLine("Invalid Input."); + } + + + } + + } + } + + public class Todo + { + public int Id { get; set; } + public string Task { get; set; } + public bool Status { get; set; } + + public Todo(int Id, string Task) + { + this.Id = Id; + this.Task = Task; + } + + public Todo(string Task) + { + this.Task = Task; + } + + override + public string ToString() + { + return Id + ": " + Task + " | " + (Status ? "Complete" : "Incomplete"); + } + } + + public class DAO + { + public Context context; + public DAO() + { + context = new Context(); + context.Database.EnsureCreated(); } - static SqliteDataReader RunQuery(string query) + public List list() { - using (var connection = new SqliteConnection(connectionStringBuilder.ConnectionString)) + List allItems = new List(); + foreach (Todo item in context.myList) { - connection.Open(); - var selectCmd = connection.CreateCommand(); - selectCmd.CommandText = query; - return selectCmd.ExecuteReader(); + allItems.Add(item); } + return allItems; + } + + //Add an items to the database. + public void add(string task) + { + context.myList.Add(new Todo(task)); } - static void PrintResults(SqliteDataReader reader) + //Search a single item in the database by Id. + public Todo GetTodo(string findId) + { + foreach (Todo item in context.myList) + { + if (item.Id.ToString() == findId) + { + return item; + } + } + return null; + } + public List listDone() { - results.Clear(); - var row = 0; - while (reader.Read()){ - results.Add(new Dictionary()); - for (var column = 0; column < reader.FieldCount; column++) + List doneList = new List(); + + foreach (Todo item in context.myList) + { + if (item.Status == true) { - results[row].Add(reader.GetName(column), reader.GetString(column)); + doneList.Add(item); + return doneList; } - var lines = results[row].Select(kvp => kvp.Key + ": " + kvp.Value.ToString()); - Console.WriteLine(String.Join(Environment.NewLine, lines)); - Console.WriteLine(""); - row++; } + return null; + } + + public void remove(Todo removeItem) + { + context.myList.Remove(removeItem); + } + + public void save() + { + context.SaveChanges(); + } + + } + + //Sets up the database. + public class Context : DbContext + { + public DbSet myList { get; set; } + override + protected void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlite("Filename =./todo.db"); } } -} +} \ No newline at end of file diff --git a/Database/Database.csproj b/Database/Database.csproj index 264c27d5..859c4da9 100644 --- a/Database/Database.csproj +++ b/Database/Database.csproj @@ -7,6 +7,7 @@ + diff --git a/Database/database.db b/Database/database.db deleted file mode 100644 index e4e11295ca188d8e54a08db72ef23930d1c627c2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 49152 zcmeI)Z*SW~90%~bIEm~0yQy@uN+@wUAr@_AiaKdX2$8G{rJ_x@EK%tmka(%LMWl8Y zrz(BGgR~NFfw#b;NqYlBNIaUvGe8Ilq`}04J{oA^Q6KR0pCm0TrDB`Zbl+=jpY5}K z_wm{4)%IPxI^Sp;+D)sqs<*Xic7k!va+<~%3)2wuhX74KrXff}H}G!cfN7Y$#jnSs zUo$0ofhV@37vgutd?FS5GX86HC%&C{n0R==)>s7r2tWV=5P$##UT%S{XqHX-`oW*OcMxB-yD+`6v+|0gJb<1q)4U<%#cF;(s z6B(D)REl@%u5sO3UDM5mVfP~8eWjf2EuVbuC5dF>*I7nYRlZemGeexKwma%lhc7yR z$TQY?htBCi3BA)l>2Cb|bNa02=O<(}o#tB^-`qb%gx-xw`_yaw6)&a&ZRjoIwzX~> z18PY^r4y4(@{V^UdX-?)pX{w6nYY90yDDc5bH(`7yQ-`DdfRg6tM2KjX5C37`)XJ% zqy{DJ)w6207nKv!uZPvy^x$o}e9lJQcra0BBTl86e(j)*djxhh+mDYVzGvt2$-zf- zE|<-29yjGH!LWMvEMMMp!>ZcGopr;k`!~7XY-ryp_N}^U&p225IhxB*#y8x`lBDaH zbU#}fl$k@_M620DC5v>jNw1Dhxkc%V^kad21(@uwc*YCPuU1d3iq4hSwCZ}hVVVE9 z5z_60tb*bJ6Hml%;s=T#KmY;|fB*y_009U<00Izz00ba#gasnOAXCOK>&>QaM&n|~@BOi;5w#r+wz~v23U+* z{}YPW`k%^1NG>RLnAjD6iN_Q{fB*y_009U<00Izz00bZa0SG`~hy_9t=fR*emLz8! z2uPBm#Klk4{=dh>J@H695MPPUhq#EyIs_m90SG_<0uX=z1Rwwb2teRS3uI17OZ-rs z49Kw&DW&wfcTi4ADtG&akP|T}&G&TSAfB*@yGl+dw5H$HfYXOx%-_YP^Zq{?>U!1w=D zL|J^o#E$q*d?W6PFGPoC5g-5o2tWV=5P$##AOHafKmY;|_Q{rgQPj0L@27%f9@=3emN{|)KE$QA$q diff --git a/Database/todo.db b/Database/todo.db new file mode 100644 index 0000000000000000000000000000000000000000..9db68106717133e79451f47dc9ed7b9752e73deb GIT binary patch literal 12288 zcmeI&!Aiq07zglVElvls>SYc*d{hL7vWw{1Dz%Jt-RvT`lhj(Vx~*=B2aozf`Uran zpTQ^4yP0zb74+so{vS=+d?a7s*Ha+vLqAmsooB;dq-cvRFwWU75o0W`o1xn@xc)Gw z1N|P4e~Ub;t~?g?tla!7vpn4)AOHafKmY;|fB*y_009U<00Ms{(8|q}Ha2)iMW@|F z4!ZgTd?J&^QCf`-+S*hd$)cn)uhjT zs$fr&Hmw&6q{FVA*;EUJ>$xEXO+mqt@6&!WXp7L%d9qvelj)jPSZg?8hw5&JoFmb! z1-f>_4aDY0F%iitn}mBjsWVNtRitj@_kD_m%J^(m?LPSzXAPZ0%!G+#P3@ zxyiO?57K@rFGyXalCFo@WfH6E`25eU7p5Ns1Rwwb2tWV=5P$##AOHafKmY>&NT9%t KGN0TjFy8?9N_IH_ literal 0 HcmV?d00001 From 18b89a9b96340b5db9b02790a5b599098d22235a Mon Sep 17 00:00:00 2001 From: Forrest-Flowers Date: Wed, 19 Dec 2018 20:24:58 -0600 Subject: [PATCH 3/3] Bugfix from class --- Database/Database.cs | 6 +++--- Database/todo.db | Bin 12288 -> 12288 bytes 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Database/Database.cs b/Database/Database.cs index 1c47727a..62c4e298 100644 --- a/Database/Database.cs +++ b/Database/Database.cs @@ -21,9 +21,9 @@ static void Main(string[] args) Console.WriteLine("--By: Forrest Flowers--"); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~"); Thread.Sleep(1500); + while (userInput != "exit") { - Console.WriteLine("Please enter 'add', 'remove', 'list','update' 'list done' or 'exit'"); userInput = Console.ReadLine().ToLower(); if (userInput == "add") @@ -114,6 +114,7 @@ static void Main(string[] args) } } + // Cookie Cutter Todo Class public class Todo { public int Id { get; set; } @@ -184,10 +185,9 @@ public List listDone() if (item.Status == true) { doneList.Add(item); - return doneList; } } - return null; + return doneList; } public void remove(Todo removeItem) diff --git a/Database/todo.db b/Database/todo.db index 9db68106717133e79451f47dc9ed7b9752e73deb..591f34de89c72c87219854d400cce4d98561a493 100644 GIT binary patch delta 78 zcmV-U0I~moV1Qtd8vzQD976#Lv0$MO4-eD;0}rbJ59SZR533KWvk?%R4;2#y1OO`t kS7CE#AarPDAY^HCXk~Mgz#kL_0000IB?+_IA0-e01$B}YLjV8( delta 71 zcmV-N0J#5vV1Qtd8vzHA976#Iv0$MO4*&oF0}sFe59SZl55Nzvvk@So4-OF{2uE)q dbZ;PYbZ>HHlfWMo1`q-S03`^s+8-ql0R+u-6Ab_W