protected void InsertCategory_Command(object sender, CommandEventArgs e) { TodosEntities context = new TodosEntities(); var selectedCategoryName = this.NewCategoryName.Text; Category newCategory = new Category() { Name = selectedCategoryName }; context.Categories.Add(newCategory); context.SaveChanges(); this.GridViewCategories.DataBind(); }
protected void InsertTodo_Command(object sender, CommandEventArgs e) { TodosEntities context = new TodosEntities(); int selectedCategoryId = (int)this.GridViewCategories.SelectedDataKey.Value; var selectedCategory = context.Categories.FirstOrDefault( c => c.Id == selectedCategoryId); TodoList todoList = new TodoList() { Title = this.NewTodoTitle.Text, Body = this.NewTodoBody.Text }; selectedCategory.TodoLists.Add(todoList); context.SaveChanges(); this.GridViewTodoLists.DataBind(); }