Пример #1
0
 protected void ButtonEdit_Command(object sender, CommandEventArgs e)
 {
     this.PanelEditTodoList.Visible = true;
     this.ButtonEditTodoList.CommandArgument = e.CommandArgument.ToString();
     using (var context = new TodoListsEntities())
     {
         var todoToUpdate = context.TodoLists.Find(Convert.ToInt32(e.CommandArgument));
         this.TextBoxEditedTitle.Text = todoToUpdate.Title;
         this.TextBoxEditedText.Text = todoToUpdate.Text;
     }
 }
Пример #2
0
 protected void ButtonDeleteCategory_Click(object sender, EventArgs e)
 {
     using (var context = new TodoListsEntities())
     {
         var categoryToRemove = context.Categories.Find(int.Parse(this.ListBoxCategories.SelectedValue));
         context.TodoLists.RemoveRange(categoryToRemove.TodoLists);
         context.Categories.Remove(categoryToRemove);
         context.SaveChanges();
         Response.Redirect(Request.RawUrl);
     }
 }
Пример #3
0
        protected void ButtonEditCategory_Click(object sender, EventArgs e)
        {
            using (var context = new TodoListsEntities())
            {
                var category = context.Categories.Find(int.Parse(this.ListBoxCategories.SelectedValue));
                this.TextBoxCategoryName.Text = category.Name;
            }

            this.PanelInsertCategory.Visible = true;
            this.ButtonEditCategory.Visible = false;

            this.ButtonEditExistingCategory.Visible = true;
            this.ButtonSaveCategory.Visible = false;
        }
Пример #4
0
        private void CreateOrUpdateTodoList(bool create = false)
        {
            using (var context = new TodoListsEntities())
            {
                var category = context.Categories.Find(int.Parse(ListBoxCategories.SelectedValue));

                if (create)
                {
                    TodoList todoList = new TodoList();
                    todoList.Category = category;
                    todoList.Title = this.TextBoxTodoTitle.Text;
                    todoList.Text = this.TextBoxTodoText.Text;
                    todoList.LastChangeDate = DateTime.Now;

                    context.TodoLists.Add(todoList);
                    context.SaveChanges();
                }
                else
                {
                    int todoListId = int.Parse(this.ButtonEditTodoList.CommandArgument);
                    var todoToUpdate = context.TodoLists.Find(todoListId);
                    todoToUpdate.Title = this.TextBoxEditedTitle.Text;
                    todoToUpdate.Text = this.TextBoxEditedText.Text;
                    todoToUpdate.LastChangeDate = DateTime.Now;

                    context.SaveChanges();
                }

                this.ListViewTodoLists.DataBind();
            }
        }
Пример #5
0
        private void CreateOrUpdateCategory(bool create = true)
        {
            string categoryName = this.TextBoxCategoryName.Text;
            if (string.IsNullOrEmpty(categoryName))
            {
                return;
            }
            using (var context = new TodoListsEntities())
            {
                if (create)
                {

                    context.Categories.Add(new Category()
                    {
                        Name = categoryName
                    });

                    context.SaveChanges();

                }
                else
                {
                    var existingCategory = context.Categories.Find(int.Parse(this.ListBoxCategories.SelectedValue));
                    existingCategory.Name = this.TextBoxCategoryName.Text;
                    context.SaveChanges();
                }
            }

            this.ListBoxCategories.DataBind();
            this.PanelInsertCategory.Visible = false;
        }