Пример #1
0
        public ActionResult Create(int expenseId, int? userId)
        {
            var expense = Expenses.FetchById(expenseId);
            if(expense == null)
                return HttpNotFound();

            var model = new Models.ExpenseItemCreateAndEditModel(true, expense, Users.FetchAll());
            model.ExpenseItem = new Models.ExpenseItemModel(ExpenseItems.CreateNew(expense));
            model.ExpenseItem.CreatorUserId = userId;
            return View("CreateAndEdit", model);
        }
Пример #2
0
        public ActionResult Create(int expenseId, [Bind(Prefix = "ExpenseItem")] Models.ExpenseItemModel value)
        {
            var expense = Expenses.FetchById(expenseId);
            if (expense == null)
                return HttpNotFound();

            if (!ViewData.ModelState.IsValid)
            {
                var model = new Models.ExpenseItemCreateAndEditModel(true, expense, Users.FetchAll());
                model.ExpenseItem = value;
                return View("CreateAndEdit", model);
            }

            // apply to BO
            value.ApplyToBO(ExpenseItems.CreateNew(expense), Users);

            // save
            Context.SaveChanges();

            return RedirectToAction("Details", "Expenses", new { id = expense.Id });
        }
Пример #3
0
        public ActionResult Edit(int id)
        {
            var item = ExpenseItems.FetchById(id);
            if (item == null)
                return HttpNotFound();

            var model = new Models.ExpenseItemCreateAndEditModel(false, item.Expense, Users.FetchAll());
            model.ExpenseItem = new Models.ExpenseItemModel(item);
            return View("CreateAndEdit", model);
        }