예제 #1
0
        private int Create(string accountName, string currency, User userEntity)
        {
            accountName.EnsureNotNullOrWhiteSpace(nameof(accountName));
            currency.EnsureNotNullOrWhiteSpace(nameof(currency));
            userEntity.EnsureNotNull("User");

            //TODO: should validate in Entity class, not this.
            accountName = accountName.Trim();
            if (accountName.Length < 10 && accountName.Length > 20)
            {
                throw new BusinessException("Account name is not valid.");
            }

            if (BankAccountRepository.ByAccountName(accountName) != null)
            {
                throw new BusinessException("Bank account name is taken.");
            }

            var currencyEntity = CurrencyService.Get(currency);

            currencyEntity.EnsureNotNull("Currency");

            var entity = new BankAccount
            {
                AccountName = accountName,
                Currency    = currencyEntity,
                User        = userEntity
            };

            BankAccountRepository.Create(entity);
            UnitOfWork.SaveChanges();
            return(entity.Id);
        }
예제 #2
0
        public BankAccount Get(string accountName)
        {
            accountName.EnsureNotNullOrWhiteSpace(nameof(accountName));

            var entity = BankAccountRepository.ByAccountName(accountName);

            entity.EnsureNotNull("Account");

            return(entity);
        }
예제 #3
0
 public bool IsOwnedByUser(string accountName, User user)
 => IsOwnedByUser(BankAccountRepository.ByAccountName(accountName), user);
예제 #4
0
 public bool IsOwnedByUser(string accountName, string email)
 => IsOwnedByUser(BankAccountRepository.ByAccountName(accountName), UserRepository.ByEmail(email));
예제 #5
0
 public bool IsOwnedByUser(string accountName, int userId)
 => IsOwnedByUser(BankAccountRepository.ByAccountName(accountName), UserRepository.ById(userId));
예제 #6
0
 public bool Exists(string accountName)
 => BankAccountRepository.ByAccountName(accountName) != null;