I'm messing around with an order's transactions and I had a couple of questions:
1.) In an ITransactionSource, how do I find the ChargeSource GUID? Then, once I have the ChargeSource Guid, how do I get ChargeSource Type (e.g. Policy, Endorsement, ATC)?
2.) I have GUID for a CDF or HUD Payee How do I determine the HUDLine/CDFLine and HUDCharge/HUDLine records associated with this GUID?
ChargeSource from TransactionSource
Re: ChargeSource from TransactionSource
1.) In an ITransactionSource, how do I find the ChargeSource GUID? Then, once I have the ChargeSource Guid, how do I get ChargeSource Type (e.g. Policy, Endorsement, ATC)?
If a transaction is associated with a Policy/Endorsement/ATC, you will find the ChargeSource guid in the transaction source's Tags collection.
/// <summary>
/// Determines if an entity is of a given type.
/// </summary>
/// <param name="entity"></param>
/// <param name="entityName"></param>
/// <returns></returns>
internal static bool IsOfType(this IOrderItem entity, string entityName)
{
Type type = entity.GetType();
while (type != null && type != typeof(object))
{
if (type.FullName == entityName)
{
return true;
}
else
{
type = type.BaseType;
}
}
return false;
}
public void Test()
{
//........
//........
foreach (ITransactionSource transactionSource in transaction.Sources)
{
Tag tag = transactionSource.Tags.Where(t => t.Name == "ChargeSource").FirstOrDefault();
Guid chargeSource;
if (tag != null && Guid.TryParse(tag.Value, out chargeSource))
{
IOrderItem sourceObj = _order.Items.SingleOrDefault(sObj => sObj.Guid == chargeSource);
if (sourceObj != null)
{
if (sourceObj.IsOfType("LoanPolicy") || sourceObj.IsOfType("OwnersPolicy"))
{
}
else if (sourceObj.IsOfType("Endorsement"))
{
}
else if (sourceObj.IsOfType("AdditionalTitleCharge"))
{
}
}
}
}
}
If a transaction is associated with a Policy/Endorsement/ATC, you will find the ChargeSource guid in the transaction source's Tags collection.
/// <summary>
/// Determines if an entity is of a given type.
/// </summary>
/// <param name="entity"></param>
/// <param name="entityName"></param>
/// <returns></returns>
internal static bool IsOfType(this IOrderItem entity, string entityName)
{
Type type = entity.GetType();
while (type != null && type != typeof(object))
{
if (type.FullName == entityName)
{
return true;
}
else
{
type = type.BaseType;
}
}
return false;
}
public void Test()
{
//........
//........
foreach (ITransactionSource transactionSource in transaction.Sources)
{
Tag tag = transactionSource.Tags.Where(t => t.Name == "ChargeSource").FirstOrDefault();
Guid chargeSource;
if (tag != null && Guid.TryParse(tag.Value, out chargeSource))
{
IOrderItem sourceObj = _order.Items.SingleOrDefault(sObj => sObj.Guid == chargeSource);
if (sourceObj != null)
{
if (sourceObj.IsOfType("LoanPolicy") || sourceObj.IsOfType("OwnersPolicy"))
{
}
else if (sourceObj.IsOfType("Endorsement"))
{
}
else if (sourceObj.IsOfType("AdditionalTitleCharge"))
{
}
}
}
}
}
Re: ChargeSource from TransactionSource
2.) I have GUID for a CDF or HUD Payee How do I determine the HUDLine/CDFLine and HUDCharge/HUDLine records associated with this GUID?
You will need a reference to the ProForm order to get to the CDFLine and the CDFCharge.
IOrderStore os = _sps.GetService<IOrderStore>();
IOrderInfo info = os.Orders
.Where(o => o.Number == "2014070001")
.SingleOrDefault();
using (IOrder order = os.OpenOrder(info, true))
{
Guid payeeID = new Guid("07DBF8B5-62C3-44E9-AC75-26CB7F7AA670");
IOrderItem payee = order.Items.SingleOrDefault(oi => oi.Guid == payeeID);
IOrderItem charge = (IOrderItem)payee["Parent"];
if (charge.IsOfType("CDFCharge"))
{
IOrderItem cdfLine = (IOrderItem)charge["Parent"];
}
}
You will need a reference to the ProForm order to get to the CDFLine and the CDFCharge.
IOrderStore os = _sps.GetService<IOrderStore>();
IOrderInfo info = os.Orders
.Where(o => o.Number == "2014070001")
.SingleOrDefault();
using (IOrder order = os.OpenOrder(info, true))
{
Guid payeeID = new Guid("07DBF8B5-62C3-44E9-AC75-26CB7F7AA670");
IOrderItem payee = order.Items.SingleOrDefault(oi => oi.Guid == payeeID);
IOrderItem charge = (IOrderItem)payee["Parent"];
if (charge.IsOfType("CDFCharge"))
{
IOrderItem cdfLine = (IOrderItem)charge["Parent"];
}
}