コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }