void SaveBankAccount(BankAccount bankAccount, Customer customer = null) { Customer cu = null; //validate bank account var validator = EntityValidatorFactory.CreateValidator(); var ba = _bankAccountRepository.Get(bankAccount.Id); if (customer != null) { cu = _customerRepository.Get(customer.Id); } if (validator.IsValid <BankAccount>(bankAccount)) // save entity { if (ba == null) { _bankAccountRepository.Add(bankAccount); } else { if (cu != null) { _customerRepository.Modify(cu); } _bankAccountRepository.Modify(ba); } _customerRepository.UnitOfWork.Commit(); _bankAccountRepository.UnitOfWork.Commit(); } else //throw validation errors { throw new ApplicationValidationErrorsException(validator.GetInvalidMessages(bankAccount)); } }
public int Add(BankAccount bankAccount) { bankAccount.Client = _repositoryClient.GetById(bankAccount.Client.Id); bankAccount.Validate(); var bank = _repositoryBankAccount.Add(bankAccount); return(bank.Id); }
public BankAccountCreateResponse CreateBankAccount(BankAccountCreateRequest bankAccountCreateRequest) { BankAccountCreateResponse bankAccountCreateResponse = new BankAccountCreateResponse(); BankAccount bankAccount = new BankAccount(); bankAccount.CustomerRef = bankAccountCreateRequest.CustomerName; _bankRepository.Add(bankAccount); return(bankAccountCreateResponse); }
public void BankAccount_Repository_Add_ShouldBeOk() { //Action var bankAccountRegistered = _repository.Add(_bankAccount); //Assert bankAccountRegistered.Should().NotBeNull(); bankAccountRegistered.Should().Be(_bankAccount); }
public int Add(BankAccount obj) { try { _bankRepository.Add(obj); _bankRepository.SaveChanges(); return(obj.Id); } catch (Exception ex) { throw ex; } }
public void Add(BankAccount account) { if (account is null) { throw new ArgumentNullException(nameof(account)); } /*if (IsExist(account)) * { * throw new RequestForExistAccountException($"{nameof(account)} already exists"); * }*/ bankAccountRepository.Add(account); }
void SaveBankAccount(BankAccount bankAccount) { //validate bank account var validator = EntityValidatorFactory.CreateValidator(); if (validator.IsValid <BankAccount>(bankAccount)) // save entity { _bankAccountRepository.Add(bankAccount); _bankAccountRepository.UnitOfWork.Commit(); } else //throw validation errors { throw new ApplicationValidationErrorsException(validator.GetInvalidMessages(bankAccount)); } }
public BankAccount CreateBankAccount(string CustomerName) { BankAccount bankAccount = new BankAccount(); bankAccount.AccountNo = Guid.NewGuid(); bankAccount.CustomerRef = CustomerName; Transaction openingTransaction = TransactionFactory.CreateDepositTransactionFrom(bankAccount, 0, "account created"); bankAccount.Transactions.Add(openingTransaction); _bankAccountRepository.Add(bankAccount); return(bankAccount); }
public async Task <bool> Create(int customerId, decimal initialCredit) { var bankAccount = new BankAccount { CustomerId = customerId }; var result = await _bankAccountRepository.Add(bankAccount); if (initialCredit != 0) { result &= await _transactionRepository.Add(new Transaction { BankAccountId = bankAccount.Id, Amount = initialCredit }); result &= await UpdateBalance(bankAccount); } return(result); }
/// <summary> /// <see cref="Microsoft.Samples.NLayerApp.Application.MainModule.BankingManagement.IBankingManagementService"/> /// </summary> /// <param name="bankAccount"><see cref="Microsoft.Samples.NLayerApp.Application.MainModule.BankingManagement.IBankingManagementService"/></param> public void AddBankAccount(BankAccount bankAccount) { if (bankAccount == (BankAccount)null) { throw new ArgumentNullException("bankAccount"); } IUnitOfWork unitOfWork = _bankAccountRepository.UnitOfWork as IUnitOfWork; _bankAccountRepository.Add(bankAccount); //complete changes in this unit of work unitOfWork.Commit(); }
public ActionResult <BankAccount> Create( [FromServices] IBankAccountRepository repository, [FromBody] BankAccount model) { try { if (ModelState.IsValid) { repository.Add(model); return(Ok(new { message = "Conta adicionada" })); } return(BadRequest(ModelState)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex)); } }
public BankAccountDto CreateAccount(int accountNo, string accountName, string currencyID, decimal initialBalance) { if (currencyID.Length < 3) { throw new InValidAmountException("Your currency is not in correct format. Pass your currencyID!"); } var currencyDto = _currencyRepository.FindByID(currencyID); if (currencyDto is null) { throw new InValidCurrencyIDException("Your currency ID does not exist!"); } var currency = AutoMapper.Mapper.Map <CurrencyDto, Currency>(currencyDto); var bankAccount = new BankAccount(accountNo, accountName, currency, initialBalance); var bankAccountDto = _bankAccountRepository.Add(bankAccount); return(bankAccountDto); }
public async Task Handle(CreateNewBankAccountCommand message) { var bankAccount = new BankAccount(message.BankId, message.AccountNumber, message.CustomerName, message.InitialBalance); if (!bankAccount.IsValid()) { var messageType = message.GetType().Name; foreach (var error in bankAccount.ValidationResult.Errors) { await NotifyError(messageType, error.ErrorMessage); } } else { _bankAccountRepository.Add(bankAccount); await _uow.SaveChangesAsync(); await _bus.RaiseEvent(new CreatedNewBankAccountEvent(message.AggregateId, bankAccount.Id)); } }
public void TestCRUD() { Core.Entities.BankAccount read; var entity = testEntity;// new Core.Entities.BankAccount() { Name = "TestCRUD-" + Guid.NewGuid().ToString() }; repository.Add(entity); Assert.IsTrue(entity.BankAccountId > 0, "BankAccountId not set"); read = repository.Read(entity.BankAccountId); Assert.IsNotNull(read); CompareBankAccounts(entity, read, "Read"); entity.Name += "-UPDATE"; repository.Update(entity); read = repository.Read(entity.BankAccountId); Assert.IsNotNull(read); CompareBankAccounts(entity, read, "Update"); repository.Delete(entity); read = repository.Read(entity.BankAccountId); Assert.IsNull(read); }
public void Add(Bank_Account bank_Account) { bankAccountRepository.Add(bank_Account); }
public BankAccount Create(BankAccount bankAccount) { _bankAccountRepository.Add(bankAccount); return(bankAccount); }