public void AddUser(User user) { using (var context = new WalletDBContext()) { context.Users.Add(user); context.SaveChanges(); } }
public async Task <ActionResult <Transaction> > PostTransactionDe(Transaction transaction) { try { // using (var scope = new TransactionScope(TransactionScopeOption.Required, new // TransactionOptions { IsolationLevel = IsolationLevel.RepeatableRead })) // using (TransactionScope ts = new TransactionScope()) using (TransactionScope ts = CreateTransactionScope()) { var tran = new Transaction(); tran.WalletId = transaction.WalletId; tran.Amount = transaction.Amount; tran.Destination = transaction.Destination; tran.Type = transaction.Type; tran.TimeCreate = DateTime.Now; tran.WalletNo = transaction.WalletNo; var wallet = _context.Wallets.FirstOrDefault(x => x.WalletNo == transaction.WalletNo); wallet.Balance = wallet.Balance + tran.Amount; wallet.TimeUpdate = DateTime.Now; _context.Transactions.Add(tran); _context.SaveChanges(); // scope.Complete(); var transactionResult = _context.Transactions // .Include(transaction => transaction.Wallet) // .ThenInclude(transaction => transaction.Customer) .FirstOrDefault(transaction => transaction.TransId == tran.TransId); ts.Complete(); return(transactionResult); } } catch (Exception) { return(NotFound()); } }