예제 #1
0
        protected void LinkButtonSaveToDo_Click(object sender, EventArgs e)
        {
            try
            {
                int? toDoId = Convert.ToInt32(Request.Params["toDoId"]);

                if (toDoId != null && toDoId > 0)
                {
                    ToDoListEntities context = new ToDoListEntities();
                    ToDo toDo = context.ToDos.Find(toDoId);

                    if (toDo != null)
                    {
                        toDo.Title = this.TextBoxToDoTitle.Text;
                        toDo.Body = this.TextBoxBody.Text;
                        toDo.CaregoryId = int.Parse(this.ListBoxCategories.SelectedValue);

                        context.SaveChanges();
                        Response.Redirect("~/ManageToDos.aspx");
                    }
                }
            }
            catch (Exception ex)
            {
                this.LiteralErrorMessage.Visible = true;
                this.LiteralErrorMessage.Text = ex.Message;
            }
        }
예제 #2
0
        protected void LinkButtonSaveQuestion_Click(object sender, EventArgs e)
        {
            try
            {
                int? categoryId = Convert.ToInt32(Request.Params["CategoryId"]);

                if (categoryId != null && categoryId > 0)
                {
                    ToDoListEntities context = new ToDoListEntities();
                    Category Category = context.Categories.Find(categoryId);

                    if (Category != null)
                    {
                        Category.Name = this.TextBoxCategoryName.Text;
                        context.SaveChanges();
                        Response.Redirect("~/ManageCategories.aspx");
                    }
                }
            }
            catch (Exception ex)
            {
                this.TextBoxErrorMessage.Visible = true;
                this.TextBoxErrorMessage.Text = ex.Message;
            }
        }
 protected void LinkButtonSaveCategory_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         ToDoListEntities context = new ToDoListEntities();
         Category Category = new Category();
         Category.Name = this.TextBoxCategoryName.Text;
         context.Categories.Add(Category);
         context.SaveChanges();
         Response.Redirect("~/ManageCategories.aspx");
     }
 }
예제 #4
0
 protected void LinkButtonSaveToDo_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         ToDoListEntities context = new ToDoListEntities();
         ToDo toDo = new ToDo();
         toDo.Title = this.TextBoxToDoTitle.Text;
         toDo.Body = this.TextBoxBody.Text;
         toDo.DateModified = DateTime.Now;
         toDo.CaregoryId = int.Parse(this.ListBoxCategories.SelectedValue);
         context.ToDos.Add(toDo);
         context.SaveChanges();
         Response.Redirect("~/ManageToDos.aspx");
     }
 }
예제 #5
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            int? CategoryId = Convert.ToInt32(Request.Params["CategoryId"]);

            if (CategoryId != null && CategoryId > 0)
            {
                ToDoListEntities context = new ToDoListEntities();
                Category Category = context.Categories.Find(CategoryId);
                this.TextBoxCategoryName.Text = Category.Name;
            }
            else
            {
                Response.Redirect("~/ManageCategories.aspx");
            }
        }
예제 #6
0
 protected void LinkButtonDeleteToDo_Command(object sender, CommandEventArgs e)
 {
     try
     {
         var id = int.Parse(e.CommandArgument.ToString());
         ToDoListEntities context = new ToDoListEntities();
         ToDo toDo = context.ToDos.Find(id);
         context.ToDos.Remove(toDo);
         context.SaveChanges();
         Response.Redirect("~/ManageToDos.aspx");
     }
     catch (Exception ex)
     {
         this.LiteralErrorMessage.Visible = true;
         this.LiteralErrorMessage.Text = ex.Message;
     }
 }
예제 #7
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            int? toDoId = Convert.ToInt32(Request.Params["toDoId"]);

            if (toDoId != null && toDoId > 0)
            {
                ToDoListEntities context = new ToDoListEntities();
                ToDo toDo = context.ToDos.Find(toDoId);
                this.ListBoxCategories.DataSource = context.Categories.ToList();
                this.ListBoxCategories.DataTextField = "Name";
                this.ListBoxCategories.DataValueField = "Id";
                this.ListBoxCategories.DataBind();
                var categoryItem = this.ListBoxCategories.Items.FindByText(toDo.Category.Name);
                categoryItem.Selected = true;
                this.TextBoxToDoTitle.Text = toDo.Title;
                this.TextBoxBody.Text = toDo.Body;
            }
            else
            {
                Response.Redirect("~/ManageToDos.aspx");
            }
        }