// return change to the buyer public async Task GetDepositCustomerAsync(Guid userId) { using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { try { // find the amount of the deposit var amoutDeposit = await _userDepositRepository.GetAmountDepositAsync(userId); // write off the user's deposit await _userDepositRepository.RetrieveDepositAsync(userId); // take coins from VM var coins = await _vendingMachineService.RetrieveCoinsAsync(amoutDeposit); // give a coin Customer await _purseRepository.AddCoinsAsync(userId, coins); scope.Complete(); } catch (System.Exception) { // TODO: Handle failure throw new ApplicationException("The problem of receiving a deposit by the user!"); } } }
// вернуть сдачу покупателю public async Task GetDepositCustomerAsync(Guid userId) { using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled)) { try { // находим сумму депозита var amoutDeposit = await _userDepositRepository.GetAmountDepositAsync(userId); // списываем депозит юзера await _userDepositRepository.RetrieveDepositAsync(userId); // забираем монетки у VM var coins = await _vendingMachineService.RetrieveCoinsAsync(amoutDeposit); // отдаем монетку Customer await _purseRepository.AddCoinsAsync(userId, coins); scope.Complete(); } catch (System.Exception) { // TODO: Handle failure throw new ApplicationException("The problem of receiving a deposit by the user!"); } } }