Ejemplo n.º 1
0
        public ActionResult Create(TodoItemEditModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Priority = new SelectList(Enumerable.Range(1, 4), "Priority");
                ViewBag.Status = new SelectList(_db.Status, "Id", "Description");
                return View(model);
            }

            var todo = new TodoItem()
            {
                Title = model.Title,
                IsDone = model.IsDone,
                Priority = model.Priority,
                Description = model.Description,
                Deadline = model.Deadline,
                MasterSiteId = model.MastersiteId
            };

            _db.TodoItems.Add(todo);
            _db.SaveChanges();

            return RedirectToAction("Index");
        }
Ejemplo n.º 2
0
        public ActionResult Edit(int id, TodoItemEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            var todo = _db.TodoItems.SingleOrDefault(x => x.Id.Equals(id));
            if (todo == null)
            {
                return HttpNotFound();
            }

            todo.Title = model.Title;
            todo.Description = model.Description;
            todo.Deadline = model.Deadline;
            todo.IsDone = model.IsDone;

            _db.SaveChanges();

            return RedirectToAction("Index", new { id = id });
        }