added controller stub. before changing idataaccess to abstract class
This commit is contained in:
parent
1cd994b074
commit
ec52a8233a
@ -4,4 +4,8 @@
|
|||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\COA.EnterpriseServices.DataAccess\COA.EnterpriseServices.DataAccess.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
using System;
|
|
||||||
|
|
||||||
namespace COA.EnterpriseServices.Creditor
|
|
||||||
{
|
|
||||||
public class CreditorController
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SettlementController
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
27
COA.EnterpriseServices.Creditor/CreditorController.cs
Normal file
27
COA.EnterpriseServices.Creditor/CreditorController.cs
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,11 +1,12 @@
|
|||||||
using System;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
namespace COA.EnterpriseServices.DataAccess.EntityFramework
|
namespace COA.EnterpriseServices.DataAccess.EntityFramework
|
||||||
{
|
{
|
||||||
public class EntityDataAccess<T> : IDataAccess<T> where T : class, IRecord
|
public class EntityDataAccess<T> : IDataAccess<T> where T : class, IRecord, new()
|
||||||
{
|
{
|
||||||
public bool Add(T item)
|
public bool Add(T item)
|
||||||
{
|
{
|
||||||
@ -23,7 +24,23 @@ namespace COA.EnterpriseServices.DataAccess.EntityFramework
|
|||||||
{
|
{
|
||||||
using (var context = new QuickBaseContext())
|
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<T> update)
|
||||||
|
{
|
||||||
|
using (var context = new QuickBaseContext())
|
||||||
|
{
|
||||||
|
var item = context.Set<T>().FirstOrDefault(e => e.Id == id);
|
||||||
|
|
||||||
|
update(item);
|
||||||
|
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,11 @@ namespace COA.EnterpriseServices.DataAccess.QuickBase
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Update(int id, Action<T> update)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public ICollection<T> Get(Expression<Func<T, bool>> query)
|
public ICollection<T> Get(Expression<Func<T, bool>> query)
|
||||||
{
|
{
|
||||||
// we'll never get data from QB
|
// we'll never get data from QB
|
||||||
|
@ -41,5 +41,10 @@ namespace COA.EnterpriseServices.DataAccess.Helpers
|
|||||||
{
|
{
|
||||||
return creditorDataAccess.Invoke(d => d.Add(creditor));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ namespace COA.EnterpriseServices.DataAccess
|
|||||||
|
|
||||||
bool Update(T item);
|
bool Update(T item);
|
||||||
|
|
||||||
|
bool Update(int id, Action<T> update);
|
||||||
|
|
||||||
ICollection<T> Get(Expression<Func<T, bool>> query);
|
ICollection<T> Get(Expression<Func<T, bool>> query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\COA.EnterpriseServices.Creditor\COA.EnterpriseServices.Creditor.csproj" />
|
||||||
<ProjectReference Include="..\COA.EnterpriseServices.DataAccess.EntityFramework\COA.EnterpriseServices.DataAccess.EntityFramework.csproj" />
|
<ProjectReference Include="..\COA.EnterpriseServices.DataAccess.EntityFramework\COA.EnterpriseServices.DataAccess.EntityFramework.csproj" />
|
||||||
<ProjectReference Include="..\COA.EnterpriseServices.DataAccess.QuickBase\COA.EnterpriseServices.DataAccess.QuickBase.csproj" />
|
<ProjectReference Include="..\COA.EnterpriseServices.DataAccess.QuickBase\COA.EnterpriseServices.DataAccess.QuickBase.csproj" />
|
||||||
<ProjectReference Include="..\COA.EnterpriseServices.DataAccess\COA.EnterpriseServices.DataAccess.csproj" />
|
<ProjectReference Include="..\COA.EnterpriseServices.DataAccess\COA.EnterpriseServices.DataAccess.csproj" />
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using COA.EnterpriseServices.DataAccess;
|
using COA.EnterpriseServices.Creditor;
|
||||||
using COA.EnterpriseServices.DataAccess.Entities;
|
using COA.EnterpriseServices.DataAccess;
|
||||||
using COA.EnterpriseServices.DataAccess.Helpers;
|
using System;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace COA.EnterpriseServices.Sandbox
|
namespace COA.EnterpriseServices.Sandbox
|
||||||
{
|
{
|
||||||
@ -8,46 +9,14 @@ namespace COA.EnterpriseServices.Sandbox
|
|||||||
{
|
{
|
||||||
private static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
ClientStuff();
|
var creditorController = Dependencies.Container.GetInstance<CreditorController>();
|
||||||
CreditorStuff();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CreditorStuff()
|
Console.WriteLine(creditorController.GetCreditorStatus(1));
|
||||||
{
|
|
||||||
var creditorHelper = Dependencies.Container.GetInstance<CreditorHelper>();
|
|
||||||
|
|
||||||
// get single creditor
|
Console.WriteLine(creditorController.SetCreditorStatus(1, "Active"));
|
||||||
var singleCreditor = creditorHelper.GetCreditor(1);
|
|
||||||
|
|
||||||
// search creditors
|
|
||||||
var searchedCreditors = creditorHelper.FindByName("Guy");
|
|
||||||
|
|
||||||
// search active creditors
|
Console.ReadLine();
|
||||||
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<ClientHelper>();
|
|
||||||
|
|
||||||
var newClient = new Client
|
|
||||||
{
|
|
||||||
FirstName = "Ryan",
|
|
||||||
LastName = "Peters",
|
|
||||||
Email = "ryan@binarydad.com",
|
|
||||||
Phone = 4102183673
|
|
||||||
};
|
|
||||||
|
|
||||||
clientHelper.Add(newClient);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COA.EnterpriseServices.Data
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COA.EnterpriseServices.Sandbox", "COA.EnterpriseServices.Sandbox\COA.EnterpriseServices.Sandbox.csproj", "{61BE21F9-8C5B-4C99-885A-E0B1E5BDCA79}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "COA.EnterpriseServices.Sandbox", "COA.EnterpriseServices.Sandbox\COA.EnterpriseServices.Sandbox.csproj", "{61BE21F9-8C5B-4C99-885A-E0B1E5BDCA79}"
|
||||||
EndProject
|
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
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Loading…
x
Reference in New Issue
Block a user