Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <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);
            }
        }
Exemplo n.º 3
0
        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));
            }
        }
Exemplo n.º 6
0
        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());
            }
        }
Exemplo n.º 7
0
        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.");
 }
Exemplo n.º 9
0
        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);
            }
        }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 11
0
        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());
        }
Exemplo n.º 13
0
        /// <inheritdoc />
        public void Add(BankAccountDto bankAccountDto)
        {
            var account = bankAccountDto.ToOrmBankAccount();

            SetAccountForeignKeys(account);

            context.Entry(account).State = EntityState.Added;
        }
Exemplo n.º 14
0
        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);
     });
 }
Exemplo n.º 16
0
        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()));
            }
        }
Exemplo n.º 20
0
        public void update(BankAccountDto bankAccountDto, long AcccountId)
        {
            BankAccount bankAccount = _mapper.Map <BankAccount>(bankAccountDto);

            bankAccount.Id = AcccountId;

            validUpdate(bankAccount);

            _iUnitOfWork.BankAccounts.Update(bankAccount);
            _iUnitOfWork.Complete();
        }
Exemplo n.º 21
0
        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());
        }
Exemplo n.º 22
0
        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);
        }
Exemplo n.º 23
0
        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);
        }
Exemplo n.º 25
0
        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());
        }
Exemplo n.º 28
0
 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));
        }