Exemplo n.º 1
0
        public async Task <BankAccountDto> OpenBankAccount(OpenBankAccountRequest request)
        {
            var convertedType = Enum.TryParse(request.Type, out BankAccountType type);

            if (!convertedType)
            {
                throw new InvalidOperationException("Type of Account is Invalid!");
            }

            var customer = await bankCustomerRepository.FindCustomerByDocumentAsync(request.Customer.Document);

            if (customer is null)
            {
                throw new InvalidOperationException("Customer is invalid!");
            }

            var account = await bankAccountRepository.FindAccountAsync(request.Branch, request.Account, request.Digit);

            if (account != null)
            {
                throw new InvalidOperationException("Account is already registered");
            }

            account = new BankAccount(request.Branch, request.Account, request.Digit, request.AuthorizationPass, customer);

            await bankAccountRepository.InsertAsync(account);

            return(mapper.Map <BankAccountDto>(account));
        }