Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public BankAccount Get(string accountName)
        {
            accountName.EnsureNotNullOrWhiteSpace(nameof(accountName));

            var entity = BankAccountRepository.ByAccountName(accountName);

            entity.EnsureNotNull("Account");

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