add client. move common add/get helpers to Base helper
This commit is contained in:
@ -7,12 +7,41 @@ namespace COA.EnterpriseServices.DataAccess
|
||||
{
|
||||
public static class DataAccessManager
|
||||
{
|
||||
private static readonly IDictionary<Type, ;
|
||||
private static readonly IDictionary<string, string[]> activeDataAccess = new Dictionary<string, string[]>
|
||||
{
|
||||
#region Creditor
|
||||
|
||||
["COA.EnterpriseServices.DataAccess.Entities.Creditor"] = new[]
|
||||
{
|
||||
"COA.EnterpriseServices.DataAccess.QuickBase.QuickBaseDataAccess",
|
||||
"COA.EnterpriseServices.DataAccess.EntityFramework.EntityDataAccess"
|
||||
},
|
||||
|
||||
#endregion
|
||||
|
||||
#region Client
|
||||
|
||||
["COA.EnterpriseServices.DataAccess.Entities.Client"] = new[]
|
||||
{
|
||||
"COA.EnterpriseServices.DataAccess.QuickBase.QuickBaseDataAccess",
|
||||
"COA.EnterpriseServices.DataAccess.EntityFramework.EntityDataAccess"
|
||||
}
|
||||
|
||||
#endregion
|
||||
};
|
||||
|
||||
public static ICollection<IDataAccess<T>> GetDataAccess<T>() where T : class, IRecord
|
||||
{
|
||||
var type = typeof(T);
|
||||
|
||||
return Dependencies.Container
|
||||
.GetAllInstances<IDataAccess<T>>()
|
||||
.Where(i =>
|
||||
{
|
||||
var dataAccessType = i.GetType().FullName;
|
||||
|
||||
return activeDataAccess.ContainsKey(type.FullName) && activeDataAccess[type.FullName].Any(a => dataAccessType.StartsWith(a));
|
||||
})
|
||||
.OrderBy(i => i.GetType().Name.StartsWith("QuickBase", StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
}
|
||||
|
19
COA.EnterpriseServices.DataAccess/Entities/Client.cs
Normal file
19
COA.EnterpriseServices.DataAccess/Entities/Client.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess.Entities
|
||||
{
|
||||
public class Client : IRecord
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
public string FirstName { get; set; }
|
||||
public string LastName { get; set; }
|
||||
public string Email { get; set; }
|
||||
public long Phone { get; set; }
|
||||
public string Address { get; set; }
|
||||
public string City { get; set; }
|
||||
public string State { get; set; }
|
||||
public string Zip { get; set; }
|
||||
}
|
||||
}
|
@ -25,5 +25,15 @@ namespace COA.EnterpriseServices.DataAccess.Helpers
|
||||
// if the "EF" version invokes first, return that value
|
||||
return results.FirstOrDefault(r => r != null && !r.Equals(default(TResult)));
|
||||
}
|
||||
|
||||
public virtual T Get(int id)
|
||||
{
|
||||
return Invoke(d => d.Get(id));
|
||||
}
|
||||
|
||||
public virtual bool Add(T item)
|
||||
{
|
||||
return Invoke(d => d.Add(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
COA.EnterpriseServices.DataAccess/Helpers/ClientHelper.cs
Normal file
13
COA.EnterpriseServices.DataAccess/Helpers/ClientHelper.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using COA.EnterpriseServices.DataAccess.Entities;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess.Helpers
|
||||
{
|
||||
public class ClientHelper : BaseHelper<Client>
|
||||
{
|
||||
public ICollection<Client> FindByEmail(string email)
|
||||
{
|
||||
return Invoke(d => d.Get(c => c.Email.Equals(email)));
|
||||
}
|
||||
}
|
||||
}
|
@ -6,12 +6,7 @@ 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)
|
||||
public ICollection<Creditor> FindByName(string name)
|
||||
{
|
||||
return Invoke(d => d.Get(c => c.ClientFirstName.Contains(name) || c.ClientLastName.Contains(name)));
|
||||
}
|
||||
@ -20,10 +15,5 @@ namespace COA.EnterpriseServices.DataAccess.Helpers
|
||||
{
|
||||
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