Esempio n. 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());
        }