public async Task <IActionResult> WalletInfo(WalletInfoRequestVM walletInfoRequestVM)
        {
            try
            {
                WalletInfoDTO walletInfoDTO = await WalletService.GetWalletInfo(walletInfoRequestVM.JMBG, walletInfoRequestVM.PASS);

                var walletInfoResponseVM = new WalletInfoResponseVM(
                    walletInfoDTO.JMBG,
                    walletInfoDTO.FirstName,
                    walletInfoDTO.LastName,
                    (short)walletInfoDTO.Bank,
                    walletInfoDTO.BankAccountNumber,
                    walletInfoDTO.Balance,
                    walletInfoDTO.IsBlocked,
                    walletInfoDTO.WalletCreationTime,
                    walletInfoDTO.MaxDeposit,
                    walletInfoDTO.UsedDeposit,
                    walletInfoDTO.MaxWithdraw,
                    walletInfoDTO.UsedWithdraw);
                ModelState.Clear();
                var walletInfoVM = new WalletInfoVM(walletInfoRequestVM, walletInfoResponseVM);
                ViewData["Success"] = "True";
                return(View(walletInfoVM));
            }
            catch (Exception ex)
            {
                ViewData["ErrorMessage"] = ex.Message;
                ViewData["Success"]      = "False";
                return(View());
            }
        }
        public async Task GetWalletInfoNewWalletSuccessTest()
        {
            try
            {
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password      = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

                //Act
                WalletInfoDTO wallet = await walletService.GetWalletInfo("0605996781029", password);


                //Assert

                Assert.IsNotNull(wallet, "Wallet must not be null");
                Assert.AreEqual("ime", wallet.FirstName, "FirstName must be 'ime'");
                Assert.AreEqual("prezime", wallet.LastName, "LastName must be 'prezime'");
                Assert.AreEqual("0605996781029", wallet.Jmbg, "Jmbg must be '0605996781029'");
                Assert.AreEqual((short)BankType.BrankoBank, wallet.BankType, $"BankType must be '{BankType.BrankoBank}'");
                Assert.AreEqual("123456789876543210", wallet.BankAccount, "BankAccount must be '123456789876543210'");
                Assert.AreEqual(0, wallet.Balance, "Balance must be 0 RSD");
                Assert.AreEqual(0, wallet.UsedDepositThisMonth, "UsedDepositThisMonth must be 0 RSD");
                Assert.AreEqual(0, wallet.UsedWithdrawThisMonth, "UsedWithdrawThisMonth must be 0 RSD");
                Assert.AreEqual(decimal.Parse(Configuration["MaximalDeposit"]), wallet.MaximalDeposit, $"MaximalDeposit must be {Configuration["MaximalDeposit"]} RSD");
                Assert.AreEqual(decimal.Parse(Configuration["MaximalWithdraw"]), wallet.MaximalWithdraw, $"MaximalWithdraw must be {Configuration["MaximalDeposit"]} RSD");
                Assert.AreEqual(0, wallet.TransactionDTOs.Count, "There must be no transactions on the wallet");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }
Exemple #3
0
        public async Task <WalletInfoDTO> GetWalletInfo(string jmbg, string password)
        {
            Wallet wallet = await CoreUnitOfWork.WalletRepository.GetFirstOrDefaultWithIncludes(
                wallet => wallet.Jmbg == jmbg,
                wallet => wallet.Transactions
                );

            if (wallet == null || !wallet.CheckPassword(password))
            {
                throw new ArgumentException($"No wallet for entered jmbg '{jmbg}' and password pair.");
            }

            wallet.CheckAndUpdateUsedDepositWithdraw();
            await CoreUnitOfWork.WalletRepository.Update(wallet);

            await CoreUnitOfWork.SaveChangesAsync();

            decimal maximalDeposit;
            decimal maximalWithdraw;
            bool    success = decimal.TryParse(Configuration["MaximalDeposit"], NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out maximalDeposit);

            if (!success)
            {
                throw new ArgumentException($"Couldn't cast {Configuration["MaximalDeposit"]} (MaximalDeposit) to decimal");
            }
            success = decimal.TryParse(Configuration["MaximalWithdraw"], NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite | NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out maximalWithdraw);
            if (!success)
            {
                throw new ArgumentException($"Couldn't cast {Configuration["MaximalWithdraw"]} (MaximalWithdraw) to decimal");
            }
            var walletInfoDTO = new WalletInfoDTO()
            {
                Jmbg                  = wallet.Jmbg,
                FirstName             = wallet.FirstName,
                LastName              = wallet.LastName,
                BankType              = (short)wallet.BankType,
                BankAccount           = wallet.BankAccount,
                Balance               = wallet.Balance,
                UsedDepositThisMonth  = wallet.UsedDepositThisMonth,
                MaximalDeposit        = maximalDeposit,
                UsedWithdrawThisMonth = wallet.UsedWithdrawThisMonth,
                MaximalWithdraw       = maximalWithdraw,
                IsBlocked             = wallet.IsBlocked,
                TransactionDTOs       = wallet.Transactions.Select(
                    transaction => new TransactionDTO()
                {
                    Amount              = transaction.Amount,
                    Destination         = transaction.Destination,
                    Source              = transaction.Source,
                    TransactionDateTime = transaction.TransactionDateTime,
                    Type          = (short)transaction.Type,
                    WalletBalance = transaction.WalletBalance
                }
                    ).ToList()
            };

            return(walletInfoDTO);
        }
        public async Task <IActionResult> WalletInfo(WalletInfoRequestVM walletInfoRequestVM)
        {
            try
            {
                WalletInfoDTO walletInfoDTO = await WalletService.GetWalletInfo(walletInfoRequestVM.Jmbg, walletInfoRequestVM.Password);

                WalletInfoResponseVM walletInfoResponseVM =
                    new WalletInfoResponseVM()
                {
                    Jmbg                  = walletInfoDTO.Jmbg,
                    FirstName             = walletInfoDTO.FirstName,
                    LastName              = walletInfoDTO.LastName,
                    BankType              = EnumMapper.MapBankType(walletInfoDTO.BankType),
                    BankAccount           = walletInfoDTO.BankAccount,
                    Balance               = walletInfoDTO.Balance,
                    UsedDepositThisMonth  = walletInfoDTO.UsedDepositThisMonth,
                    MaximalDeposit        = walletInfoDTO.MaximalDeposit,
                    UsedWithdrawThisMonth = walletInfoDTO.UsedWithdrawThisMonth,
                    MaximalWithdraw       = walletInfoDTO.MaximalWithdraw,
                    IsBlocked             = walletInfoDTO.IsBlocked,
                    TransactionVMs        = walletInfoDTO.TransactionDTOs.Select(
                        transaction => new TransactionResposneVM()
                    {
                        Inflow              = (EnumMapper.MapTransactionTypeFlow(transaction.Type) == "Inflow" ? transaction.Amount : 0M),
                        Outflow             = (EnumMapper.MapTransactionTypeFlow(transaction.Type) == "Outflow" ? transaction.Amount : 0M),
                        Destination         = transaction.Destination,
                        Source              = transaction.Source,
                        TransactionDateTime = transaction.TransactionDateTime,
                        Type          = EnumMapper.MapTransactionType(transaction.Type),
                        WalletBalance = transaction.WalletBalance
                    }
                        ).OrderByDescending(t => t.TransactionDateTime).ToList()
                };
                ModelState.Clear();
                return(View(new WalletInfoPageVM()
                {
                    WalletInfoResponseVM = walletInfoResponseVM
                }));
            }
            catch (Exception ex)
            {
                ViewData["IsSuccessful"] = "no";
                ViewData["ErrorMessage"] = ex.Message;

                return(View());
            }
        }
        public async Task GetWalletInfoWithDepositAndWithdrawSuccessTest()
        {
            try
            {
                //Arrange
                var    walletService = new WalletService(CoreUnitOfWork, BankRoutingService, Configuration, FeeService);
                string password      = await walletService.CreateWallet("ime", "prezime", "0605996781029", (short)BankType.BrankoBank, "1234", "123456789876543210");

                await walletService.Deposit("0605996781029", password, 100000M);

                await walletService.Withdraw("0605996781029", password, 50000M);

                //Act
                WalletInfoDTO wallet = await walletService.GetWalletInfo("0605996781029", password);


                //Assert

                Assert.IsNotNull(wallet, "Wallet must not be null");
                Assert.AreEqual("ime", wallet.FirstName, "FirstName must be 'ime'");
                Assert.AreEqual("prezime", wallet.LastName, "LastName must be 'prezime'");
                Assert.AreEqual("0605996781029", wallet.Jmbg, "Jmbg must be '0605996781029'");
                Assert.AreEqual((short)BankType.BrankoBank, wallet.BankType, $"BankType must be '{BankType.BrankoBank}'");
                Assert.AreEqual("123456789876543210", wallet.BankAccount, "BankAccount must be '123456789876543210'");
                Assert.AreEqual(50000M, wallet.Balance, "Balance must be 0 RSD");
                Assert.AreEqual(100000M, wallet.UsedDepositThisMonth, "UsedDepositThisMonth must be 0 RSD");
                Assert.AreEqual(50000M, wallet.UsedWithdrawThisMonth, "UsedWithdrawThisMonth must be 0 RSD");
                Assert.AreEqual(decimal.Parse(Configuration["MaximalDeposit"]), wallet.MaximalDeposit, $"MaximalDeposit must be {Configuration["MaximalDeposit"]} RSD");
                Assert.AreEqual(decimal.Parse(Configuration["MaximalWithdraw"]), wallet.MaximalWithdraw, $"MaximalWithdraw must be {Configuration["MaximalDeposit"]} RSD");
                Assert.AreEqual(2, wallet.TransactionDTOs.Count, "There must be two transactions on the wallet");

                Assert.AreNotEqual(null, wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Deposit), $"Tranasction of type {TransactionType.Deposit} must exist on the wallet");
                Assert.AreEqual(100000M, wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Deposit).Amount, $"Deposit transaction amount must be 100000.");
                Assert.AreEqual(BankType.BrankoBank.ToString(), wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Deposit).Source, $"Source of the transaction should be {BankType.BrankoBank}.");
                Assert.AreEqual("0605996781029", wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Deposit).Destination, $"Destination of the transaction should be 0605996781029.");

                Assert.AreNotEqual(null, wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Withdraw), $"Tranasction of type {TransactionType.Withdraw} must exist on the wallet");
                Assert.AreEqual(50000M, wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Withdraw).Amount, $"Withdraw transaction amount must be 50000.");
                Assert.AreEqual(BankType.BrankoBank.ToString(), wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Withdraw).Destination, $"Source of the transaction should be {BankType.BrankoBank}.");
                Assert.AreEqual("0605996781029", wallet.TransactionDTOs.FirstOrDefault(transaction => transaction.Type == (short)TransactionType.Withdraw).Source, $"Destination of the transaction should be 0605996781029.");
            }
            catch (Exception ex)
            {
                Assert.Fail("Unexpected error: " + ex.Message);
            }
        }