Here is my mapping file
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="HELM.Domains.Payments,HELM.Domains" table="Payment" lazy="false" >
<id name="Paymentid" column="PaymentID" type="System.Int32">
<generator class="increment"/>
</id>
<property column="LastName" type="System.String" name="LastName" />
<property column="FirstName" type="System.String" name="FirstName" />
<property column="Address1" type="System.String" name="Address1" />
<property column="Address2" type="System.String" name="Address2" />
<property column="City" type="System.String" name="City" />
<property column="State" type="System.String" name="State" />
<property column="Zip" type="System.String" name="Zip" />
<property column="Phone" type="System.String" name="Phone" />
</class>
</hibernate-mapping>
Here is my code
Code:
//payment retries loop for PK violation
for (int i = 0; i < 10; i++)
{
try
{
//we need a paymentID and an OrderID before we can send
//the payment to the CGW
PersistenceManager.Save(payment, false);
theReturn = ProcessPayment(payment);
//process the payment
if (theReturn.Result == false)
{
//payment declined
PaymentDeclined(payment);
}
else
{
PaymentAuthorized(payment);
}
//save the payment
PersistenceManager.SaveOrUpdate(payment, true);
//no pk errors, leave our loop
break;
}
catch (Exception ex)
{
Exception innerMostException = ex;
//get the inner-most exception
while (innerMostException.InnerException != null)
{
innerMostException = innerMostException.InnerException;
}
if (innerMostException.GetType() == typeof(SqlException))
{
//these error numbers are all error numbers for PK violations
if (((SqlException)innerMostException).Number != 547 && ((SqlException)innerMostException).Number != 2627 && ((SqlException)innerMostException).Number != 2607)
{
//something other than a PK violation and this loop
//isn't here to handle that
throw new Exception("Unable to apply payment. \n\n\n" + "message is: \n\n" + ex.Message);
}
else
{
payment.Paymentid = 0;
}
}
else
{
//something other than a PK violation and this loop
//isn't here to handle that
throw new Exception("Unable to apply payment. \n\n\n" + "message is: \n\n" + ex.Message);
}
}
}
Thanks for your help