working with QB field mapping registry
This commit is contained in:
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));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user