public async Task <IActionResult> Add(IFormCollection model)
        {
            var budget = new Budget {
                Period = DateTime.Now
            };

            _repo.Add <Budget>(budget);

            foreach (var item in model.Keys)
            {
                if (item != "__RequestVerificationToken")
                {
                    var mapper = new BudgetCategoryMapper()
                    {
                        BudgetId   = budget.Id,
                        CategoryId = Guid.Parse(item.ToString()),
                        Amount     = model[item].ToString() == "" ? 0 : float.Parse(model[item].ToString())
                    };

                    _repo.Add <BudgetCategoryMapper>(mapper);
                }
            }

            if (await _repo.SaveAll())
            {
                return(RedirectToAction("Index"));
            }

            return(View());
        }
Пример #2
0
        public async Task <IActionResult> Add(Category model)
        {
            if (ModelState.IsValid)
            {
                model.Id = Guid.NewGuid();
                _repo.Add <Category>(model);

                if (await _repo.SaveAll())
                {
                    return(RedirectToAction("Index"));
                }
            }

            return(View());
        }
Пример #3
0
        public async Task <IActionResult> Add(Saving model)
        {
            if (ModelState.IsValid)
            {
                _repo.Add <Saving>(model);

                if (await _repo.SaveAll())
                {
                    return(RedirectToAction("Details", "SavingsGoal", new { id = model.SavingsGoalId }));
                }

                throw new Exception("Something went wrong trying to add saving");
            }

            return(View());
        }
Пример #4
0
        public async Task <IActionResult> Add(SavingsGoal model)
        {
            if (ModelState.IsValid)
            {
                var goals = await _repo.GetList <SavingsGoal>();

                if (!goals.Any())
                {
                    model.IsPinned = true;
                }

                _repo.Add <SavingsGoal>(model);

                if (await _repo.SaveAll())
                {
                    return(RedirectToAction("Goals"));
                }

                throw new Exception("Something went wrong, trying to add new Savings Goal");
            }

            return(View(model));
        }
Пример #5
0
        public async Task <IActionResult> Add(ExpenseViewModel model)
        {
            if (ModelState.IsValid)
            {
                var expense = new Expense();

                expense.Amount      = model.Amount;
                expense.CategoryId  = model.CategoryId;
                expense.Date        = model.Date;
                expense.Description = model.Description;

                _repo.Add(expense);

                if (await _repo.SaveAll())
                {
                    return(RedirectToAction("Index"));
                }
            }

            model.Categories = await _repo.GetList <Category>();

            return(View(model));
        }