public void ConstructorShouldCreate_AddFundsViewModel_WithoutParams() { // Act & Assert var addFundsViewModel = new AddFundsViewModel(); Assert.IsInstanceOf <AddFundsViewModel>(addFundsViewModel); }
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 { }); }
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); }
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")); }
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)); }
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))); }
public Result AddFunds(AddFundsViewModel model) { return(bal.AddFunds(model)); }