コード例 #1
0
        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));
        }
コード例 #2
0
 // GET: Todos/Create
 public ActionResult Create()
 {
     ViewBag.TodoLists = TodoList.GetCurrentUserLists();
     return(View());
 }