Ramco Ramco

Ramco Ramco

  • 439
  • 3.4k
  • 544.9k

How to RollBack if error encounters

Feb 1 2023 6:19 AM

Hi

 In below code Data is updated in 2 tables. I want if any error occurs during the processing it should RollBack . Only if data is updated in 2 condition then Success message should get displayed

try
{
    BALReturnOrderHeader bALReturnOrderHeader = new BALReturnOrderHeader();
    BALReturnOrderItem bALReturnOrderItem = new BALReturnOrderItem();
    BALReturnOrderLine bALReturnOrderLine = new BALReturnOrderLine();
    BALNimbusReturnOrderDetails bALNimbusReturnOrderDetails = new BALNimbusReturnOrderDetails();

    ReturnOrderHeader objreturnOrderHeader = bALReturnOrderHeader.GetReturnOrderHeaderDetail(Convert.ToInt32(hdfUpdateReturnOrderID.Value));
    if (objreturnOrderHeader != null)
    {
        objreturnOrderHeader.IsActive = false;
        bALReturnOrderHeader.UpdateReturnOrder(objreturnOrderHeader);
    }

    List<ReturnOrderItem> objreturnOrderItem = bALReturnOrderItem.GetReturnOrderItems(Convert.ToInt32(hdfUpdateReturnOrderID.Value));
    if (objreturnOrderItem.Count > 0)
    {
        foreach (var colum in objreturnOrderItem)
        {
            ReturnOrderItem returnOrderItem = bALReturnOrderItem.GetRecordDetail(colum.ItemID);
            if (returnOrderItem != null)
            {
                returnOrderItem.Deleted = true;
                bALReturnOrderItem.UpdateReturnOrderItem(returnOrderItem);
            }
        }
    }
}
catch (Exception ex)
{
    Utility.SaveErrorLog(ex.Message, System.IO.Path.GetFileName(Request.Path), System.Reflection.MethodBase.GetCurrentMethod().Name, Convert.ToInt32(hdfLogisticsManagerID.Value));
    ShowMessage("Oops...", ex.Message, "error");
}

Thanks


Answers (2)