static async Task CommittableTransactionAsync() { var tx = new CommittableTransaction(); DisplayTransactionInformation("TX created", tx.TransactionInformation); try { var b = new Book { Title = "A Dog in The House", Publisher = "Pet Show", Isbn = RandomIsbn(), ReleaseDate = new DateTime(2018, 11, 24) }; var data = new BookData(); await data.AddBookAsync(b, tx); if (AbortTx()) { throw new ApplicationException("transaction abort by the user"); } tx.Commit(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(); tx.Rollback(); } DisplayTransactionInformation("TX completed", tx.TransactionInformation); }
static async Task TransactionPromotionsAsync() { var tx = new CommittableTransaction(); DisplayTransactionInformation("TX created", tx.TransactionInformation); try { var b = new Book { Title = "A Cat in The House", Publisher = "Pet Show", Isbn = string.Join("", Guid.NewGuid().ToString().ToCharArray().Take(15)), ReleaseDate = new DateTime(2019, 11, 24) }; var data = new BookData(); await data.AddBookAsync(b, tx); DisplayTransactionInformation("First Connection", tx.TransactionInformation); var b2 = new Book { Title = "A Rabbit in The House", Publisher = "Pet Show", Isbn = string.Join("", Guid.NewGuid().ToString().ToCharArray().Take(15)), ReleaseDate = new DateTime(2020, 11, 24) }; var data2 = new BookData(); await data2.AddBookAsync(b2, tx); DisplayTransactionInformation("Second Connection", tx.TransactionInformation); if (AbortTx()) { throw new ApplicationException("transaction abort by the user"); } tx.Commit(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(); tx.Rollback(); } DisplayTransactionInformation("TX completed", tx.TransactionInformation); }