diff --git a/COA.EnterpriseServices.Creditor/COA.EnterpriseServices.Creditor.csproj b/COA.EnterpriseServices.Creditor/COA.EnterpriseServices.Creditor.csproj index cb63190..da7db72 100644 --- a/COA.EnterpriseServices.Creditor/COA.EnterpriseServices.Creditor.csproj +++ b/COA.EnterpriseServices.Creditor/COA.EnterpriseServices.Creditor.csproj @@ -4,4 +4,8 @@ netcoreapp3.1 + + + + diff --git a/COA.EnterpriseServices.Creditor/Class1.cs b/COA.EnterpriseServices.Creditor/Class1.cs deleted file mode 100644 index 7699b01..0000000 --- a/COA.EnterpriseServices.Creditor/Class1.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace COA.EnterpriseServices.Creditor -{ - public class CreditorController - { - } - - public class SettlementController - { - - } -} diff --git a/COA.EnterpriseServices.Creditor/CreditorController.cs b/COA.EnterpriseServices.Creditor/CreditorController.cs new file mode 100644 index 0000000..f5f6669 --- /dev/null +++ b/COA.EnterpriseServices.Creditor/CreditorController.cs @@ -0,0 +1,27 @@ +using COA.EnterpriseServices.DataAccess.Helpers; +using System; + +namespace COA.EnterpriseServices.Creditor +{ + public class CreditorController + { + private readonly CreditorHelper creditorHelper; + + public CreditorController(CreditorHelper creditorHelper) + { + this.creditorHelper = creditorHelper; + } + + public string GetCreditorStatus(int creditorId) + { + var creditor = creditorHelper.GetCreditor(creditorId); + + return creditor.Status; + } + + public bool SetCreditorStatus(int creditorId, string status) + { + return creditorHelper.SetCreditorStatus(creditorId, status); + } + } +} diff --git a/COA.EnterpriseServices.DataAccess.EntityFramework/EntityDataAccess.cs b/COA.EnterpriseServices.DataAccess.EntityFramework/EntityDataAccess.cs index e7e69c9..f7dbf16 100644 --- a/COA.EnterpriseServices.DataAccess.EntityFramework/EntityDataAccess.cs +++ b/COA.EnterpriseServices.DataAccess.EntityFramework/EntityDataAccess.cs @@ -1,11 +1,12 @@ -using System; +using Microsoft.EntityFrameworkCore; +using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; namespace COA.EnterpriseServices.DataAccess.EntityFramework { - public class EntityDataAccess : IDataAccess where T : class, IRecord + public class EntityDataAccess : IDataAccess where T : class, IRecord, new() { public bool Add(T item) { @@ -23,7 +24,23 @@ namespace COA.EnterpriseServices.DataAccess.EntityFramework { using (var context = new QuickBaseContext()) { - context.Entry(item); + var entry = context.Entry(item); + + entry.State = EntityState.Modified; + + context.SaveChanges(); + } + + return true; + } + + public bool Update(int id, Action update) + { + using (var context = new QuickBaseContext()) + { + var item = context.Set().FirstOrDefault(e => e.Id == id); + + update(item); context.SaveChanges(); } diff --git a/COA.EnterpriseServices.DataAccess.QuickBase/QuickBaseDataAccess.cs b/COA.EnterpriseServices.DataAccess.QuickBase/QuickBaseDataAccess.cs index 607b44e..091bd60 100644 --- a/COA.EnterpriseServices.DataAccess.QuickBase/QuickBaseDataAccess.cs +++ b/COA.EnterpriseServices.DataAccess.QuickBase/QuickBaseDataAccess.cs @@ -20,6 +20,11 @@ namespace COA.EnterpriseServices.DataAccess.QuickBase return true; } + public bool Update(int id, Action update) + { + return true; + } + public ICollection Get(Expression> query) { // we'll never get data from QB diff --git a/COA.EnterpriseServices.DataAccess/Helpers/CreditorHelper.cs b/COA.EnterpriseServices.DataAccess/Helpers/CreditorHelper.cs index c437be0..f15c742 100644 --- a/COA.EnterpriseServices.DataAccess/Helpers/CreditorHelper.cs +++ b/COA.EnterpriseServices.DataAccess/Helpers/CreditorHelper.cs @@ -41,5 +41,10 @@ namespace COA.EnterpriseServices.DataAccess.Helpers { return creditorDataAccess.Invoke(d => d.Add(creditor)); } + + public bool SetCreditorStatus(int creditorId, string status) + { + return creditorDataAccess.Invoke(d => d.Update(creditorId, c => c.Status = status)); + } } } diff --git a/COA.EnterpriseServices.DataAccess/IDataAccess.cs b/COA.EnterpriseServices.DataAccess/IDataAccess.cs index 6c0f11a..3766af6 100644 --- a/COA.EnterpriseServices.DataAccess/IDataAccess.cs +++ b/COA.EnterpriseServices.DataAccess/IDataAccess.cs @@ -10,6 +10,8 @@ namespace COA.EnterpriseServices.DataAccess bool Update(T item); + bool Update(int id, Action update); + ICollection Get(Expression> query); } } diff --git a/COA.EnterpriseServices.Sandbox/COA.EnterpriseServices.Sandbox.csproj b/COA.EnterpriseServices.Sandbox/COA.EnterpriseServices.Sandbox.csproj index ddd1894..f1f97c1 100644 --- a/COA.EnterpriseServices.Sandbox/COA.EnterpriseServices.Sandbox.csproj +++ b/COA.EnterpriseServices.Sandbox/COA.EnterpriseServices.Sandbox.csproj @@ -6,6 +6,7 @@ + diff --git a/COA.EnterpriseServices.Sandbox/Program.cs b/COA.EnterpriseServices.Sandbox/Program.cs index fc640c8..8d3c8af 100644 --- a/COA.EnterpriseServices.Sandbox/Program.cs +++ b/COA.EnterpriseServices.Sandbox/Program.cs @@ -1,6 +1,7 @@ -using COA.EnterpriseServices.DataAccess; -using COA.EnterpriseServices.DataAccess.Entities; -using COA.EnterpriseServices.DataAccess.Helpers; +using COA.EnterpriseServices.Creditor; +using COA.EnterpriseServices.DataAccess; +using System; +using System.Runtime.CompilerServices; namespace COA.EnterpriseServices.Sandbox { @@ -8,46 +9,14 @@ namespace COA.EnterpriseServices.Sandbox { private static void Main(string[] args) { - ClientStuff(); - CreditorStuff(); - } + var creditorController = Dependencies.Container.GetInstance(); - private static void CreditorStuff() - { - var creditorHelper = Dependencies.Container.GetInstance(); + Console.WriteLine(creditorController.GetCreditorStatus(1)); - // get single creditor - var singleCreditor = creditorHelper.GetCreditor(1); + Console.WriteLine(creditorController.SetCreditorStatus(1, "Active")); - // search creditors - var searchedCreditors = creditorHelper.FindByName("Guy"); - // search active creditors - var activeCreditors = creditorHelper.FindByStatus("Active"); - - var newCreditor = new Creditor - { - ClientFirstName = "New", - ClientLastName = "Guy", - Status = "Active" - }; - - creditorHelper.AddCreditor(newCreditor); - } - - private static void ClientStuff() - { - var clientHelper = Dependencies.Container.GetInstance(); - - var newClient = new Client - { - FirstName = "Ryan", - LastName = "Peters", - Email = "ryan@binarydad.com", - Phone = 4102183673 - }; - - clientHelper.Add(newClient); + Console.ReadLine(); } } } diff --git a/COA.EnterpriseServices.sln b/COA.EnterpriseServices.sln index 039ea75..2b78fac 100644 --- a/COA.EnterpriseServices.sln +++ b/COA.EnterpriseServices.sln @@ -11,7 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COA.EnterpriseServices.Data EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COA.EnterpriseServices.Sandbox", "COA.EnterpriseServices.Sandbox\COA.EnterpriseServices.Sandbox.csproj", "{61BE21F9-8C5B-4C99-885A-E0B1E5BDCA79}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "COA.EnterpriseServices.Creditor", "COA.EnterpriseServices.Creditor\COA.EnterpriseServices.Creditor.csproj", "{FD33DD45-C0B9-45EE-B4C9-43CF1E6AB383}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COA.EnterpriseServices.Creditor", "COA.EnterpriseServices.Creditor\COA.EnterpriseServices.Creditor.csproj", "{FD33DD45-C0B9-45EE-B4C9-43CF1E6AB383}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution