コード例 #1
0
ファイル: BankService.cs プロジェクト: vitordm/MyBank
        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));
        }
コード例 #2
0
 public async Task <IActionResult> OpenBankAccount([FromBody] OpenBankAccountRequest request)
 => Ok(await bankService.OpenBankAccount(request));