add Raw to DAM. add initial support for uspCreditorPortal_SettlementAttemptGet

This commit is contained in:
Ryan Peters 2020-10-15 23:15:28 -04:00
parent 7ad01a2586
commit 79b3b5be1d
2 changed files with 52 additions and 39 deletions

View File

@ -35,6 +35,18 @@ namespace COA.EnterpriseServices.DataAccess
return Invoke<T, ICollection<T>>(d => d.Get(query)); return Invoke<T, ICollection<T>>(d => d.Get(query));
} }
public T Get<T>(int id) where T : class, IRecord
{
var item = Get<T>(i => i.Id == id);
if (item != null && item.Any())
{
return item.FirstOrDefault();
}
return default;
}
public bool Add<T>(T item) where T : class, IRecord public bool Add<T>(T item) where T : class, IRecord
{ {
return Invoke<T, bool>(d => d.Add(item)); return Invoke<T, bool>(d => d.Add(item));
@ -56,16 +68,9 @@ namespace COA.EnterpriseServices.DataAccess
return Update(item); return Update(item);
} }
public T Get<T>(int id) where T : class, IRecord public ICollection<T> Raw<T>(string command, params object[] parameters) where T : class, IRecord
{ {
var item = Get<T>(i => i.Id == id); return Invoke<T, ICollection<T>>(d => d.Raw(command, parameters));
if (item != null && item.Any())
{
return item.FirstOrDefault();
}
return default;
} }
private TResult Invoke<T, TResult>(Func<IDataAccess<T>, TResult> func) where T : class, IRecord private TResult Invoke<T, TResult>(Func<IDataAccess<T>, TResult> func) where T : class, IRecord

View File

@ -2,6 +2,7 @@
using COA.EnterpriseServices.Creditors; using COA.EnterpriseServices.Creditors;
using COA.EnterpriseServices.DataAccess.Entities; using COA.EnterpriseServices.DataAccess.Entities;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace COA.EnterpriseServices.DataAccess.Helpers namespace COA.EnterpriseServices.DataAccess.Helpers
{ {
@ -35,51 +36,58 @@ namespace COA.EnterpriseServices.DataAccess.Helpers
public ICollection<Creditors.SettlementAttempt> GetSettlements(SettlementAttemptFilter filter) public ICollection<Creditors.SettlementAttempt> GetSettlements(SettlementAttemptFilter filter)
{ {
var dal2 = new DataAccessManager2(); // we may use this non-generic throughout instead
var dataAccess = new DataAccessManager2();
dal2.Get<Entities.Creditor>(c => c.ClientLastName == "Peters"); // More info on "FromSqlRaw" => https://docs.microsoft.com/en-us/ef/core/querying/raw-sql
var attempts = dataAccess.Raw<Entities.SettlementAttempt>("uspCreditorPortal_SettlementAttemptGet @SettlementAttemptID = {0}, @CreditorProfileID = {1}", filter.SettlementAttemptId, filter.CreditorProfileId);
return DBWrapper.ExecuteProcedure(QuickbaseConnectionString, "uspCreditorPortal_SettlementAttemptGet", cmd => // TODO: write extension to map list of T to destination type
{ return attempts
if (filter != null) .Select(a => mapper.Map<Creditors.SettlementAttempt>(a))
{ .ToList();
cmd.CommandTimeout = 0;
cmd.Parameters.AddWithValue("@SettlementAttemptID", filter.SettlementAttemptId); //return DBWrapper.ExecuteProcedure(QuickbaseConnectionString, "uspCreditorPortal_SettlementAttemptGet", cmd =>
cmd.Parameters.AddWithValue("@CreditorProfileID", filter.CreditorProfileId); //{
cmd.Parameters.AddWithValue("@CreditorID", filter.CreditorId); // if (filter != null)
cmd.Parameters.AddWithValue("@CreditorContactID", filter.CreditorContactId); // {
cmd.Parameters.AddWithValue("@FirstPaymentDateStart", filter.FirstPaymentDateStart); // cmd.CommandTimeout = 0;
cmd.Parameters.AddWithValue("@FirstPaymentDateEnd", filter.FirstPaymentDateEnd);
cmd.Parameters.AddWithValue("@ResponseDateStart", filter.ResponseDateStart);
cmd.Parameters.AddWithValue("@ResponseDateEnd", filter.ResponseDateEnd);
cmd.Parameters.AddWithValue("@PortalSubmissionDateStart", filter.PortalSubmissionDateStart);
cmd.Parameters.AddWithValue("@PortalSubmissionDateEnd", filter.PortalSubmissionDateEnd);
if (filter.SettlementAttemptIds.AnyAndNotNull()) // cmd.Parameters.AddWithValue("@SettlementAttemptID", filter.SettlementAttemptId);
{ // cmd.Parameters.AddWithValue("@CreditorProfileID", filter.CreditorProfileId);
cmd.Parameters.Add("@SettlementAttemptIDs", SqlDbType.Structured).Value = CreateIdsTable(filter.SettlementAttemptIds); // cmd.Parameters.AddWithValue("@CreditorID", filter.CreditorId);
} // cmd.Parameters.AddWithValue("@CreditorContactID", filter.CreditorContactId);
else if (filter.CreditorIds.AnyAndNotNull()) // cmd.Parameters.AddWithValue("@FirstPaymentDateStart", filter.FirstPaymentDateStart);
{ // cmd.Parameters.AddWithValue("@FirstPaymentDateEnd", filter.FirstPaymentDateEnd);
cmd.Parameters.Add("@CreditorIDs", SqlDbType.Structured).Value = CreateIdsTable(filter.CreditorIds); // cmd.Parameters.AddWithValue("@ResponseDateStart", filter.ResponseDateStart);
} // cmd.Parameters.AddWithValue("@ResponseDateEnd", filter.ResponseDateEnd);
} // cmd.Parameters.AddWithValue("@PortalSubmissionDateStart", filter.PortalSubmissionDateStart);
// cmd.Parameters.AddWithValue("@PortalSubmissionDateEnd", filter.PortalSubmissionDateEnd);
return cmd.ToList<SettlementAttempt>(); // if (filter.SettlementAttemptIds.AnyAndNotNull())
}); // {
// cmd.Parameters.Add("@SettlementAttemptIDs", SqlDbType.Structured).Value = CreateIdsTable(filter.SettlementAttemptIds);
// }
// else if (filter.CreditorIds.AnyAndNotNull())
// {
// cmd.Parameters.Add("@CreditorIDs", SqlDbType.Structured).Value = CreateIdsTable(filter.CreditorIds);
// }
// }
// return cmd.ToList<SettlementAttempt>();
//});
} }
public bool AddCreditor(Creditors.Creditor creditor) public bool AddCreditor(Creditors.Creditor creditor)
{ {
var creditorEntity = mapper.Map<Creditor>(creditor); var creditorEntity = mapper.Map<Entities.Creditor>(creditor);
return creditorDataAccess.Add(creditorEntity); return creditorDataAccess.Add(creditorEntity);
} }
public bool UpdateCreditor(Creditors.Creditor creditor) public bool UpdateCreditor(Creditors.Creditor creditor)
{ {
var creditorEntity = mapper.Map<Creditor>(creditor); var creditorEntity = mapper.Map<Entities.Creditor>(creditor);
return creditorDataAccess.Update(creditorEntity); return creditorDataAccess.Update(creditorEntity);
} }