// The id parameter name should match the DataKeyNames value set on the control
        public void ListViewTodos_UpdateItem(int Id)
        {
            var db = new TodoDbContext();
            TodoTask item = null;
            var itemData = db.Todos.Find(Id);

            if (itemData == null)
            {
                // The item wasn't found
                ModelState.AddModelError("", String.Format("Item with id {0} was not found", Id));
                return;
            }

            item = new TodoTask()
            {
                Title = itemData.Title,
                Body = itemData.Body,
                LastModified = DateTime.Now,
                CategoryId = itemData.CategoryId
            };
            TryUpdateModel(item);
            if (ModelState.IsValid)
            {
                itemData.Title = item.Title;
                itemData.Body = item.Body;
                itemData.LastModified = item.LastModified;
                itemData.CategoryId = item.CategoryId;
                db.SaveChanges();
            }
        }
 public void ListViewTodos_InsertItem()
 {
     var db = new TodoDbContext();
     var item = new TodoTask();
     TryUpdateModel(item);
     if (ModelState.IsValid)
     {
         var itemData = new TodoTask()
         {
             Title = item.Title,
             Body = item.Body,
             LastModified = DateTime.Now,
             CategoryId = item.CategoryId
         };
         db.Todos.Add(itemData);
         db.SaveChanges();
     }
 }