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

                    decimal amountChanged = model.PreviousAmount - model.Amount;

                    await _userEditor.AddCurrentMoney(amountChanged);

                    await _userEditor.SubtractFromAllTimeSpent(amountChanged);

                    await _userEditor.AddBudgetedForSavings(amountChanged);

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

            return(BadRequest());
        }
        public async Task <IActionResult> AddPaycheck(AddViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _itemGenerator.CreatePaycheckAndPushToDbAsync(model);

                    await _userEditor.AddCurrentMoney(model.Amount);

                    await _userEditor.AddToAllTimeEarned(model.Amount);

                    await _userEditor.AddBudgetedForNeeds(model.Amount * .5m);

                    await _userEditor.AddBudgetedForWants(model.Amount * .3m);

                    await _userEditor.AddBudgetedForSavings(model.Amount * .2m);

                    return(RedirectToAction("Index", "Dashboard"));
                }
                catch
                {
                    return(BadRequest());
                }
            }
            return(BadRequest());
        }
Exemple #3
0
        public async Task <IActionResult> TransferFromWants(TransferViewModel model)
        {
            if (ModelState.IsValid)
            {
                await _userEditor.SubtractBudgetedForWants(model.TransferToSavings + model.TransferToNeeds);

                await _userEditor.AddBudgetedForNeeds(model.TransferToNeeds);

                await _userEditor.AddBudgetedForSavings(model.TransferToSavings);

                return(RedirectToAction("Index", "Dashboard"));
            }
            return(View(model));
        }