add client. move common add/get helpers to Base helper
This commit is contained in:
parent
3a6ca75196
commit
2a03bc6bc8
71
COA.EnterpriseServices.DataAccess.EntityFramework/Migrations/20201014142201_add-client.Designer.cs
generated
Normal file
71
COA.EnterpriseServices.DataAccess.EntityFramework/Migrations/20201014142201_add-client.Designer.cs
generated
Normal file
@ -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("20201014142201_add-client")]
|
||||
partial class addclient
|
||||
{
|
||||
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,17 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations
|
||||
{
|
||||
public partial class addclient : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
113
COA.EnterpriseServices.DataAccess.EntityFramework/Migrations/20201014142507_add-client-dbset.Designer.cs
generated
Normal file
113
COA.EnterpriseServices.DataAccess.EntityFramework/Migrations/20201014142507_add-client-dbset.Designer.cs
generated
Normal file
@ -0,0 +1,113 @@
|
||||
// <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("20201014142507_add-client-dbset")]
|
||||
partial class addclientdbset
|
||||
{
|
||||
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.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<string>("Address")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("City")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("Modified")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<long>("Phone")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("State")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Zip")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
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,39 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations
|
||||
{
|
||||
public partial class addclientdbset : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Clients",
|
||||
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),
|
||||
FirstName = table.Column<string>(nullable: true),
|
||||
LastName = table.Column<string>(nullable: true),
|
||||
Email = table.Column<string>(nullable: true),
|
||||
Phone = table.Column<long>(nullable: false),
|
||||
Address = table.Column<string>(nullable: true),
|
||||
City = table.Column<string>(nullable: true),
|
||||
State = table.Column<string>(nullable: true),
|
||||
Zip = table.Column<string>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Clients", x => x.Id);
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Clients");
|
||||
}
|
||||
}
|
||||
}
|
@ -19,6 +19,48 @@ namespace COA.EnterpriseServices.DataAccess.EntityFramework.Migrations
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128)
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
modelBuilder.Entity("COA.EnterpriseServices.DataAccess.Entities.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int")
|
||||
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
|
||||
|
||||
b.Property<string>("Address")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("City")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("FirstName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("LastName")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("Modified")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<long>("Phone")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<string>("State")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Zip")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("COA.EnterpriseServices.DataAccess.Entities.Creditor", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
|
@ -14,5 +14,6 @@ namespace COA.EnterpriseServices.DataAccess.EntityFramework
|
||||
|
||||
public DbSet<Creditor> Creditors { get; set; }
|
||||
public DbSet<SettlementAttempt> SettlementAttempts { get; set; }
|
||||
public DbSet<Client> Clients { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -13,12 +13,22 @@ namespace COA.EnterpriseServices.DataAccess.QuickBase
|
||||
|
||||
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<Client>(c => c.Id, 1);
|
||||
AddFieldMap<Client>(c => c.Created, 2);
|
||||
AddFieldMap<Client>(c => c.Modified, 3);
|
||||
AddFieldMap<Client>(c => c.Email, 10);
|
||||
AddFieldMap<Client>(c => c.Phone, 11);
|
||||
AddFieldMap<Client>(c => c.FirstName, 20);
|
||||
AddFieldMap<Client>(c => c.LastName, 21);
|
||||
}
|
||||
|
||||
internal static void AddFieldMap<TEntity>(Expression<Func<TEntity, object>> property, int fieldId)
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,14 +6,20 @@ namespace COA.EnterpriseServices.Sandbox
|
||||
internal class Program
|
||||
{
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
ClientStuff();
|
||||
//CreditorStuff();
|
||||
}
|
||||
|
||||
private static void CreditorStuff()
|
||||
{
|
||||
var creditorHelper = new CreditorHelper();
|
||||
|
||||
// get single creditor
|
||||
var singleCreditor = creditorHelper.GetCreditor(1);
|
||||
var singleCreditor = creditorHelper.Get(1);
|
||||
|
||||
// search creditors
|
||||
var searchedCreditors = creditorHelper.FindCreditorsByName("Guy");
|
||||
var searchedCreditors = creditorHelper.FindByName("Guy");
|
||||
|
||||
// search active creditors
|
||||
var activeCreditors = creditorHelper.FindByStatus("Active");
|
||||
@ -25,9 +31,22 @@ namespace COA.EnterpriseServices.Sandbox
|
||||
Status = "Active"
|
||||
};
|
||||
|
||||
creditorHelper.AddCreditor(newCreditor);
|
||||
creditorHelper.Add(newCreditor);
|
||||
}
|
||||
|
||||
private static void ClientStuff()
|
||||
{
|
||||
var clientHelper = new ClientHelper();
|
||||
|
||||
var newClient = new Client
|
||||
{
|
||||
FirstName = "Ryan",
|
||||
LastName = "Peters",
|
||||
Email = "ryan@binarydad.com",
|
||||
Phone = 4102183673
|
||||
};
|
||||
|
||||
clientHelper.Add(newClient);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user