Ejemplo n.º 1
0
        public ActionResult AddExpense(ExpenseAddViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.Expense.ExpenseId != 0)
                {
                    //update
                    var expense = _expenseManager.Get(e => e.ExpenseId == model.Expense.ExpenseId);
                    expense.ExpenseName        = model.Expense.ExpenseName;
                    expense.ExpenseDescription = model.Expense.ExpenseDescription;
                    expense.ExpenseAmount      = model.Expense.ExpenseAmount;
                    expense.DateTime           = model.Expense.DateTime;
                    expense.CategoryId         = model.Expense.CategoryId;
                    _expenseManager.Update(expense);
                }

                else
                {
                    //add
                    _expenseManager.Add(model.Expense);
                }
            }

            else
            {
                ViewBag.Message = "Model yanlış";
                return(View());
            }

            return(RedirectToAction("ListExpense"));
        }