public void Add(BankLedger bankLedger, decimal amount) { bool flag = false; try { _unitOfWork.BeginTransaction(); flag = true; var identity = (LoginIdentity)Thread.CurrentPrincipal.Identity; if (string.IsNullOrEmpty(bankLedger.CompanyId)) { bankLedger.CompanyId = identity.CompanyId; } if (string.IsNullOrEmpty(bankLedger.BranchId)) { bankLedger.BranchId = identity.BranchId; } bankLedger.Id = GenerateAutoId(bankLedger.CompanyId, bankLedger.BranchId, "BankLedger"); bankLedger.Sequence = GetAutoSequence("BankLedger"); bankLedger.TrackingNo = GenerateTrackingNo(bankLedger.CompanyId, bankLedger.BranchId, "BankLedger"); if (bankLedger.TransactionType == BankTransactionType.Deposit.ToString()) { bankLedger.DebitAmount = amount; bankLedger.CreditAmount = 0; } else if (bankLedger.TransactionType == BankTransactionType.Withdrawn.ToString()) { bankLedger.DebitAmount = 0; bankLedger.CreditAmount = amount; } bankLedger.SynchronizationType = SynchronizationType.Server.ToString(); bankLedger.AddedBy = identity.Name; bankLedger.AddedDate = DateTime.Now; bankLedger.AddedFromIp = identity.IpAddress; _bankLedgerRepository.Add(bankLedger); _unitOfWork.SaveChanges(); flag = false; _unitOfWork.Commit(); _rawSqlService.UpdateBankLedgerRunningBalance(bankLedger?.AccountNo); } catch (Exception ex) { throw new Exception(ex.Message); } finally { if (flag) { _unitOfWork.Rollback(); } } }