public void Rollback() { if (Trn != null) { Trn.Rollback(); ActiveTransaction = false; } }
/// <summary> /// Insert New Rate in DB which pick up from Azure Job Scheduled for every 30 minutes. /// </summary> /// <returns></returns> public async Task <bool> Create(CurrencyViewModel currencyViewModel) { try { using (SqlConnection Cn = new SqlConnection(ConnectionString)) { SqlParameter[] parameters = { new SqlParameter("@pstrCurrCode", SqlDbType.VarChar), new SqlParameter("@pdecExchRate", SqlDbType.Decimal, 20), }; parameters[0].Value = currencyViewModel.SourceCurrency; parameters[1].Value = currencyViewModel.ConversionRate; SqlTransaction Trn; Cn.Open(); Trn = Cn.BeginTransaction(); try { await SqlHelper.ExecuteNonQueryAsync(Trn, CommandType.StoredProcedure, consExchRateCreate, parameters); Trn.Commit(); } catch (SqlException exSql) { Trn.Rollback(); //Need to use logger to log the error } finally { Trn.Dispose(); } } } catch (Exception ex) { throw ex; } return(true); }