working with QB field mapping registry
This commit is contained in:
@ -4,4 +4,8 @@
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="StructureMap" Version="4.7.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,15 +0,0 @@
|
||||
using COA.EnterpriseServices.DataAccess.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess
|
||||
{
|
||||
public class CreditorHelper
|
||||
{
|
||||
public Creditor GetCreditor(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
23
COA.EnterpriseServices.DataAccess/Dependencies.cs
Normal file
23
COA.EnterpriseServices.DataAccess/Dependencies.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using StructureMap;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess
|
||||
{
|
||||
public static class Dependencies
|
||||
{
|
||||
public static IContainer Container { get; }
|
||||
|
||||
static Dependencies()
|
||||
{
|
||||
Container = new Container(c =>
|
||||
{
|
||||
c.Scan(s =>
|
||||
{
|
||||
s.AddAllTypesOf(typeof(IDataAccess<>));
|
||||
|
||||
s.WithDefaultConventions();
|
||||
s.AssembliesFromApplicationBaseDirectory();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
16
COA.EnterpriseServices.DataAccess/Entities/Creditor.cs
Normal file
16
COA.EnterpriseServices.DataAccess/Entities/Creditor.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess.Entities
|
||||
{
|
||||
public class Creditor : IRecord
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
public string Status { get; set; }
|
||||
public string ClientFirstName { get; set; }
|
||||
public string ClientLastName { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess.Entities
|
||||
{
|
||||
public class SettlementAttempt : IRecord
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
}
|
||||
}
|
32
COA.EnterpriseServices.DataAccess/Helpers/BaseHelper.cs
Normal file
32
COA.EnterpriseServices.DataAccess/Helpers/BaseHelper.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess.Helpers
|
||||
{
|
||||
public class BaseHelper<T> where T : class, IRecord
|
||||
{
|
||||
protected readonly ICollection<IDataAccess<T>> dataAccessInstances;
|
||||
|
||||
public BaseHelper()
|
||||
{
|
||||
dataAccessInstances = Dependencies.Container
|
||||
.GetAllInstances<IDataAccess<T>>()
|
||||
.OrderBy(i => i.GetType().Name.StartsWith("QuickBase", StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
protected TResult Invoke<TResult>(Func<IDataAccess<T>, TResult> func)
|
||||
{
|
||||
var results = new List<TResult>();
|
||||
|
||||
foreach (var dataAccessInstance in dataAccessInstances)
|
||||
{
|
||||
results.Add(func(dataAccessInstance));
|
||||
}
|
||||
|
||||
// if the "EF" version invokes first, return that value
|
||||
return results.FirstOrDefault(r => r != null && !r.Equals(default(TResult)));
|
||||
}
|
||||
}
|
||||
}
|
29
COA.EnterpriseServices.DataAccess/Helpers/CreditorHelper.cs
Normal file
29
COA.EnterpriseServices.DataAccess/Helpers/CreditorHelper.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using COA.EnterpriseServices.DataAccess.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess.Helpers
|
||||
{
|
||||
public class CreditorHelper : BaseHelper<Creditor>
|
||||
{
|
||||
public Creditor GetCreditor(int id)
|
||||
{
|
||||
return Invoke(d => d.Get(id));
|
||||
}
|
||||
|
||||
public ICollection<Creditor> FindCreditorsByName(string name)
|
||||
{
|
||||
return Invoke(d => d.Get(c => c.ClientFirstName.Contains(name) || c.ClientLastName.Contains(name)));
|
||||
}
|
||||
|
||||
public ICollection<Creditor> FindByStatus(string status)
|
||||
{
|
||||
return Invoke(d => d.Get(c => c.Status == status));
|
||||
}
|
||||
|
||||
public bool AddCreditor(Creditor creditor)
|
||||
{
|
||||
return Invoke(d => d.Add(creditor));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess
|
||||
{
|
||||
@ -12,60 +10,8 @@ namespace COA.EnterpriseServices.DataAccess
|
||||
|
||||
bool Update(T item);
|
||||
|
||||
ICollection<T> Get(int id);
|
||||
T Get(int id);
|
||||
|
||||
ICollection<T> Get(Expression<Func<T, bool>> query);
|
||||
}
|
||||
|
||||
//public class AggregateDataAccess<T> : IDataAccess<T> where T : class, IRecord
|
||||
//{
|
||||
// private static ICollection<Type> dataAccessTypes;
|
||||
|
||||
// static AggregateDataAccess() => LoadInstances();
|
||||
|
||||
// /// <summary>
|
||||
// /// Invokes a method for all instances of <typeparamref name="T"/>
|
||||
// /// </summary>
|
||||
// /// <typeparam name="TResult"></typeparam>
|
||||
// /// <param name="func"></param>
|
||||
// /// <returns></returns>
|
||||
// protected TResult Invoke<TResult>(Func<IDataAccess<T>, TResult> func)
|
||||
// {
|
||||
// var results = new List<TResult>();
|
||||
|
||||
// foreach (var dataAccessType in dataAccessTypes)
|
||||
// {
|
||||
// var instance = Activator.CreateInstance(dataAccessType) as IDataAccess<T>;
|
||||
|
||||
// results.Add(func(instance));
|
||||
// }
|
||||
|
||||
// // if the "EF" version invokes first, return that value
|
||||
// return results.FirstOrDefault(r => !r.Equals(default(T)));
|
||||
// }
|
||||
|
||||
// private static void LoadInstances()
|
||||
// {
|
||||
// if (dataAccessTypes == null)
|
||||
// {
|
||||
// var type = typeof(IDataAccess<T>);
|
||||
// var aggregateType = typeof(AggregateDataAccess<>);
|
||||
|
||||
// // load all types except for 1) the interface itself, 2) any interface, and 3) is not implementing AggregateDataAccess<T>
|
||||
// // NOTE: the "EF" version will load first, allowing for the "QuickBase" version to run last, in a separate thread if desired
|
||||
// dataAccessTypes = AppDomain.CurrentDomain
|
||||
// .GetAssemblies()
|
||||
// .Where(a => a.FullName.StartsWith("COA.EnterpriseServices.DataAccess"))
|
||||
// .SelectMany(a => a.ExportedTypes)
|
||||
// //.Where(t => type.IsAssignableFrom(t)/* && !t.IsInterface && !aggregateType.IsAssignableFrom(t)*/)
|
||||
// //.OrderBy(t => t.Name.StartsWith("QuickBase", StringComparison.OrdinalIgnoreCase))
|
||||
// .ToList();
|
||||
// }
|
||||
// }
|
||||
|
||||
// public bool Add(T item) => Invoke(d => d.Add(item));
|
||||
// public bool Update(T item) => Invoke(d => d.Update(item));
|
||||
// public ICollection<T> Get(int id) => Invoke(d => d.Get(id));
|
||||
// public ICollection<T> Get(Expression<Func<T, bool>> query) => Invoke(d => d.Get(query));
|
||||
//}
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
namespace COA.EnterpriseServices.DataAccess
|
||||
using System;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess
|
||||
{
|
||||
public interface IRecord
|
||||
{
|
||||
int Id { get; set; }
|
||||
DateTime Created { get; set; }
|
||||
DateTime Modified { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess.Models
|
||||
{
|
||||
public class Creditor : IRecord
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user