コード例 #1
0
        public async Task AddTransaction(TransactionEntity transaction)
        {
            await NotFakeDatabase.AccessDatabase();

            Console.WriteLine($"TransactionsRepo: Adding transaction with id {transaction.Id} tot the transaction history.");
            NotFakeDatabase.TransactionsHistory.Add(transaction);
            Console.WriteLine("Transaction processed.");
        }
コード例 #2
0
        public async Task UpdateAccount(AccountEntity accountEntity)
        {
            Console.WriteLine($"AccountsRepo: Updating account with id {accountEntity.Id}");

            await NotFakeDatabase.AccessDatabase();

            var account = GetAccount(accountEntity.Id);

            account.Balance = accountEntity.Balance;
        }
コード例 #3
0
        public async Task <AccountEntity> GetAccountEntity(int accountId)
        {
            Console.WriteLine($"AccountsRepo: Getting account with id {accountId}");

            await NotFakeDatabase.AccessDatabase();

            var account = GetAccount(accountId);

            return(account);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: emilroman/WalletApp
        public static void Main(string[] args)
        {
            NotFakeDatabase.SeedDatabase();

            var serviceProvider = new ServiceCollection()
                                  .AddSingleton <IAccountsRepository, AccountsRepository>()
                                  .AddSingleton <ITransactionsRepository, TransactionsRepository>()
                                  .AddSingleton <IAccountsService, AccountsService>()
                                  .AddSingleton <ITransactionsService, TransactionService>()
                                  .AddAutoMapper()
                                  .BuildServiceProvider();

            accountsService     = serviceProvider.GetService <IAccountsService>();
            transactionsService = serviceProvider.GetService <ITransactionsService>();

            Console.WriteLine("Hi, welcome to your wallet app!");
            ShowAccounts();

            Console.WriteLine("Let's transfer some $");
            Console.WriteLine("Please enter the accountId to transfer from:");
            var fromAccount = int.Parse(Console.ReadLine());

            Console.WriteLine("Please enter the accountId to transfer to:");
            var toAccount = int.Parse(Console.ReadLine());

            Console.WriteLine("Please enter the ammount to transfer:");
            var ammount = int.Parse(Console.ReadLine());

            Console.WriteLine();
            Console.WriteLine("Processing transaction...");
            var transaction = new Transaction
            {
                FromAccountId = fromAccount,
                ToAccountId   = toAccount,
                Amount        = ammount
            };

            try
            {
                transactionsService.ProcessTransaction(transaction).GetAwaiter().GetResult();
                Console.WriteLine("Transaction succeded.");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Transaction failed ({ex.Message}).");
            }


            ShowAccounts();
            Console.Read();
        }
コード例 #5
0
        public async Task <IEnumerable <AccountEntity> > GetAccountEntities()
        {
            Console.WriteLine("AccountsRepo: Getting all accounts.");

            await NotFakeDatabase.AccessDatabase();

            var accounts = NotFakeDatabase.Accounts.Values;

            if (!accounts.Any())
            {
                throw new Exception("AccountsRepo: The database currently contains no accounts.");
            }

            return(accounts);
        }