/// <inheritdoc /> public string CreateAccount( AccountType type, IAccountNumberGenerator numberGenerator, string ownerFirstName, string ownerLastName, string ownerEmail, decimal balance = 0m, int bonus = 0) { if (ReferenceEquals(numberGenerator, null)) { throw new ArgumentNullException(nameof(numberGenerator)); } try { string accountNumber = numberGenerator.CreateNumber(_repository.GetAllAccounts().ToBllAccounts()); var account = CreateAccountOfSpecifiedType(type, accountNumber, ownerFirstName, ownerLastName, ownerEmail, balance, bonus); _repository.AddAccount(account.ToDtoAccount()); return(accountNumber); } catch (Exception ex) { throw new BankAccountServiceException("Some error occuried while creating new account.", ex); } }
public async Task <IActionResult> Post([FromBody] IEnumerable <BankAccountDto> newAccounts) { if (newAccounts == null) { throw new Exception("Something went wrong..."); } try { foreach (var newAccount in newAccounts) { await _accountRepository.AddAccount(new BankAccountDoc { Id = new Guid(newAccount.Id), UserId = newAccount.Id, Label = newAccount.Label, BankNumber = newAccount.BranchNumber, AccountNumber = newAccount.AccountNumber }); } } catch (Exception ex) { throw; } return(Ok(newAccounts)); }