public int Add(BankAccountInputDto entity) { Notification notification = Validation(entity); if (notification.HasErrors()) { throw new ArgumentException(notification.ErrorMessage()); } var customer = _unitOfWork.Customers.GetByIdWithBankAccounts(entity.CustomerId); var bankAccountWithSameAccountNumber = _unitOfWork.BankAccounts.GetByNumber(entity.Number); _bankAccountDomainService.PerformNewBankAccount(customer, bankAccountWithSameAccountNumber, entity.Number, entity.IsLocked); return(_unitOfWork.Complete()); }
private Notification Validation(BankAccountInputDto entity) { Notification notification = new Notification(); if (entity == null) { notification.AddError("Invalid JSON data in request body."); return(notification); } if (string.IsNullOrEmpty(entity.Number)) { notification.AddError("Bank Account Number is missing"); } else if (entity.Number.Length != 18) { notification.AddError("Bank Account Number should have 18 numbers"); } return(notification); }
public IActionResult Post([FromBody] BankAccountInputDto bankAccount) { _bankAccountApplicationService.Add(bankAccount); return(Ok("bank account was added successfully")); }