public BankAccountDto GetById(Guid?userId, int id) { BankAccountDto toReturn = null; try { if (userId.HasValue) { using (var context = Factory.CreateContext(ConnexionString)) { toReturn = ExtractBankAccount(userId, id, context).ToDto(); } } } catch (DaGetServiceException) { throw; } catch (Exception ex) { throw new DaGetServiceException( String.Format("Erreur lors de la récupération du compte {0} pour l'utilisateur {1}", id, userId), ex); } return(toReturn); }
/// <summary> /// <see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IBankAppService" /> /// </summary> /// <param name="bankAccountDto"> /// <see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IBankAppService" /> /// </param> /// <returns> /// <see cref="Microsoft.Samples.NLayerApp.Application.MainBoundedContext.BankingModule.Services.IBankAppService" /> /// </returns> public BankAccountDto AddBankAccount(BankAccountDto bankAccountDto) { if (bankAccountDto == null || bankAccountDto.CustomerId == Guid.Empty) { throw new ArgumentException(Messages.warning_CannotAddNullBankAccountOrInvalidCustomer); } //check if exists the customer for this bank account var associatedCustomer = _customerRepository.Get(bankAccountDto.CustomerId); if (associatedCustomer != null) // if the customer exist { //Create a new bank account number var accountNumber = CalculateNewBankAccountNumber(); //Create account from factory var account = BankAccountFactory.CreateBankAccount(associatedCustomer, accountNumber); //save bank account SaveBankAccount(account); return(account.ProjectedAs <BankAccountDto>()); } else //the customer for this bank account not exist, cannot create a new bank account { throw new InvalidOperationException(Messages.warning_CannotCreateBankAccountForNonExistingCustomer); } }
public BankAccountDto getById(long AccountId) { var bankAccount = _iUnitOfWork.BankAccounts.GetById(AccountId); BankAccountDto bankAccountDto = _mapper.Map <BankAccountDto>(bankAccount); return(bankAccountDto); }
public async Task <List <AccountWithMasterDetailsDto> > GetCOAAccountDetailsaAsync() { var data = await _repository.GetCOADetailAsync(); List <AccountWithMasterDetailsDto> accountDetailDto = new List <AccountWithMasterDetailsDto>(); foreach (var item in data) { AccountWithMasterDetailsDto accountMasterDto = new AccountWithMasterDetailsDto(); accountMasterDto.Id = item.Id.ToString(); accountMasterDto.text = item.AccountMasterName; accountMasterDto.children = new List <BankAccountDto>(); foreach (var accType in item.AccountTypes) { foreach (var acc in accType.BankAccount) { BankAccountDto bankAccountDto = new BankAccountDto(); bankAccountDto.Id = acc.Id.ToString(); bankAccountDto.text = acc.AccountName.ToString(); accountMasterDto.children.Add(bankAccountDto); } } accountDetailDto.Add(accountMasterDto); } return(accountDetailDto); }
public TransactionDto Pay(CreditCardDto from, BankAccountDto to, double amountDollar) { if (!IsValid(from)) { return(null); } var builder = new TransactionBuilder(); Transaction transaction = builder .From(from.CardNumber) .To(to.Id) .AmountDollar(amountDollar) .TimeUtcNow() .Build(); using (var db = new BankSystemContext()) { Transaction saved = db.Transactions.Add(transaction); BankAccountDetails fromBank = db.BankAccounts.FirstOrDefault(bank => bank.CreditCards.Any(card => card.CardNumber == from.CardNumber)); if (fromBank == null) { return(null); } fromBank.Balance -= transaction.AmountDollar; BankAccountDetails toBank = db.BankAccounts.Find(to.Id); toBank.Balance += transaction.AmountDollar; db.SaveChanges(); return(mapper.Map <TransactionDto>(transaction)); } }
public Object PerformTransfer(BankAccountDto originBankAccountDto, BankAccountDto destinationBankAccountDto, Decimal amount) { try { BaseResponseDto <BankAccountDto> baseResponseDto = new BaseResponseDto <BankAccountDto>(); //List<BankAccountDto> bankAccountDto = this.bankAccountRepository.FindByNumber(originBankAccountDto.Number); //baseResponseDto.Data = customerDto; var originAccount = bankAccountRepository.FindByNumber(originBankAccountDto.Number); var destinationAccount = bankAccountRepository.FindByNumber(destinationBankAccountDto.Number); //transferDomainService.PerformTransfer(originAccount, destinationAccount, amount); originAccount.Balance = originAccount.Balance - amount; destinationAccount.Balance = destinationAccount.Balance + amount; bankAccountRepository.Update(originAccount); bankAccountRepository.Update(destinationAccount); return(baseResponseDto); } catch (Exception) { return(this.getExceptionErrorResponse()); } }
public void create(BankAccountDto bankAccountDto) { BankAccount bankAccount = _mapper.Map <BankAccount>(bankAccountDto); Notification notification = this.validationIsNull(bankAccount); if (notification.hasErrors()) { throw new ArgumentException(notification.errorMessage()); } notification = bankAccount.validateSaveBankAccount(); if (notification.hasErrors()) { throw new ArgumentException(notification.errorMessage()); } BankAccount findBankAccount = _iUnitOfWork.BankAccounts.findByNumberLocked(bankAccountDto.Number); this.bankAccountDomainService.validDoesntExistNumberAccount(findBankAccount); Customer findCustomer = _iUnitOfWork.Customers.GetById(bankAccount.CustomerId); this.customerDomainService.validExistCustomer(findCustomer); _iUnitOfWork.BankAccounts.Add(bankAccount); _iUnitOfWork.Complete(); }
private static void AssertEqual(BankAccountDto expected, BankAccountDto actual) { TransactionCategoryTests.AssertEqual(expected, actual, false); Assert.AreEqual(expected.DisplayName, actual.DisplayName, "Different display name."); Assert.AreEqual(expected.BSB, actual.BSB, "Different BSB."); Assert.AreEqual(expected.AccountNumber, actual.AccountNumber, "Different account number."); }
public BankAccountDto Deposit(BankAccountDto bankAccount) { try { _transactionService.CreateDeposit(bankAccount.AccountNumber, bankAccount.Amount, bankAccount.Currency); var currBankAccount = _bankAccountService.GetByID(bankAccount.AccountNumber); var bankAccountDto = new BankAccountDto() { AccountNumber = currBankAccount.AccountNo, Balance = decimal.Round(currBankAccount.Balance, 2, MidpointRounding.AwayFromZero), Currency = currBankAccount.CurrencyID, Message = $"{bankAccount.Amount} {bankAccount.Currency} was successfully deposited into your account. Your current balance is {currBankAccount.Balance} {currBankAccount.CurrencyID}!", Successful = true, Amount = bankAccount.Amount }; return(bankAccountDto); } catch (Exception ex) { var bankAccountDto = new BankAccountDto() { AccountNumber = bankAccount.AccountNumber, Balance = null, Currency = null, Message = ex.Message, Successful = false, Amount = bankAccount.Amount }; return(bankAccountDto); } }
public BankAccountDto Balance(int accountNumber) { try { var bankAccount = _bankAccountService.GetByID(accountNumber); var bankAccountDto = new BankAccountDto() { AccountNumber = bankAccount.AccountNo, Balance = decimal.Round(bankAccount.Balance, 2, MidpointRounding.AwayFromZero), Currency = bankAccount.CurrencyID, Message = $"Your current balance is {bankAccount.Balance} {bankAccount.CurrencyID}!", Successful = true }; return(bankAccountDto); } catch (Exception ex) { var bankAccountDto = new BankAccountDto() { AccountNumber = accountNumber, Balance = null, Currency = null, Message = ex.Message, Successful = false }; return(bankAccountDto); } }
public async Task ValidateBankAccount(BankAccountDto bankAccountDto) { var company = await bankAccountRepository.Context.Companies.OrderBy(c => c.Id).LastOrDefaultAsync(); if (bankAccountDto.Id != 0) { var bankAccount = await bankAccountRepository.AllAsNoTracking().Where(ba => ba.Name == bankAccountDto.Name && ba.CompanyId == company.Id && ba.Id != bankAccountDto.Id).FirstOrDefaultAsync(); if (bankAccount is null) { bankAccountDto.IsValidBankAccount = true; } else { bankAccountDto.IsValidBankAccount = false; bankAccountDto.ErrorMassages.Add($"Съществува Име {bankAccount.Name}"); } } else { var bankAccount = await bankAccountRepository.AllAsNoTracking().Where(ba => ba.Name == bankAccountDto.Name && ba.CompanyId == company.Id).FirstOrDefaultAsync(); if (bankAccount is null) { bankAccountDto.IsValidBankAccount = true; } else { bankAccountDto.IsValidBankAccount = false; bankAccountDto.ErrorMassages.Add($"Съществува Име {bankAccount.Name}"); } } }
/// <inheritdoc /> public BankAccount GetAccountById(string accountId) { accountId = accountId ?? throw new ArgumentNullException($"{nameof(accountId)} cannot be null."); BankAccountDto bankAccountDto = repository.GetAccountById(accountId); return(bankAccountDto?.ToAccount()); }
/// <inheritdoc /> public void Add(BankAccountDto bankAccountDto) { var account = bankAccountDto.ToOrmBankAccount(); SetAccountForeignKeys(account); context.Entry(account).State = EntityState.Added; }
public BankAccountDto findByAccountNumber(string accountNumber) { var bankAccount = _iUnitOfWork.BankAccounts.findByAccountNumber(accountNumber); BankAccountDto bankAccountDto = _mapper.Map <BankAccountDto>(bankAccount); return(bankAccountDto); }
private static void ConfigureDtoMapper(this IServiceCollection services) { services.AddAutoMapper(config => { BankAccountDto.ApplyMappingConfiguration(config); UserDto.ApplyMappingConfiguration(config); BillDto.ApplyMappingConfiguration(config); }); }
public IActionResult Put([FromBody] BankAccountDto model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } return(Ok(_bankAccountService.Update(User.Identity.GetUserId(), model))); }
public async Task UpdateAsync(BankAccountDto dto) { var bank = await _bankAccountRepository.GetAsync(dto.BanAccountId); bank.SetCurrency(dto.Currency); bank.SetHexColor(dto.HexColor); bank.SetAccountName(dto.AccountName); bank.SetInitialBalance(dto.InitialBalance); await _bankAccountRepository.UpdateAsync(bank); }
public static BankAccount ToAccount(this BankAccountDto accountDto) { return((BankAccount)Activator.CreateInstance( AccountResolver.GetBankAccountType(accountDto.AccountType), accountDto.Id, accountDto.FirstName, accountDto.LastName, accountDto.Balance, accountDto.BonusPoints, accountDto.IsClosed)); }
public List <TransactionDto> TransactionHistoryOf(BankAccountDto bank) { using (var db = new BankSystemContext()) { var query = from transaction in db.Transactions where transaction.From.BankAccount.Id.Equals(bank.Id) || transaction.To.Id.Equals(bank.Id) select transaction; return(mapper.Map <List <TransactionDto> >(query.ToList())); } }
public void update(BankAccountDto bankAccountDto, long AcccountId) { BankAccount bankAccount = _mapper.Map <BankAccount>(bankAccountDto); bankAccount.Id = AcccountId; validUpdate(bankAccount); _iUnitOfWork.BankAccounts.Update(bankAccount); _iUnitOfWork.Complete(); }
public void CanCreateBankAccout() { //arrange var bankAccountDto = new BankAccountDto(); var service = InstantiateService(); //act service.CreateBankAccount(bankAccountDto); //assert _bankAccountRepository.Verify(g => g.Create(It.IsAny <BankAccount>()), Times.Once()); }
public async Task HandleAsync(UpdateBankAccount command) { var dto = new BankAccountDto { BanAccountId = command.BankAccountId, AccountName = command.BankAccountName, Currency = command.Currency, InitialBalance = command.InitialBalance, HexColor = command.HexColor }; await _bankAccountService.UpdateAsync(dto); }
public async Task <IActionResult> Create(BankAccountDto bankAccountDto) { await bankAccountService.ValidateBankAccount(bankAccountDto); if (ModelState.IsValid && bankAccountDto.IsValidBankAccount) { await bankAccountService.Create(bankAccountDto); return(RedirectToAction("Index")); } return(View(bankAccountDto)); }
public void TestInsertAndGet() { CrudProxy proxy = new BankAccountProxy(); BankAccountDto dto1 = this.GetBankAccount(); proxy.Insert(dto1); Assert.IsTrue(dto1.Uid > 0, "Uid must be > 0 after save."); BankAccountDto dto2 = (BankAccountDto)proxy.GetByUid(dto1.Uid); AssertEqual(dto1, dto2); }
public void CreateBankAccount(BankAccountDto bankAccountDto) { var bankAccount = new BankAccount() { ApplicationIdentityUserId = bankAccountDto.ApplicationUserId, Cash = 100, CreatedOn = DateTime.Now, Id = bankAccountDto.ApplicationUserId, BankAccountTypeId = bankAccountDto.BankAccountTypeId }; _bankAccountRepository.Create(bankAccount); }
public void PerformTransfer(BankAccountDto originBankAccountDto, BankAccountDto destinationBankAccountDto, decimal amount) { var scope = new TransactionScope(); using (scope) { var originAccount = _bankAccountRepository.FindByNumber(originBankAccountDto.Number); var destinationAccount = _bankAccountRepository.FindByNumber(destinationBankAccountDto.Number); _transferDomainService.PerformTransfer(originAccount, destinationAccount, amount); _bankAccountRepository.update(originAccount); _bankAccountRepository.update(destinationAccount); scope.Complete(); } }
/// <summary> /// Updates a bank account /// </summary> /// <param name="bankAccount"></param> /// <returns></returns> public async Task <int> UpdateAsync(BankAccountDto bankAccount) { var bankAccountEntity = await _ctx.BankAccounts.FindAsync(bankAccount.Number); if (bankAccountEntity == null) { return(0); } _mapper.Map(bankAccount, bankAccountEntity); bankAccountEntity.UpdatedAt = DateTime.UtcNow; return(await _ctx.SaveChangesAsync()); }
public static BankAccount ToOrmBankAccount(this BankAccountDto dto) { return(new BankAccount { AccountNumber = dto.Id, AccountType = new AccountType { Name = dto.AccountType }, Balance = dto.Balance, BonusPoints = dto.BonusPoints, IsClosed = dto.IsClosed }); }
private BankAccountDto GetBankAccount() { BankAccountDto dto = new BankAccountDto(); dto.Type = AccountType.Asset; dto.Name = "CBA " + System.Guid.NewGuid().ToString(); dto.DisplayName = dto.Name + " DisplayName"; dto.LedgerCode = Guid.NewGuid().ToString().Substring(0, 5); dto.IsActive = true; dto.BSB = "111-111"; dto.AccountNumber = "12345-6789"; dto.MerchantFeeAccountUid = _merchantFeeDto.Uid; return(dto); }
public ActionResult New() { var bankAccountDto = new BankAccountDto { Id = 0 }; var baViewModel = new BankAccountFormViewModel { ActionIndicator = 1, BankAccountDto = bankAccountDto, AccountDtos = _context.Accounts.ToList().Select(Mapper.Map <Account, AccountDto>) }; return(View("BankAccountForm", baViewModel)); }