Example #1
0
        public async Task <IActionResult> EditNeed(EditViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _itemGenerator.EditNeedAndPushToDbAsync(model);

                    // I must get the amount changed after the edit to update user money values
                    decimal amountChanged = model.PreviousAmount - model.Amount;

                    // Now I update user money values to be accurate.
                    await _userEditor.AddCurrentMoney(amountChanged);

                    await _userEditor.SubtractFromAllTimeSpent(amountChanged);

                    await _userEditor.AddBudgetedForNeeds(amountChanged);

                    return(RedirectToAction("Index", "Dashboard"));
                }
                catch
                {
                    return(BadRequest());
                }
            }
            return(BadRequest());
        }
        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());
        }