Esempio n. 1
0
        public async Task Handle(WalletCreated notification, CancellationToken cancellationToken)
        {
            User user = _userRepository.GetById(notification.UserId);

            user.MustNotBeNull(ex: new UserNotFoundException(ExceptionMessage.UserNotFoundExceptionMessage));

            var accountHistory = new AccountHistory(
                notification.UserId,
                DateTime.Now,
                $"New wallet created for {user.Name} with an initial balance of {notification.InitialBalance}."
                );

            _accountHistoryRepository.Add(accountHistory);

            await _accountHistoryRepository.SaveChanges(cancellationToken);
        }
Esempio n. 2
0
        public async Task Handle(CreditedMoney notification, CancellationToken cancellationToken)
        {
            Wallet wallet = _walletRepository.GetById(notification.EntityId);

            User fromUser = _userRepository.GetById(notification.FromUserId);

            wallet.MustNotBeNull(ex: new WalletNotFoundException(ExceptionMessage.WalletNotFoundExceptionMessage));
            fromUser.MustNotBeNull(ex: new UserNotFoundException(ExceptionMessage.UserNotFoundExceptionMessage));

            var   creditedMoney          = new Money(notification.Amount);
            Money originalDepositedMoney = notification.Currency.OriginalMoneyValue();

            var accountHistory = new AccountHistory(
                notification.ToUserId,
                DateTime.Now,
                notification.Currency.Key == CurrencySettings.DefaultCurrencyKey ?
                $"{creditedMoney} has been credited to your account from {fromUser.Name}. New account balance is {wallet.Balance}." :
                $"{notification.Currency.Key} {originalDepositedMoney.Value:#.00} or {creditedMoney} has been credited to your account from {fromUser.Name}. New account balance is {wallet.Balance}."
                );

            _accountHistoryRepository.Add(accountHistory);

            await _accountHistoryRepository.SaveChanges(cancellationToken);
        }
Esempio n. 3
0
        public async Task Handle(WithdrewMoney notification, CancellationToken cancellationToken)
        {
            Wallet wallet = _walletRepository.GetById(notification.EntityId);

            User user = _userRepository.GetById(notification.UserId);

            wallet.MustNotBeNull(ex: new WalletNotFoundException("Wallet not found."));
            user.MustNotBeNull(ex: new UserNotFoundException(ExceptionMessage.UserNotFoundExceptionMessage));

            var   withdrawnMoney         = new Money(notification.Amount);
            Money originalWithdrawnMoney = notification.Currency.OriginalMoneyValue();

            var accountHistory = new AccountHistory(
                notification.UserId,
                DateTime.Now,
                notification.Currency.Key == CurrencySettings.DefaultCurrencyKey ?
                $"{user.Name} has withdrawn {withdrawnMoney}. Total account balance is {wallet.Balance}." :
                $"{user.Name} has withdrawn {notification.Currency.Key} {originalWithdrawnMoney.Value:#.00} or {withdrawnMoney}. Total account balance is {wallet.Balance}."
                );

            _accountHistoryRepository.Add(accountHistory);

            await _accountHistoryRepository.SaveChanges(cancellationToken);
        }