public ActionResult Create([Bind(Include = "ID,Name,Description,DueDate,Importance,List")] Todo todo) { string userID = ApplicationUser.GetCurrentUserID(); TodoList list = db.TodoLists.Find(todo.List.ID); if (list == null || list.Category.Owner.Id != userID) { // TODO: Error message for invalid list ViewBag.TodoLists = TodoList.GetCurrentUserLists(); return(View(todo)); } todo.List = list; ModelState.Clear(); TryValidateModel(todo); if (ModelState.IsValid) { db.Todos.Add(todo); db.SaveChanges(); return(RedirectToAction("Index")); } // TODO: Error message for failed validation ViewBag.TodoLists = TodoList.GetCurrentUserLists(); return(View(todo)); }
// GET: Todos/Create public ActionResult Create() { ViewBag.TodoLists = TodoList.GetCurrentUserLists(); return(View()); }