From 125dff547371a8b7da88f97042903c51fc56c8fc Mon Sep 17 00:00:00 2001 From: Axel Date: Wed, 9 Jul 2025 12:58:16 -0400 Subject: [PATCH 1/3] merging_changes and fixing for vs code --- .DS_Store | Bin 0 -> 8196 bytes Asana.API/Asana.API.csproj | 2 +- Asana.Maui/.DS_Store | Bin 0 -> 10244 bytes 3 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 Asana.Maui/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..783e7f6326645053ccddda56b111762af2557f53 GIT binary patch literal 8196 zcmeHM-D(p-6h4!mc4HKBVWC)r1;MKl(-;aWLYk%*g;uevR#1uAB&MsIosevd5(>Fh zpFv+i#T(y1FTE00zZ^Yspm^qV~^X;7Pn@py&1prnVG*gQ zK9|KR#%P?%ge6oDff?e#ZLe4j-sw(6>JF`dRzNGD70?Q31^yKU@XRJNrkwk7RM%Po zt-yb&0R29gSjd-^A4@NOI1$k(L1AgfKp6Y%Ij&*po zYP;OVKHO^KT^l~Gg~ywRkyVFZXngmO-we-s}T%>GXD%)5rnJ|=?>|IK4|WQfsRm-0ImVzh;t+R#IGJ$M#j z_6DPa%w`}%4B5%6v*!si#dW&=P%@qI{2=37r5|sVHZu?*=7|C^KM`WSjhqMIggLXb z5zes~d)V))Z@>q;>pFeEQ24?U$y9o7-k3MC#(is#4=um$5BimQ?=F41$+>GEwCnb5 zr!}nQPOo#%uRC6=Cjd^fg(3HL9k0oU6+ZBqeSx*)fRQmWwcO%pR9r1An-`0v{bh4> zsfg{;YH5EzV=SDzaAl|V*zI`y1rf$0Mjb`C>S23{A7i-%S8{1|qdYAxxQ5%WzJ6=V zHH>{`aP|Ha8(g=g*CtLMpXU>+=egW#<2Z2)?~*>a;6+xJ7ze-2S=!6Eqc`9hSXk%5 zho|62P~Rh{4D4X+8dPChU^>tYBNCKRa30K0pZ} zE1(rPHVUv*)v8u7-Ge`9qM6fO+r;t!3mL_Yr56ya#C06KIF8XD{=*R4CWaEGto&Gd S>_O8n0)z~@(hB@l1%3gjA0fX0 literal 0 HcmV?d00001 diff --git a/Asana.API/Asana.API.csproj b/Asana.API/Asana.API.csproj index 3260759..26812de 100644 --- a/Asana.API/Asana.API.csproj +++ b/Asana.API/Asana.API.csproj @@ -1,7 +1,7 @@ - net8.0 + net9.0 enable enable diff --git a/Asana.Maui/.DS_Store b/Asana.Maui/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5c126186e1b048ed111b99341c04a711910663cf GIT binary patch literal 10244 zcmeHMzi$&U6n^dxxU>`n2@ng?2^NG5CT+kO-KWmyC^>hsH&6^ z!NSfzz<^Xn23X-gU|>OFU}j~4@7X4`FFu%%P-RE* z>09ps?*Z?Dkq3Bx2vJ#SZdve*bAZHzT9&mODk-6`sZI|nbbQH(5%&=a_43HO06b|E-&^6bU6^@njQNuOcmC_-<{G^f6gT8@Th6E_wr8)>V}V{@Nxz1kgV zr7J6%XYgVve&3*v>=BJ?rL{kdwl@u{-@dbPjeAt-BypN>1bB6GGWPI2ts(~+h*eGo z66dZNjbc7h<&hmtnZYLh;3(@>Wxh4g@=clJy^+~#VkeQGkuyUbT6-p6BxfsMUT(dR zk(DE6zMQDMe>ch(J-VAO2+ijCj9m^F9S$O~?!<-igF%V<&QAY*zFn z&vp(kr%m%MH<&qfEpF;3V}aI~4cPU;ZNtF~Z?(nDfv|W@eR&FA4y_zkPR*QXjjh#U zG+oBTh}I1mp#gS}lxkoUXQRbCjm61{u~^Z;4|%q8csXt6M$55giyMW^ZFOE90tT$9rLeQ`Z_si>eeBpEMDcx6M$pzzOEr&`< iIQk_VQr+hN^M3~H-a`5Ff9Cw<&;P$~C}~fh|9=5$vFtPe literal 0 HcmV?d00001 From 0a26c8f7b5966d83a916b204fa95a9b77906f6db Mon Sep 17 00:00:00 2001 From: Axel Date: Mon, 28 Jul 2025 14:39:59 -0500 Subject: [PATCH 2/3] Integrated Sqlite db --- Asana.CLI/Asana.CLI.csproj | 3 +- Asana.CLI/Program.cs | 109 ++++++++++--------------------------- Asana.CLI/asana.db | Bin 0 -> 12288 bytes 3 files changed, 31 insertions(+), 81 deletions(-) create mode 100644 Asana.CLI/asana.db diff --git a/Asana.CLI/Asana.CLI.csproj b/Asana.CLI/Asana.CLI.csproj index 7c06fea..ce657ba 100644 --- a/Asana.CLI/Asana.CLI.csproj +++ b/Asana.CLI/Asana.CLI.csproj @@ -2,12 +2,13 @@ Exe - net8.0 + net9.0 enable enable + diff --git a/Asana.CLI/Program.cs b/Asana.CLI/Program.cs index a3be611..b266b06 100644 --- a/Asana.CLI/Program.cs +++ b/Asana.CLI/Program.cs @@ -1,88 +1,37 @@ -using Asana.Library.Models; -using Asana.Library.Services; +using Asana.API.Database; +using Asana.Library.Models; using System; -namespace Asana +class Program { - public class Program + static void Main(string[] args) { - - public static void Main(string[] args) - { - var toDoSvc = ToDoServiceProxy.Current; - int choiceInt; - do - { - Console.WriteLine("Choose a menu option:"); - Console.WriteLine("1. Create a ToDo"); - Console.WriteLine("2. List all ToDos"); - Console.WriteLine("3. List all outstanding ToDos"); - Console.WriteLine("4. Delete a ToDo"); - Console.WriteLine("5. Update a ToDo"); - Console.WriteLine("6. Exit"); - - var choice = Console.ReadLine() ?? "6"; - - if (int.TryParse(choice, out choiceInt)) - { - switch (choiceInt) - { - case 1: - Console.Write("Name:"); - var name = Console.ReadLine(); - Console.Write("Description:"); - var description = Console.ReadLine(); - - toDoSvc.AddOrUpdate(new ToDo - { - Name = name, - Description = description, - IsCompleted = false, - Id = 0 - }); - break; - case 2: - toDoSvc.DisplayToDos(true); - break; - case 3: - toDoSvc.DisplayToDos(); - break; - case 4: - toDoSvc.DisplayToDos(true); - Console.Write("ToDo to Delete: "); - var toDoChoice4 = int.Parse(Console.ReadLine() ?? "0"); - - var reference = toDoSvc.GetById(toDoChoice4); - toDoSvc.DeleteToDo(reference?.Id ?? 0); - break; - case 5: - toDoSvc.DisplayToDos(true); - Console.Write("ToDo to Update: "); - var toDoChoice5 = int.Parse(Console.ReadLine() ?? "0"); - var updateReference = toDoSvc.GetById(toDoChoice5); - if (updateReference != null) - { - Console.Write("Name:"); - updateReference.Name = Console.ReadLine(); - Console.Write("Description:"); - updateReference.Description = Console.ReadLine(); - } - toDoSvc.AddOrUpdate(updateReference); - break; - case 6: - break; - default: - Console.WriteLine("ERROR: Unknown menu selection"); - break; - } - } else - { - Console.WriteLine($"ERROR: {choice} is not a valid menu selection"); - } - - } while (choiceInt != 6); + // Added the sql connection and then delete it + var context = new SqliteContext(); + // Add a new ToDo + var newToDo = new ToDo + { + Name = "Test Task", + Description = "Testing SQLite insert", + IsCompleted = false, + Priority = 1 + }; + + context.AddOrUpdateToDo(newToDo); + Console.WriteLine($"Added ToDo with ID: {newToDo.Id}"); + + // Get all ToDos + var allToDos = context.ToDos; + Console.WriteLine("\nAll ToDos:"); + foreach (var todo in allToDos) + { + Console.WriteLine($"ID: {todo.Id}, Name: {todo.Name}, Completed: {todo.IsCompleted}"); } + + // Delete test ToDo + context.DeleteToDo(newToDo.Id); + Console.WriteLine($"\nDeleted ToDo with ID: {newToDo.Id}"); } -} \ No newline at end of file +} diff --git a/Asana.CLI/asana.db b/Asana.CLI/asana.db new file mode 100644 index 0000000000000000000000000000000000000000..95d1a0514cfc9d5ebb1d113d455a0c071b3ead9e GIT binary patch literal 12288 zcmeI&F-yZh6bJCT#wrT7Zdu>h(&FMQ7~4aFX&U1d>?F0G5NMM&iGyqLQ#tuL{2uPU zv{bPey4(LFcgcl&$K8)C4|03sMY*A;B%O|OIuj>CN^wCXgs5_}xUEC-!`^zp_hP&) zs^T<$JLXxHS}bbs+#w(U0SG_<0uX=z1Rwwb2tZ&51cJ)G-D=5UK6;p#Y(C-A^FA~4 zXA_S%hgK(4j#i|dOHa|p+(tZ_nl@)P7w7W8wr%;kT2m+8BwKcsU-`>d)HtG&a39I_ zwYpLv1)!XaI&AvpuxcYR)|r+nQm&GvaWq}81!zt3&pdF6AvCL5>GERT|SnNmK} z%{s|+HZi&R+1&Q^gEUIgD1Z4r&pPGL-8YNcoQr-@|JZ@g4@ZOm1Rwwb2tWV=5P$## wAOHaf?5IFd|I7NP;0pl(2tWV=5P$##AOHafKmY;|fWUteIFyzxSAR)-0l&6!E&u=k literal 0 HcmV?d00001 From 4076c3d2a9cf3b145bb0ce92f271051fdb208a32 Mon Sep 17 00:00:00 2001 From: Axel Date: Mon, 28 Jul 2025 14:45:36 -0500 Subject: [PATCH 3/3] Add SQLite support and update ToDo API --- Asana.API/Asana.API.csproj | 2 + Asana.API/Asana.API.sln | 24 +++++ Asana.API/Controllers/ToDoController.cs | 8 +- Asana.API/Database/SqLiteContext.cs | 134 ++++++++++++++++++++++++ Asana.API/Enterprise/ToDoEC.cs | 24 ++--- Asana.API/appsettings.json | 1 + Asana.API/asana.db | Bin 0 -> 12288 bytes Asana.Library/DTOs/ToDoDTO.cs | 30 ++++++ Asana.Library/Models/ToDo.cs | 16 ++- 9 files changed, 224 insertions(+), 15 deletions(-) create mode 100644 Asana.API/Asana.API.sln create mode 100644 Asana.API/Database/SqLiteContext.cs create mode 100644 Asana.API/asana.db create mode 100644 Asana.Library/DTOs/ToDoDTO.cs diff --git a/Asana.API/Asana.API.csproj b/Asana.API/Asana.API.csproj index 26812de..92ffb75 100644 --- a/Asana.API/Asana.API.csproj +++ b/Asana.API/Asana.API.csproj @@ -7,8 +7,10 @@ + + diff --git a/Asana.API/Asana.API.sln b/Asana.API/Asana.API.sln new file mode 100644 index 0000000..0ce6a9b --- /dev/null +++ b/Asana.API/Asana.API.sln @@ -0,0 +1,24 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.2.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Asana.API", "Asana.API.csproj", "{447D3E3A-83F3-91C7-4B6B-DAFF35B66491}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {447D3E3A-83F3-91C7-4B6B-DAFF35B66491}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {447D3E3A-83F3-91C7-4B6B-DAFF35B66491}.Debug|Any CPU.Build.0 = Debug|Any CPU + {447D3E3A-83F3-91C7-4B6B-DAFF35B66491}.Release|Any CPU.ActiveCfg = Release|Any CPU + {447D3E3A-83F3-91C7-4B6B-DAFF35B66491}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {69FD3303-CA61-48FB-9807-0E80CD7B91E3} + EndGlobalSection +EndGlobal diff --git a/Asana.API/Controllers/ToDoController.cs b/Asana.API/Controllers/ToDoController.cs index 80d9b17..2fa90a1 100644 --- a/Asana.API/Controllers/ToDoController.cs +++ b/Asana.API/Controllers/ToDoController.cs @@ -24,7 +24,13 @@ public IEnumerable Get() [HttpDelete("{id}")] public ToDo? Delete(int id) { - return new ToDoEC().Delete(id); + var ec = new ToDoEC(); + var toDo = ec.GetById(id); // get it before it's deleted + if (toDo == null) + return null; + + ec.Delete(id); + return toDo; } [HttpPost] diff --git a/Asana.API/Database/SqLiteContext.cs b/Asana.API/Database/SqLiteContext.cs new file mode 100644 index 0000000..35bd0bb --- /dev/null +++ b/Asana.API/Database/SqLiteContext.cs @@ -0,0 +1,134 @@ +using Asana.Library.Models; +using Microsoft.Data.Sqlite; +using System.Collections.Generic; + +namespace Asana.API.Database +{ + public class SqliteContext + { + private string _connectionString; + + public SqliteContext() + { + _connectionString = "Data Source=asana.db"; + InitializeDatabase(); + } + + private void InitializeDatabase() + { + using (var connection = new SqliteConnection(_connectionString)) + { + connection.Open(); + + var command = connection.CreateCommand(); + command.CommandText = @" + CREATE TABLE IF NOT EXISTS ToDos ( + Id INTEGER PRIMARY KEY AUTOINCREMENT, + Name TEXT NOT NULL, + Description TEXT, + IsCompleted INTEGER NOT NULL, + Priority INTEGER NOT NULL + );"; + command.ExecuteNonQuery(); + } + } + + public List ToDos + { + get + { + var toDos = new List(); + + using (var connection = new SqliteConnection(_connectionString)) + { + connection.Open(); + + var command = connection.CreateCommand(); + command.CommandText = "SELECT * FROM ToDos"; + + using (var reader = command.ExecuteReader()) + { + while (reader.Read()) + { + var toDo = new ToDo + { + Id = reader.GetInt32(reader.GetOrdinal("Id")), + Name = reader.GetString(reader.GetOrdinal("Name")), + Description = reader.GetString(reader.GetOrdinal("Description")), + IsCompleted = reader.GetInt32(reader.GetOrdinal("IsCompleted")) == 1, + Priority = reader.GetInt32(reader.GetOrdinal("Priority")) + }; + toDos.Add(toDo); + } + } + } + + return toDos; + } + } + + public ToDo? AddOrUpdateToDo(ToDo? toDo) + { + if (toDo == null) return null; + + using (var connection = new SqliteConnection(_connectionString)) + { + connection.Open(); + + var command = connection.CreateCommand(); + + if (toDo.Id <= 0) + { + command.CommandText = @" + INSERT INTO ToDos (Name, Description, IsCompleted, Priority) + VALUES (@name, @description, @isCompleted, @priority); + SELECT last_insert_rowid();"; + } + else + { + command.CommandText = @" + UPDATE ToDos + SET Name = @name, + Description = @description, + IsCompleted = @isCompleted, + Priority = @priority + WHERE Id = @id;"; + command.Parameters.AddWithValue("@id", toDo.Id); + } + + command.Parameters.AddWithValue("@name", toDo.Name); + command.Parameters.AddWithValue("@description", toDo.Description); + command.Parameters.AddWithValue("@isCompleted", toDo.IsCompleted); + command.Parameters.AddWithValue("@priority", toDo.Priority); + + if (toDo.Id <= 0) + { + var result = command.ExecuteScalar(); + toDo.Id = Convert.ToInt32(result); + } + else + { + command.ExecuteNonQuery(); + } + } + + return toDo; + } + + public int DeleteToDo(int toDoId) + { + using (var connection = new SqliteConnection(_connectionString)) + { + connection.Open(); + + var command = connection.CreateCommand(); + command.CommandText = "DELETE FROM ToDos WHERE Id = @id"; + command.Parameters.AddWithValue("@id", toDoId); + + command.ExecuteNonQuery(); + } + + return toDoId; + } + } +} diff --git a/Asana.API/Enterprise/ToDoEC.cs b/Asana.API/Enterprise/ToDoEC.cs index 75609f2..410e30e 100644 --- a/Asana.API/Enterprise/ToDoEC.cs +++ b/Asana.API/Enterprise/ToDoEC.cs @@ -1,18 +1,20 @@ -using Api.ToDoApplication.Persistence; -using Asana.API.Database; +using Asana.API.Database; using Asana.Library.Models; namespace Asana.API.Enterprise { public class ToDoEC { - public ToDoEC() { - + private readonly SqliteContext _context; + + public ToDoEC() + { + _context = new SqliteContext(); } public IEnumerable GetToDos() { - return Filebase.Current.ToDos.Take(100); + return _context.ToDos.Take(100); } public ToDo? GetById(int id) @@ -20,20 +22,18 @@ public IEnumerable GetToDos() return GetToDos().FirstOrDefault(t => t.Id == id); } - public ToDo? Delete(int id) + public int Delete(int id) { - var toDoToDelete = GetById(id); - if (toDoToDelete != null) + if (id > 0) { - //Filebase.Current.Delete(toDoToDelete); + return _context.DeleteToDo(id); } - return toDoToDelete; + return -1; } public ToDo? AddOrUpdate(ToDo? toDo) { - Filebase.Current.AddOrUpdate(toDo); - return toDo; + return _context.AddOrUpdateToDo(toDo); } } } diff --git a/Asana.API/appsettings.json b/Asana.API/appsettings.json index 10f68b8..612bbd1 100644 --- a/Asana.API/appsettings.json +++ b/Asana.API/appsettings.json @@ -5,5 +5,6 @@ "Microsoft.AspNetCore": "Warning" } }, + "AllowedHosts": "*" } diff --git a/Asana.API/asana.db b/Asana.API/asana.db new file mode 100644 index 0000000000000000000000000000000000000000..770b2914a9b72315065d7977e5504aa14ed6815a GIT binary patch literal 12288 zcmeI&K~KUk6bJBj7(^4n+m5~?1meZSn~4(^vpB|tlE}$SD7Xk4Y&AxY#t-JvPsG^* zK_ih6ZzTR-)~;RNYuewf$y(QLs3i5{WE3bmVTX)!c22|?Gjz-7whXQZJIjfF&*q!L zV8<_$1D$2$BbI;H9RdOnfB*y_009U<00Izz00jPlfNx~Ya+!Bja5t3cWT>y6x2c>w z%BZ_K%~YGVC2SJbg=^DFZZQf*vZ5-$LBDRgMgvm!lKe(Xkc@icIE)nalXyg}r(iIUiLto