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));
            }
        }
Example #2
0
        public async Task <IActionResult> AddNeed(AddViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _itemGenerator.CreateNeedAndPushToDbAsync(model);

                    // Now I update user money values to be accurate.
                    await _userEditor.SubtractCurrentMoney(model.Amount);

                    await _userEditor.SubtractBudgetedForNeeds(model.Amount);

                    await _userEditor.AddToAllTimeSpent(model.Amount);

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