2020-10-15 13:34:25 +00:00
|
|
|
|
using AutoMapper;
|
2020-10-16 03:05:21 +00:00
|
|
|
|
using COA.EnterpriseServices.Creditors;
|
|
|
|
|
using System.Collections.Generic;
|
2020-10-16 03:15:28 +00:00
|
|
|
|
using System.Linq;
|
2020-10-14 12:35:14 +00:00
|
|
|
|
|
|
|
|
|
namespace COA.EnterpriseServices.DataAccess.Helpers
|
|
|
|
|
{
|
2020-10-16 13:54:09 +00:00
|
|
|
|
public class CreditorHelper : BaseHelper
|
2020-10-14 12:35:14 +00:00
|
|
|
|
{
|
2020-10-15 13:34:25 +00:00
|
|
|
|
private readonly IMapper mapper;
|
2020-10-14 16:23:04 +00:00
|
|
|
|
|
2020-10-16 13:54:09 +00:00
|
|
|
|
public CreditorHelper(DataAccessManager dataAccess, IMapper mapper) : base(dataAccess, mapper) { }
|
2020-10-14 21:57:39 +00:00
|
|
|
|
|
2020-10-16 13:54:09 +00:00
|
|
|
|
public Creditor GetCreditor(int id)
|
2020-10-14 16:23:04 +00:00
|
|
|
|
{
|
2020-10-16 13:54:09 +00:00
|
|
|
|
return DataAccess
|
|
|
|
|
.Get<Entities.Creditor>(id)
|
|
|
|
|
.MapTo<Creditor>();
|
2020-10-14 16:23:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-16 13:54:09 +00:00
|
|
|
|
public SettlementAttempt GetSettlementAttempt(int id)
|
2020-10-14 16:23:04 +00:00
|
|
|
|
{
|
2020-10-16 13:54:09 +00:00
|
|
|
|
return DataAccess
|
|
|
|
|
.Get<Entities.SettlementAttempt>(id)
|
|
|
|
|
.MapTo<SettlementAttempt>();
|
2020-10-16 03:05:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-16 13:54:09 +00:00
|
|
|
|
public ICollection<SettlementAttempt> GetSettlements(SettlementAttemptFilter filter)
|
2020-10-16 03:05:21 +00:00
|
|
|
|
{
|
2020-10-16 03:15:28 +00:00
|
|
|
|
// More info on "FromSqlRaw" => https://docs.microsoft.com/en-us/ef/core/querying/raw-sql
|
2020-10-16 13:54:09 +00:00
|
|
|
|
return DataAccess
|
|
|
|
|
.Raw<Entities.SettlementAttempt>("uspCreditorPortal_SettlementAttemptGet @SettlementAttemptID = {0}, @CreditorProfileID = {1}", filter.SettlementAttemptId, filter.CreditorProfileId)
|
|
|
|
|
.MapTo<SettlementAttempt>()
|
2020-10-16 03:15:28 +00:00
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
//return DBWrapper.ExecuteProcedure(QuickbaseConnectionString, "uspCreditorPortal_SettlementAttemptGet", cmd =>
|
|
|
|
|
//{
|
|
|
|
|
// if (filter != null)
|
|
|
|
|
// {
|
|
|
|
|
// cmd.CommandTimeout = 0;
|
|
|
|
|
|
|
|
|
|
// cmd.Parameters.AddWithValue("@SettlementAttemptID", filter.SettlementAttemptId);
|
|
|
|
|
// cmd.Parameters.AddWithValue("@CreditorProfileID", filter.CreditorProfileId);
|
|
|
|
|
// cmd.Parameters.AddWithValue("@CreditorID", filter.CreditorId);
|
|
|
|
|
// cmd.Parameters.AddWithValue("@CreditorContactID", filter.CreditorContactId);
|
|
|
|
|
// cmd.Parameters.AddWithValue("@FirstPaymentDateStart", filter.FirstPaymentDateStart);
|
|
|
|
|
// 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.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>();
|
|
|
|
|
//});
|
2020-10-14 16:23:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-16 13:54:09 +00:00
|
|
|
|
public bool AddCreditor(Creditor creditor)
|
2020-10-14 16:23:04 +00:00
|
|
|
|
{
|
2020-10-16 03:15:28 +00:00
|
|
|
|
var creditorEntity = mapper.Map<Entities.Creditor>(creditor);
|
2020-10-15 12:48:11 +00:00
|
|
|
|
|
2020-10-16 13:54:09 +00:00
|
|
|
|
return DataAccess.Add(creditorEntity);
|
2020-10-14 12:35:14 +00:00
|
|
|
|
}
|
2020-10-15 11:07:32 +00:00
|
|
|
|
|
2020-10-16 13:54:09 +00:00
|
|
|
|
public bool UpdateCreditor(Creditor creditor)
|
2020-10-15 12:48:11 +00:00
|
|
|
|
{
|
2020-10-16 03:15:28 +00:00
|
|
|
|
var creditorEntity = mapper.Map<Entities.Creditor>(creditor);
|
2020-10-15 12:48:11 +00:00
|
|
|
|
|
2020-10-16 13:54:09 +00:00
|
|
|
|
return DataAccess.Update(creditorEntity);
|
2020-10-15 12:48:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-15 11:07:32 +00:00
|
|
|
|
public bool SetCreditorStatus(int creditorId, string status)
|
|
|
|
|
{
|
2020-10-16 13:54:09 +00:00
|
|
|
|
return DataAccess.Update<Entities.Creditor>(creditorId, c => c.Status = status);
|
2020-10-15 12:08:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetOriginalCreditorAsPrimary(int creditorId)
|
|
|
|
|
{
|
2020-10-16 13:54:09 +00:00
|
|
|
|
var creditor = DataAccess.Get<Entities.Creditor>(creditorId);
|
2020-10-15 12:08:02 +00:00
|
|
|
|
|
2020-10-16 02:17:27 +00:00
|
|
|
|
creditor.ReferenceNumber = string.Empty;
|
|
|
|
|
|
2020-10-16 13:54:09 +00:00
|
|
|
|
DataAccess.Update(creditor);
|
2020-10-16 02:17:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ClearCreditorReferenceNumber(int creditorId)
|
|
|
|
|
{
|
2020-10-16 13:54:09 +00:00
|
|
|
|
var creditor = DataAccess.Get<Entities.Creditor>(creditorId);
|
2020-10-16 02:17:27 +00:00
|
|
|
|
|
2020-10-15 12:08:02 +00:00
|
|
|
|
creditor.CurrentCreditorProfileId = creditor.OriginalCreditorProfileId;
|
|
|
|
|
|
2020-10-16 13:54:09 +00:00
|
|
|
|
DataAccess.Update(creditor);
|
2020-10-15 11:07:32 +00:00
|
|
|
|
}
|
2020-10-14 12:35:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|