// The id parameter name should match the DataKeyNames value set on the control
        public void GridViewCategories_DeleteItem(int categoryId)
        {
            TodoDbEntities context = new TodoDbEntities();
            Category category = context.Categories.Find(categoryId);

            context.Categories.Remove(category);
            context.SaveChanges();
        }
        public void InsertCategory(Category category)
        {
            TodoDbEntities context = new TodoDbEntities();
            context.Categories.Add(category);

            context.SaveChanges();

            this.GridViewCategories.DataBind();
            this.GridViewTodos.DataBind();
        }
        // The id parameter name should match the DataKeyNames value set on the control
        public void GridViewCategories_UpdateItem(int categoryId)
        {
            // Load the item here, e.g. item = MyDataLayer.Find(id);
            TodoDbEntities context = new TodoDbEntities();
            Category category = context.Categories.Find(categoryId);
            if (category == null)
            {
                // The item wasn't found
                ModelState.AddModelError("", String.Format("Category with id {0} was not found", categoryId));
                return;
            }
            TryUpdateModel(category);
            if (ModelState.IsValid)
            {
                context.Entry(category).State = EntityState.Modified;
                context.SaveChanges();
            }

            this.GridViewTodos.DataBind();
        }
        public void InsertTodoItem(TodoItem todo)
        {
            TodoDbEntities context = new TodoDbEntities();
            context.TodoItems.Add(todo);

            context.SaveChanges();

            this.GridViewTodos.DataBind();
            this.GridViewCategories.DataBind();
        }
        // The id parameter name should match the DataKeyNames value set on the control
        public void GridViewTodos_DeleteItem(int todoId)
        {
            TodoDbEntities context = new TodoDbEntities();
            TodoItem todo = context.TodoItems.Find(todoId);

            context.TodoItems.Remove(todo);
            context.SaveChanges();
        }