working with QB field mapping registry
This commit is contained in:
parent
4ed44dc913
commit
5151da0724
@ -32,15 +32,9 @@ namespace COA.EnterpriseServices.DataAccess.EntityFramework
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICollection<T> Get(int id)
|
public T Get(int id)
|
||||||
{
|
{
|
||||||
using (var context = new QuickBaseContext())
|
return Get(r => r.Id == id).FirstOrDefault();
|
||||||
{
|
|
||||||
return context
|
|
||||||
.Set<T>()
|
|
||||||
.Where(r => r.Id == id)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICollection<T> Get(Expression<Func<T, bool>> query)
|
public ICollection<T> Get(Expression<Func<T, bool>> query)
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using COA.EnterpriseServices.DataAccess.EntityFramework;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(QuickBaseContext))]
|
||||||
|
[Migration("20201014110259_updated-creditor")]
|
||||||
|
partial class updatedcreditor
|
||||||
|
{
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "3.1.9")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
modelBuilder.Entity("COA.EnterpriseServices.DataAccess.Entities.Creditor", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int")
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
b.Property<string>("ClientFirstName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("ClientLastName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Creditors");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations
|
||||||
|
{
|
||||||
|
public partial class updatedcreditor : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "ClientFirstName",
|
||||||
|
table: "Creditors",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "ClientLastName",
|
||||||
|
table: "Creditors",
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "ClientFirstName",
|
||||||
|
table: "Creditors");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "ClientLastName",
|
||||||
|
table: "Creditors");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using COA.EnterpriseServices.DataAccess.EntityFramework;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(QuickBaseContext))]
|
||||||
|
[Migration("20201014122348_added-create-modified-dates")]
|
||||||
|
partial class addedcreatemodifieddates
|
||||||
|
{
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "3.1.9")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
modelBuilder.Entity("COA.EnterpriseServices.DataAccess.Entities.Creditor", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int")
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
b.Property<string>("ClientFirstName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("ClientLastName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Created")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Modified")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Creditors");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations
|
||||||
|
{
|
||||||
|
public partial class addedcreatemodifieddates : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<DateTime>(
|
||||||
|
name: "Created",
|
||||||
|
table: "Creditors",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<DateTime>(
|
||||||
|
name: "Modified",
|
||||||
|
table: "Creditors",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Created",
|
||||||
|
table: "Creditors");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Modified",
|
||||||
|
table: "Creditors");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using COA.EnterpriseServices.DataAccess.EntityFramework;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(QuickBaseContext))]
|
||||||
|
[Migration("20201014122738_settlement-attempt")]
|
||||||
|
partial class settlementattempt
|
||||||
|
{
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "3.1.9")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
modelBuilder.Entity("COA.EnterpriseServices.DataAccess.Entities.Creditor", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int")
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
b.Property<string>("ClientFirstName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("ClientLastName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Created")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Modified")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Creditors");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("COA.EnterpriseServices.DataAccess.Entities.SettlementAttempt", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int")
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
b.Property<DateTime>("Created")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Modified")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("SettlementAttempts");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations
|
||||||
|
{
|
||||||
|
public partial class settlementattempt : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "SettlementAttempts",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
Created = table.Column<DateTime>(nullable: false),
|
||||||
|
Modified = table.Column<DateTime>(nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_SettlementAttempts", x => x.Id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "SettlementAttempts");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using COA.EnterpriseServices.DataAccess.EntityFramework;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(QuickBaseContext))]
|
||||||
|
[Migration("20201014123332_added-creditor-status")]
|
||||||
|
partial class addedcreditorstatus
|
||||||
|
{
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "3.1.9")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
modelBuilder.Entity("COA.EnterpriseServices.DataAccess.Entities.Creditor", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int")
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
b.Property<string>("ClientFirstName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("ClientLastName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Created")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Modified")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<string>("Status")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Creditors");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("COA.EnterpriseServices.DataAccess.Entities.SettlementAttempt", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int")
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
b.Property<DateTime>("Created")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Modified")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("SettlementAttempts");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations
|
||||||
|
{
|
||||||
|
public partial class addedcreditorstatus : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<string>(
|
||||||
|
name: "Status",
|
||||||
|
table: "Creditors",
|
||||||
|
nullable: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "Status",
|
||||||
|
table: "Creditors");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
using COA.EnterpriseServices.DataAccess.EntityFramework;
|
using COA.EnterpriseServices.DataAccess.EntityFramework;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
@ -18,17 +19,50 @@ namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations
|
|||||||
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
modelBuilder.Entity("COA.EnterpriseServices.DataAccess.EntityFramework.Entities.Creditor", b =>
|
modelBuilder.Entity("COA.EnterpriseServices.DataAccess.Entities.Creditor", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
.ValueGeneratedOnAdd()
|
.ValueGeneratedOnAdd()
|
||||||
.HasColumnType("int")
|
.HasColumnType("int")
|
||||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
b.Property<string>("ClientFirstName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("ClientLastName")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Created")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Modified")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<string>("Status")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.ToTable("Creditors");
|
b.ToTable("Creditors");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("COA.EnterpriseServices.DataAccess.Entities.SettlementAttempt", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int")
|
||||||
|
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||||
|
|
||||||
|
b.Property<DateTime>("Created")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Modified")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("SettlementAttempts");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
using COA.EnterpriseServices.DataAccess.EntityFramework.Entities;
|
using COA.EnterpriseServices.DataAccess.Entities;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace COA.EnterpriseServices.DataAccess.EntityFramework
|
namespace COA.EnterpriseServices.DataAccess.EntityFramework
|
||||||
{
|
{
|
||||||
@ -16,5 +13,6 @@ namespace COA.EnterpriseServices.DataAccess.EntityFramework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DbSet<Creditor> Creditors { get; set; }
|
public DbSet<Creditor> Creditors { get; set; }
|
||||||
|
public DbSet<SettlementAttempt> SettlementAttempts { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
9
COA.EnterpriseServices.DataAccess.QuickBase/FieldMap.cs
Normal file
9
COA.EnterpriseServices.DataAccess.QuickBase/FieldMap.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace COA.EnterpriseServices.DataAccess.QuickBase
|
||||||
|
{
|
||||||
|
internal class FieldMap
|
||||||
|
{
|
||||||
|
internal string DeclaringTypeName { get; set; }
|
||||||
|
internal string PropertyName { get; set; }
|
||||||
|
internal int FieldId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
using COA.EnterpriseServices.DataAccess.Entities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace COA.EnterpriseServices.DataAccess.QuickBase
|
||||||
|
{
|
||||||
|
internal static class FieldMapRegistry
|
||||||
|
{
|
||||||
|
private static readonly ICollection<FieldMap> registry = new List<FieldMap>();
|
||||||
|
|
||||||
|
static FieldMapRegistry()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void AddFieldMap<TEntity>(Expression<Func<TEntity, object>> property, int fieldId)
|
||||||
|
{
|
||||||
|
if (property.Body is MemberExpression memberExpression)
|
||||||
|
{
|
||||||
|
registry.Add(new FieldMap
|
||||||
|
{
|
||||||
|
DeclaringTypeName = memberExpression.Member.DeclaringType.FullName,
|
||||||
|
PropertyName = memberExpression.Member.Name,
|
||||||
|
FieldId = fieldId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else if (property.Body is UnaryExpression unaryExpression && unaryExpression.Operand is MemberExpression unaryMemberExpression)
|
||||||
|
{
|
||||||
|
registry.Add(new FieldMap
|
||||||
|
{
|
||||||
|
DeclaringTypeName = unaryMemberExpression.Member.DeclaringType.FullName,
|
||||||
|
PropertyName = unaryMemberExpression.Member.Name,
|
||||||
|
FieldId = fieldId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static int? GetFieldId(PropertyInfo info)
|
||||||
|
{
|
||||||
|
var map = registry.FirstOrDefault(m => m.DeclaringTypeName == info.DeclaringType.FullName && m.PropertyName == info.Name);
|
||||||
|
|
||||||
|
return map != null ? map.FieldId : default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,10 +4,14 @@ using System.Linq.Expressions;
|
|||||||
|
|
||||||
namespace COA.EnterpriseServices.DataAccess.QuickBase
|
namespace COA.EnterpriseServices.DataAccess.QuickBase
|
||||||
{
|
{
|
||||||
public class QuickBaseDataAccess<T> : IDataAccess<T> where T : class, IRecord
|
public class QuickBaseDataAccess<T> : IDataAccess<T> where T : class, IRecord, new()
|
||||||
{
|
{
|
||||||
public bool Add(T item)
|
public bool Add(T item)
|
||||||
{
|
{
|
||||||
|
var fieldData = GetFieldData(item);
|
||||||
|
|
||||||
|
// use fieldData to create mapped data to push to quickbase API
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,14 +20,32 @@ namespace COA.EnterpriseServices.DataAccess.QuickBase
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICollection<T> Get(int id)
|
public T Get(int id)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
// we'll never get data from QB
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICollection<T> Get(Expression<Func<T, bool>> query)
|
public ICollection<T> Get(Expression<Func<T, bool>> query)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
// we'll never get data from QB
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<KeyValuePair<int, object>> GetFieldData(T item)
|
||||||
|
{
|
||||||
|
var properties = item.GetType().GetProperties();
|
||||||
|
|
||||||
|
foreach (var property in properties)
|
||||||
|
{
|
||||||
|
var fieldId = FieldMapRegistry.GetFieldId(property);
|
||||||
|
var value = property.GetValue(item);
|
||||||
|
|
||||||
|
if (fieldId != null)
|
||||||
|
{
|
||||||
|
yield return new KeyValuePair<int, object>(fieldId.Value, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,4 +4,8 @@
|
|||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="StructureMap" Version="4.7.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,11 +2,14 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace COA.EnterpriseServices.DataAccess.EntityFramework.Entities
|
namespace COA.EnterpriseServices.DataAccess.Entities
|
||||||
{
|
{
|
||||||
public class Creditor : IRecord
|
public class Creditor : IRecord
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
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 ClientFirstName { get; set; }
|
||||||
public string ClientLastName { 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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
namespace COA.EnterpriseServices.DataAccess
|
namespace COA.EnterpriseServices.DataAccess
|
||||||
{
|
{
|
||||||
@ -12,60 +10,8 @@ namespace COA.EnterpriseServices.DataAccess
|
|||||||
|
|
||||||
bool Update(T item);
|
bool Update(T item);
|
||||||
|
|
||||||
ICollection<T> Get(int id);
|
T Get(int id);
|
||||||
|
|
||||||
ICollection<T> Get(Expression<Func<T, bool>> query);
|
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
|
public interface IRecord
|
||||||
{
|
{
|
||||||
int Id { get; set; }
|
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; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,10 +5,6 @@
|
|||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="structuremap" Version="4.7.1" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<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" />
|
||||||
|
@ -1,40 +1,33 @@
|
|||||||
using COA.EnterpriseServices.DataAccess;
|
using COA.EnterpriseServices.DataAccess.Entities;
|
||||||
using COA.EnterpriseServices.DataAccess.EntityFramework;
|
using COA.EnterpriseServices.DataAccess.Helpers;
|
||||||
using COA.EnterpriseServices.DataAccess.EntityFramework.Entities;
|
|
||||||
using COA.EnterpriseServices.DataAccess.QuickBase;
|
|
||||||
using StructureMap;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace COA.EnterpriseServices.Sandbox
|
namespace COA.EnterpriseServices.Sandbox
|
||||||
{
|
{
|
||||||
class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
private static void Main(string[] args)
|
||||||
{
|
{
|
||||||
var container = CreateContainer();
|
var creditorHelper = new CreditorHelper();
|
||||||
|
|
||||||
var creditorDataAccess = container.GetAllInstances<IDataAccess<Creditor>>();
|
// get single creditor
|
||||||
|
var singleCreditor = creditorHelper.GetCreditor(1);
|
||||||
|
|
||||||
|
// search creditors
|
||||||
|
var searchedCreditors = creditorHelper.FindCreditorsByName("Guy");
|
||||||
|
|
||||||
|
// search active creditors
|
||||||
|
var activeCreditors = creditorHelper.FindByStatus("Active");
|
||||||
|
|
||||||
|
var newCreditor = new Creditor
|
||||||
|
{
|
||||||
|
ClientFirstName = "New",
|
||||||
|
ClientLastName = "Guy",
|
||||||
|
Status = "Active"
|
||||||
|
};
|
||||||
|
|
||||||
|
creditorHelper.AddCreditor(newCreditor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IContainer CreateContainer()
|
|
||||||
{
|
|
||||||
return new Container(c =>
|
|
||||||
{
|
|
||||||
//c.Scan(s =>
|
|
||||||
//{
|
|
||||||
// s.WithDefaultConventions();
|
|
||||||
// s.AssembliesFromApplicationBaseDirectory();
|
|
||||||
//});
|
|
||||||
|
|
||||||
// when saving to QuickBase is needed (as well as SQL)
|
|
||||||
c.For<IDataAccess<Creditor>>().Add<EntityDataAccess<Creditor>>();
|
|
||||||
c.For<IDataAccess<Creditor>>().Add<QuickBaseDataAccess<Creditor>>();
|
|
||||||
|
|
||||||
// when only SQL is needed
|
|
||||||
//c.For<ISettlementAttemptDataAccess>().Singleton().Use<EfSettlementAttemptDataAccess>();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user