progress. in the middle of reworking QB api binding to use fluent api
This commit is contained in:
parent
be0bc54bb9
commit
9ce87d4ecb
@ -6,6 +6,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="COA.Common" Version="20.10.13.1-alpha" />
|
||||
<PackageReference Include="DataObjects" Version="20.10.2.3-alpha" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="COA.Common" Version="20.10.13.1-alpha" />
|
||||
<PackageReference Include="COA.PartnerApis.QuickBase" Version="20.9.30.2-alpha" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -6,4 +6,9 @@
|
||||
internal string PropertyName { get; set; }
|
||||
internal int FieldId { get; set; }
|
||||
}
|
||||
|
||||
internal class TableMap<TEntity, TEnumFieldMap>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
using COA.EnterpriseServices.DataAccess.Entities;
|
||||
using COA.Common;
|
||||
using COA.EnterpriseServices.DataAccess.Entities;
|
||||
using COA.PartnerApis.QuickBase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -7,59 +9,104 @@ using System.Reflection;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess.QuickBase
|
||||
{
|
||||
internal class QuickBaseRecordContext
|
||||
{
|
||||
internal string Table { get; set; }
|
||||
internal IDictionary<int, object> FieldIds { get; set; } = new Dictionary<int, object>();
|
||||
|
||||
}
|
||||
|
||||
internal static class FieldMapRegistry
|
||||
{
|
||||
private static readonly ICollection<FieldMap> registry = new List<FieldMap>();
|
||||
private static readonly ICollection<FieldMap> fieldRegistry = new List<FieldMap>();
|
||||
private static readonly IDictionary<Type, string> tableRegistry = new Dictionary<Type, string>();
|
||||
|
||||
static FieldMapRegistry()
|
||||
{
|
||||
// Map to QB field IDs. Obviously we will use actual IDs
|
||||
|
||||
AddFieldMap<Creditor>(c => c.Id, 1);
|
||||
AddFieldMap<Creditor>(c => c.Created, 2);
|
||||
AddFieldMap<Creditor>(c => c.Modified, 3);
|
||||
AddFieldMap<Creditor>(c => c.Status, 10);
|
||||
AddFieldMap<Creditor>(c => c.ClientFirstName, 20);
|
||||
AddFieldMap<Creditor>(c => c.ClientLastName, 21);
|
||||
AddFieldMap<Creditor>(c => c.CurrentCreditorProfileId, 90);
|
||||
AddFieldMap<Creditor>(c => c.OriginalCreditorProfileId, 91);
|
||||
AddTable<Creditor, CreditorsFieldMap>()
|
||||
.WithProperty(c => c.Id, CreditorsFieldMap.RecordId)
|
||||
.WithProperty(c => c.Modified, CreditorsFieldMap.DateModified);
|
||||
|
||||
AddFieldMap<Entities.Client>(c => c.Id, 1);
|
||||
AddFieldMap<Entities.Client>(c => c.Created, 2);
|
||||
AddFieldMap<Entities.Client>(c => c.Modified, 3);
|
||||
AddFieldMap<Entities.Client>(c => c.Email, 10);
|
||||
AddFieldMap<Entities.Client>(c => c.Phone, 11);
|
||||
AddFieldMap<Entities.Client>(c => c.FirstName, 20);
|
||||
AddFieldMap<Entities.Client>(c => c.LastName, 21);
|
||||
AddFieldMap<Creditor>(c => c.Id, CreditorsFieldMap.RecordId);
|
||||
AddFieldMap<Creditor>(c => c.Created, CreditorsFieldMap.DateCreated);
|
||||
AddFieldMap<Creditor>(c => c.Modified, CreditorsFieldMap.DateModified);
|
||||
AddFieldMap<Creditor>(c => c.Status, CreditorsFieldMap.CreditorStatus);
|
||||
AddFieldMap<Creditor>(c => c.ClientFirstName, CreditorsFieldMap.ClientFirstName);
|
||||
AddFieldMap<Creditor>(c => c.ClientLastName, CreditorsFieldMap.ClientLastName);
|
||||
AddFieldMap<Creditor>(c => c.CurrentCreditorProfileId, CreditorsFieldMap.RelatedCurrentCreditorPrimary);
|
||||
AddFieldMap<Creditor>(c => c.OriginalCreditorProfileId, CreditorsFieldMap.RelatedOriginalCreditor);
|
||||
AddFieldMap<Creditor>(c => c.AccountNumber, CreditorsFieldMap.AccountNum);
|
||||
|
||||
//AddFieldMap<Entities.Client>(c => c.Id, 1);
|
||||
//AddFieldMap<Entities.Client>(c => c.Created, 2);
|
||||
//AddFieldMap<Entities.Client>(c => c.Modified, 3);
|
||||
//AddFieldMap<Entities.Client>(c => c.Email, 10);
|
||||
//AddFieldMap<Entities.Client>(c => c.Phone, 11);
|
||||
//AddFieldMap<Entities.Client>(c => c.FirstName, 20);
|
||||
//AddFieldMap<Entities.Client>(c => c.LastName, 21);
|
||||
}
|
||||
|
||||
internal static void AddFieldMap<TEntity>(Expression<Func<TEntity, object>> property, int fieldId)
|
||||
public static TableMap<TEntity, TEnumFieldMap> AddTable<TEntity, TEnumFieldMap>()
|
||||
{
|
||||
tableRegistry.Add(typeof(TEntity), "asdas");
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static TableMap<TEntity, TEnumFieldMap> WithProperty<TEntity, TEnumFieldMap>(this TableMap<TEntity, TEnumFieldMap> table, Expression<Func<TEntity, object>> property, Enum field)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
internal static void AddFieldMap<TEntity>(Expression<Func<TEntity, object>> property, Enum field)
|
||||
{
|
||||
if (property.Body is MemberExpression memberExpression)
|
||||
{
|
||||
registry.Add(new FieldMap
|
||||
fieldRegistry.Add(new FieldMap
|
||||
{
|
||||
DeclaringTypeName = memberExpression.Member.DeclaringType.FullName,
|
||||
PropertyName = memberExpression.Member.Name,
|
||||
FieldId = fieldId
|
||||
FieldId = field.To<int>()
|
||||
});
|
||||
}
|
||||
else if (property.Body is UnaryExpression unaryExpression && unaryExpression.Operand is MemberExpression unaryMemberExpression)
|
||||
{
|
||||
registry.Add(new FieldMap
|
||||
fieldRegistry.Add(new FieldMap
|
||||
{
|
||||
DeclaringTypeName = unaryMemberExpression.Member.DeclaringType.FullName,
|
||||
PropertyName = unaryMemberExpression.Member.Name,
|
||||
FieldId = fieldId
|
||||
//FieldId = fieldId,
|
||||
FieldId = field.To<int>()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
internal static int? GetFieldId(PropertyInfo info)
|
||||
{
|
||||
var map = registry.FirstOrDefault(m => m.DeclaringTypeName == info.DeclaringType.FullName && m.PropertyName == info.Name);
|
||||
var map = fieldRegistry.FirstOrDefault(m => m.DeclaringTypeName == info.DeclaringType.FullName && m.PropertyName == info.Name);
|
||||
|
||||
return map != null ? map.FieldId : default;
|
||||
}
|
||||
|
||||
internal static QuickBaseRecordContext GetTableContext(object item)
|
||||
{
|
||||
var context = new QuickBaseRecordContext();
|
||||
var properties = item.GetType().GetProperties();
|
||||
|
||||
foreach (var property in properties)
|
||||
{
|
||||
var fieldId = FieldMapRegistry.GetFieldId(property);
|
||||
var value = property.GetValue(item);
|
||||
|
||||
if (fieldId != null)
|
||||
{
|
||||
context.FieldIds.Add(new KeyValuePair<int, object>(fieldId.Value, value));
|
||||
}
|
||||
}
|
||||
|
||||
return context;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using COA.PartnerApis.QuickBase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
@ -6,9 +7,18 @@ namespace COA.EnterpriseServices.DataAccess.QuickBase
|
||||
{
|
||||
public class QuickBaseDataAccess<T> : IDataAccess<T> where T : class, IRecord, new()
|
||||
{
|
||||
private readonly QuickBaseApiClient client;
|
||||
|
||||
public QuickBaseDataAccess(QuickBaseApiClient client)
|
||||
{
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public bool Add(T item)
|
||||
{
|
||||
var fieldData = GetFieldData(item);
|
||||
var fieldData = FieldMapRegistry.GetTableContext(item);
|
||||
|
||||
//client.AddRecord()
|
||||
|
||||
// use fieldData to create mapped data to push to quickbase API
|
||||
|
||||
@ -17,8 +27,6 @@ namespace COA.EnterpriseServices.DataAccess.QuickBase
|
||||
|
||||
public bool Update(T item)
|
||||
{
|
||||
var fieldData = GetFieldData(item);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="10.0.0" />
|
||||
<PackageReference Include="COA.Common" Version="20.10.13.1-alpha" />
|
||||
<PackageReference Include="DataObjects" Version="20.10.2.3-alpha" />
|
||||
<PackageReference Include="StructureMap" Version="4.7.1" />
|
||||
</ItemGroup>
|
||||
|
@ -7,12 +7,11 @@ namespace COA.EnterpriseServices.DataAccess
|
||||
{
|
||||
public static IMapper GetMapper()
|
||||
{
|
||||
var cfg = new MapperConfigurationExpression();
|
||||
cfg.AddProfile<MappingProfile>();
|
||||
var configuration = new MapperConfigurationExpression();
|
||||
|
||||
configuration.AddProfile<MappingProfile>();
|
||||
|
||||
//Mapper.Initialize(cfg);
|
||||
// or
|
||||
var mapperConfig = new MapperConfiguration(cfg);
|
||||
var mapperConfig = new MapperConfiguration(configuration);
|
||||
|
||||
return new Mapper(mapperConfig);
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ namespace COA.EnterpriseServices.Sandbox
|
||||
{
|
||||
var creditorController = Dependencies.Container.GetInstance<CreditorController>();
|
||||
|
||||
Console.WriteLine(creditorController.GetCreditorStatus(1));
|
||||
//Console.WriteLine(creditorController.SetCreditorStatus(1, "Active"));
|
||||
//Console.WriteLine(creditorController.GetCreditorStatus(1));
|
||||
Console.WriteLine(creditorController.SetCreditorStatus(1, "Active"));
|
||||
|
||||
//creditorController.AddOfferResponse(new OfferResponse
|
||||
//{
|
||||
|
Loading…
x
Reference in New Issue
Block a user