예제 #1
0
        public ActionResult Create()
        {
            ViewBag.CategoryId = new SelectList(expenseCategorySvc.GetAll(), "Id", "Category");

            Expense _Expense = new Expense();
            _Expense.Date = DateTime.Today;
            return View(_Expense);
        }
예제 #2
0
        public ActionResult Create(Expense Expense, FormCollection collection)
        {
            if (ModelState.IsValid)
            {

                this.UpdateModel(Expense);


                svc.Save(Expense);

                return RedirectToAction("Details", new { id = Expense.Id });
            }
            ViewBag.CategoryId = new SelectList(expenseCategorySvc.GetAll(), "Id", "Category");
            return View(Expense);
        }
예제 #3
0
        public ActionResult Edit(int id, Expense Expense, FormCollection collection)
        {
            Expense _entity = svc.GetById(id);
            if (ModelState.IsValid)
            {
                _entity.Date = Convert.ToDateTime(collection["Date"]);
                _entity.Amount = Convert.ToDecimal(collection["Amount"]);
                _entity.Remark = collection["Remark"];
                _entity.CategoryId = int.Parse(collection["CategoryId"]);
                try
                {
                    svc.Update(_entity);
                }
                catch (Exception e)
                {

                }


                return RedirectToAction("Details", new { id = _entity.Id });
            }
            ViewBag.CategoryId = new SelectList(expenseCategorySvc.GetAll(), "Id", "Category", _entity.CategoryId);
            return View(_entity);
        }