Esempio n. 1
0
 // GET: /Expense/Edit
 public ActionResult Edit(int id)
 {
     var expense = expenseRepository.GetById(id);
     var viewModel = new ExpenseFormModel(expense);
     var categories = categoryRepository.GetAll();
     viewModel.Category = categories.ToSelectListItems(expense.Category.CategoryId);
     return View(viewModel);
 }
Esempio n. 2
0
 public ActionResult Create()
 {
     var viewModel = new ExpenseFormModel();
     var categories = categoryRepository.GetAll();
     viewModel.Category = categories.ToSelectListItems(-1);
     viewModel.Date = DateTime.Today;
     return View(viewModel);
 }
Esempio n. 3
0
        public ActionResult Save(ExpenseFormModel form)
        {
            Category category = categoryRepository.GetById(form.CategoryId);

            if (ModelState.IsValid)
            {
                var command = new CreateOrUpdateExpenseCommand
                {
                    ExpenseId = form.ExpenseId,
                    Category = category,
                    Date = form.Date,
                    Transaction = form.Transaction,
                    Amount = form.Amount
                };
                var result = commandBus.Submit(command);
                if (result.Success) return RedirectToAction("Index");
            }

            if (form.ExpenseId == 0)
                return View("Create", form);
            else
                return View("Edit", form);
        }