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); }
public BankAccount Get(string accountName) { accountName.EnsureNotNullOrWhiteSpace(nameof(accountName)); var entity = BankAccountRepository.ByAccountName(accountName); entity.EnsureNotNull("Account"); return(entity); }
public bool IsOwnedByUser(string accountName, User user) => IsOwnedByUser(BankAccountRepository.ByAccountName(accountName), user);
public bool IsOwnedByUser(string accountName, string email) => IsOwnedByUser(BankAccountRepository.ByAccountName(accountName), UserRepository.ByEmail(email));
public bool IsOwnedByUser(string accountName, int userId) => IsOwnedByUser(BankAccountRepository.ByAccountName(accountName), UserRepository.ById(userId));
public bool Exists(string accountName) => BankAccountRepository.ByAccountName(accountName) != null;