public async Task <IActionResult> EditPaycheck(EditViewModel model)
        {
            if (ModelState.IsValid)
            {
                try {
                    await _itemGenerator.EditPaycheckAndPushToDbAsync(model);

                    decimal amountChanged = model.PreviousAmount - model.Amount;

                    await _userEditor.SubtractCurrentMoney(amountChanged);

                    await _userEditor.SubtractBudgetedForNeeds(amountChanged * .5m);

                    await _userEditor.SubtractBudgetedForWants(amountChanged * .3m);

                    await _userEditor.SubtractBudgetedForSavings(amountChanged * .2m);

                    await _userEditor.SubtractFromAllTimeEarned(amountChanged);

                    return(RedirectToAction("Index", "Dashboard"));
                }
                catch
                {
                    return(BadRequest());
                }
            }
            else
            {
                return(View(model));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> AddWant(AddViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _itemGenerator.CreateWantAndPushToDbAsync(model);

                    await _userEditor.SubtractCurrentMoney(model.Amount);

                    await _userEditor.SubtractBudgetedForWants(model.Amount);

                    await _userEditor.AddToAllTimeSpent(model.Amount);

                    return(RedirectToAction("Index", "Dashboard"));
                }
                catch
                {
                    return(BadRequest());
                }
            }
            return(BadRequest());
        }