public IActionResult ChangeBalance(ChangeBalanceViewModel model)
        {
            if (ModelState.IsValid)
            {
                switch (model.Mode)
                {
                case "withdraw":
                    model.Message = _repository.Withdraw(model.Account, model.Amount);
                    break;

                case "deposit":
                    model.Message = _repository.Deposit(model.Account, model.Amount);
                    break;
                }
            }
            return(View(model));
        }
Beispiel #2
0
        public async Task <ActionResult> ManageBalance(ChangeBalanceViewModel model)
        {
            if (ModelState.IsValid)
            {
                //add the value to the balance
                var manager     = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
                var currentUser = manager.FindById(User.Identity.GetUserId());
                currentUser.Balance = currentUser.Balance + model.AddBalance;
                var result = await manager.UpdateAsync(currentUser);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", new { Message = ManageMessageId.ChangeBalanceSuccess }));
                }
                return(View(model));
            }
            else
            {
                return(View(model));
            }
        }
        public IActionResult Index()
        {
            var model = new ChangeBalanceViewModel();

            return(View("ChangeBalance", model));
        }