示例#1
0
        // GET CREATE EXPENSE
        public ViewResult Create(int ClientID)
        {
            var frequencies = clientsRepository.Frequencies.ToList();

            // create view model
            var viewModel = new ExpenseFormViewModel
            {
                Frequencies = new SelectList(frequencies, "FrequencyID", "FrequencyName"),
                clientId = ClientID
            };

            return View("Edit", viewModel);
        }
示例#2
0
        public ActionResult Edit(ExpenseFormViewModel expenseForm)
        {
            var expense = Mapper.Map<ExpenseFormViewModel, Expense>(expenseForm);

            if (ModelState.IsValid)
            {
                clientsRepository.SaveExpense(expense);
                TempData["message"] = "Expense: " + expense.ExpenseName + " has been saved.";
                return RedirectToAction("List", "LegalFinance", new { expense.ClientId });
            }
            else // validation error, so redisplay the same view
            {
                expenseForm.Frequencies = new SelectList(clientsRepository.Frequencies.ToList(), "FrequenciesID", "FrequencyName", expenseForm.FrequencyID);
                return View("Edit", expenseForm);
            }
        }