Esempio n. 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;
            }
        }
        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");
     }
 }
 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");
     }
 }
        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");
            }
        }
 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;
     }
 }
Esempio n. 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");
            }
        }