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 void Create(string accountType, string clientName, string balance) { Client client = new Client(clientName); int account = 0; double value = 0; int.TryParse(accountType, out account); double.TryParse(balance, out value); switch (account) { case (int)AccountType.NORMAL_PERSON: _bankAccountRepository.Create(AccountType.NORMAL_PERSON, client, value); break; case (int)AccountType.LEGAL_PERSON: _bankAccountRepository.Create(AccountType.LEGAL_PERSON, client, value); break; } }