Example #1
0
        public void ConstructorShouldCreate_AddFundsViewModel_WithoutParams()
        {
            // Act & Assert
            var addFundsViewModel = new AddFundsViewModel();

            Assert.IsInstanceOf <AddFundsViewModel>(addFundsViewModel);
        }
Example #2
0
        public Result AddFunds(AddFundsViewModel user)
        {
            float balance = repo.GetBalance(user.ID);

            if (balance == -1)
            {
                return(new Result
                {
                    Error = "User not found!"
                });
            }

            float sum = balance + user.Amount;

            if (sum < 0)
            {
                return(new Result
                {
                    Error = "Balance not enough!"
                });
            }

            repo.SaveNewBalance(user.ID, sum);

            return(new Result {
            });
        }
Example #3
0
        public void AddFundsViewModel_Should_Set_Properties_Correctly_With_CorrectData()
        {
            // Arrange
            decimal amount            = 1m;
            var     addFundsViewModel = new AddFundsViewModel()
            {
                Amount = amount
            };

            // Act & Assert
            Assert.AreEqual(amount, addFundsViewModel.Amount);
        }
Example #4
0
        public ActionResult AddFunds(AddFundsViewModel addFundsViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(addFundsViewModel));
            }

            var userId = this.loggedInUser.GetUserId();
            var amount = addFundsViewModel.Amount;

            this.userService.TopUpUserBalance(userId, amount);
            TempData["Success"] = amount + " deposited successfully!";
            return(RedirectToAction("Index"));
        }
Example #5
0
        public async Task <IActionResult> WithdrawFunds()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                await _signInManager.SignOutAsync();

                return(RedirectToAction("Index", "Home", new { area = "" }));
            }

            var model = new AddFundsViewModel()
            {
                CurrentBalance = user.Currency
            };

            return(View(model));
        }
Example #6
0
        public async Task <IActionResult> WithdrawFunds(AddFundsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                await _signInManager.SignOutAsync();

                return(RedirectToAction("Index", "Home", new { area = "" }));
            }

            var ouruser = user.Id;
            await _users.WithdrawFundsAsync(ouruser, model.Amount);


            return(RedirectToAction(nameof(WithdrawFunds)));
        }
Example #7
0
 public Result AddFunds(AddFundsViewModel model)
 {
     return(bal.AddFunds(model));
 }