public ActionResult Create([Bind(Include = "ID,Name,Category")] TodoList todoList)
        {
            string userID = ApplicationUser.GetCurrentUserID();
            TodoListCategory cat = db.TodoListCategories.Find(todoList.Category.ID);
            if (cat == null || cat.Owner.Id != userID)
            {
                // TODO: Error message for invalid category
                ViewBag.Categories = TodoListCategory.GetCurrentUserCategories(db);
                return View(todoList);
            }
            todoList.Category = cat;
            ModelState.Clear();
            TryValidateModel(todoList);

            if (ModelState.IsValid)
            {
                db.TodoLists.Add(todoList);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            // TODO: Error message for failed validation
            ViewBag.Categories = TodoListCategory.GetCurrentUserCategories(db);
            return View(todoList);
        }
Exemple #2
0
        // GET: My
        public ActionResult Index()
        {
            TodoListCategory[] myCats = TodoListCategory.GetCurrentUserCategories();
            JsonString         jStr   = JsonString.FromObject(myCats);

            return(View(jStr));
        }
 // GET: TodoLists/Create
 public ActionResult Create()
 {
     ViewBag.Categories = TodoListCategory.GetCurrentUserCategories(db);
     return View();
 }