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> 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());
        }
        public async Task <IActionResult> TransferFromSavings(TransferViewModel model)
        {
            if (ModelState.IsValid)
            {
                await _userEditor.SubtractBudgetedForSavings(model.TransferToWants + model.TransferToNeeds);

                await _userEditor.AddBudgetedForNeeds(model.TransferToNeeds);

                await _userEditor.AddBudgetedForWants(model.TransferToWants);

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