// The id parameter name should match the DataKeyNames value set on the control public void CategoriesList_DeleteItem(int id) { var context = new TodoListEntities(); using (context) { Category category = context.Categories.FirstOrDefault(c => c.Id == id); context.Categories.Remove(category); context.SaveChanges(); } }
public void CategoriesList_InsertItem() { var item = new TotoList.Category(); TryUpdateModel(item); if (ModelState.IsValid) { var context = new TodoListEntities(); using (context) { context.Categories.Add(item); context.SaveChanges(); } } }
// The id parameter name should match the DataKeyNames value set on the control public void CategoriesList_UpdateItem(int id) { var context = new TodoListEntities(); using (context) { Category category = context.Categories.Find(id); if (category == null) { // The item wasn't found ModelState.AddModelError("", String.Format("Product with id {0} was not found", id)); return; } TryUpdateModel(category); if (ModelState.IsValid) { context.Entry(category).State = EntityState.Modified; context.SaveChanges(); } } }
// The id parameter name should match the DataKeyNames value set on the control public void TodosListView_DeleteItem(int id) { var context = new TodoListEntities(); using (context) { var todo = context.Todos.FirstOrDefault(t => t.Id == id); context.Todos.Remove(todo); context.SaveChanges(); } }
public void TodosListView_InsertItem() { var item = new TotoList.Todo(); TryUpdateModel(item); if (ModelState.IsValid) { item.LastChangeDate = DateTime.Now; var context = new TodoListEntities(); using (context) { context.Todos.Add(item); context.SaveChanges(); } } }
// The id parameter name should match the DataKeyNames value set on the control public void TodosListView_UpdateItem(int id) { var context = new TodoListEntities(); using (context) { Todo todo = context.Todos.Find(id); if (todo == null) { // The item wasn't found ModelState.AddModelError("", String.Format("Product with id {0} was not found", id)); return; } TryUpdateModel(todo); if (ModelState.IsValid) { todo.LastChangeDate = DateTime.Now; context.Entry(todo).State = EntityState.Modified; context.SaveChanges(); } } }