public ActionResult Save(ExpenseCategoryVM view)
        {
            ModelState.Remove("Id");
            if (ModelState.IsValid)
            {
                if (view.Id == 0)
                {
                    _expenseCategoryRepository.AddToDatabase(view.MapToModel());
                }
                else
                {
                    _expenseCategoryRepository.UpdateInDatabase(view.MapToModel(), view.Id);
                }

                _expenseCategoryRepository.Save();
            }
            return(RedirectToAction("Index"));
        }
Example #2
0
        public IActionResult EditExpenseCategory(ExpenseCategory model)
        {
            if (ModelState.IsValid)
            {
                _expenseCatRepo.Save(model);
                TempData["message"] = $"{model.Name} has been saved";
                return(RedirectToAction("ExpenseCategories"));
            }
            else
            {
                if (model.ID == 0)
                {
                    ViewBag.FormTitle = "Create Expense Category";
                }
                else
                {
                    ViewBag.FormTitle = "Edit Expense Category";
                }

                return(View(model));
            }
        }