Esempio n. 1
0
        public async Task <IActionResult> EditWant(EditViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    await _itemGenerator.EditWantAndPushToDbAsync(model);

                    decimal amountChanged = model.PreviousAmount - model.Amount;

                    await _userEditor.AddCurrentMoney(amountChanged);

                    await _userEditor.SubtractFromAllTimeSpent(amountChanged);

                    await _userEditor.AddBudgetedForWants(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));
        }
Esempio n. 4
0
        public async Task <IActionResult> TransferFromNeeds(TransferViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Now I update user money values to be accurate.
                await _userEditor.SubtractBudgetedForNeeds(model.TransferToSavings + model.TransferToWants);

                await _userEditor.AddBudgetedForWants(model.TransferToWants);

                await _userEditor.AddBudgetedForSavings(model.TransferToSavings);

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