/**
         * <summary>
         * This event handler updates todo with the new completed state
         * </summary>
         *
         * @param {object} sender
         * @param {EventArgs} e
         * @returns {void}
         */
        protected void chkCompleted_CheckedChanged(object sender, EventArgs e)
        {
            // Get the clicked checkbox
            CheckBox chk = (CheckBox)sender;

            // Get the row
            GridViewRow gvr = (GridViewRow)chk.NamingContainer;
            var selectedRow = gvr.RowIndex;

            // get the selected StudentID using the Grid's DataKey collection
            int TodoID = Convert.ToInt32(TodoGridView.DataKeys[selectedRow].Values["TodoID"]);

            // Create a new Todo item
            Todo newTodo = new Todo();

            using (TodoConnection db = new TodoConnection())
            {
                // get the current student from EF DB
                newTodo = (from todo in db.Todos
                           where todo.TodoID == TodoID
                           select todo).FirstOrDefault();

                newTodo.Completed = chk.Checked;

                try
                {
                    db.SaveChanges();
                    Response.Redirect("/Todos/TodoList.aspx");
                }
                catch (Exception ex)
                {
                    // ...
                }
            }
        }
        protected void GetTodo()
        {
            // populate the form with existing data from the database
            int TodoID = Convert.ToInt32(Request.QueryString["TodoID"]);

            // connect to the EF DB
            using (TodoConnection db = new TodoConnection())
            {
                // populate a Todo object instance with the TodoID from the URL Parameter
                Todo updatedTodo = (from Todo in db.Todos
                                                where Todo.TodoID == TodoID
                                                select Todo).FirstOrDefault();

                // map the Todo properties to the form controls
                if (updatedTodo != null)
                {
                    TodoNameTextBox.Text = updatedTodo.TodoName;
                    TodoNotesTextBox.Text = updatedTodo.TodoNotes;
                    if (updatedTodo.Completed == true)
                        CompletedCheckbox.Checked = true;
                    else
                        CompletedCheckbox.Checked = false;
                }
            }
        }
        protected void GetTodo()
        {
            // connect to ef
            using (TodoConnection db = new TodoConnection())
            {
                // Query todo table using ef and linq
                var Todo = (from allTodo in db.Todos
                            select allTodo);

                //bind the results to the GridView
                TodoGridView.DataSource = Todo.ToList();
                TodoGridView.DataBind();
            }
        }
        /**
         * <summary>
         * This method gets the Todo data from the DB
         * </summary>
         *
         * @method GetTodos
         * @returns {void}
         */
        protected void GetTodos()
        {
            // connect to EF
            using (TodoConnection db = new TodoConnection())
            {
                string SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                // query the Todos Table using EF and LINQ
                var Todos = (from allTodos in db.Todos
                                select allTodos);

                // bind the result to the GridView
                TodosGridView.DataSource = Todos.AsQueryable().OrderBy(SortString).ToList();
                TodosGridView.DataBind();
            }
        }
        protected void GetToDo()
        {
            //Connect to Entity Framework
            using (TodoConnection db = new TodoConnection())
            {
                string SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                //Query the Students Table using Entity Framework and LINQ
                var toDo = (from allToDo in db.Todos
                                select allToDo);

                //Bind the results to the GridView
                TodoGridView.DataSource = toDo.ToList();
                TodoGridView.DataBind();
            }
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            // Use EF to connect to the server
            using (TodoConnection db = new TodoConnection())
            {
                // use the Todo model to create a new Todo object and
                // save a new record
                Todo newTodo = new Todo();

                int TodoID = 0;

                if (Request.QueryString.Count > 0) // our URL has a TodoID in it
                {
                    // get the id from the URL
                    TodoID = Convert.ToInt32(Request.QueryString["TodoID"]);

                    // get the current Todo from EF DB
                    newTodo = (from Todo in db.Todos
                                     where Todo.TodoID == TodoID
                                     select Todo).FirstOrDefault();
                }

                // add form data to the new Todo record
                newTodo.TodoName= TodoNameTextBox.Text;
                newTodo.TodoNotes = TodoNotesTextBox.Text;
                newTodo.Completed = CompletedCheckbox.Checked;

                // use LINQ to ADO.NET to add / insert new Todo into the database

                if (TodoID == 0)
                {
                    db.Todos.Add(newTodo);
                }

                // save our changes - also updates and inserts
                db.SaveChanges();

                // Redirect back to the updated Todos page
                Response.Redirect("~/Todo/TodoList.aspx");
            }
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            //Use Entity Framework to connect to the server
            using (TodoConnection db = new TodoConnection())
            {
                //Use the Student model to create a new student object and
                //Save a new record

                //Student newStudent = new Student();
                Todo newTodo = new Todo();

                int StudentID = 0;

                if (Request.QueryString.Count > 0) //Our URL has a StudentID in it
                {
                    //Get the StudentID from the URL
                    StudentID = Convert.ToInt32(Request.QueryString["StudentID"]);

                    //Get the current student from the Entity Framework Database
                    newTodo = (from student in db.Todos
                                  where student.TodoID == StudentID
                                  select student).FirstOrDefault();
                }

                //Add data to the new student record
                newTodo.TodoName = TodoNameTextBox.Text;
                newTodo.TodoNotes = TodoNotesTextBox.Text;

                //Use LINQ/ADO.NET to Add/Insert new student into the database
                if (StudentID == 0)
                {
                    db.Todos.Add(newTodo);
                }

                //Save our changes (also updates and inserts)
                db.SaveChanges();

                //Redirect back to the updated students page
                Response.Redirect("~/TodoList.aspx");
            }
        }
        protected void GetToDo()
        {
            //Populate the form with existing data from the database
            int toDoID = Convert.ToInt32(Request.QueryString["TodoID"]);

            //Connect to the Entity Framework Database
            using (TodoConnection db = new TodoConnection())
            {
                //Populate a student object instance with the StudentID from the URL Param
                Todo updatedStudent = (from student in db.Todos
                                          where student.TodoID == toDoID
                                          select student).FirstOrDefault();

                //Map the student properties to the from controls
                if (updatedStudent != null)
                {
                    TodoNameTextBox.Text = updatedStudent.TodoName;
                    TodoNotesTextBox.Text = updatedStudent.TodoNotes;
                }
            }
        }
        /**
         * <summary>
         * This method gets the ToDo data from the DB
         * </summary>
         *
         * @method GetToDo
         * @returns {void}
         */
        protected void GetTodo()
        {
            // populate teh form with existing data from the database
            int todoID = Convert.ToInt32(Request.QueryString["todoID"]);

            // connect to the EF DB
            using (TodoConnection db = new TodoConnection())
            {
                // populate a student object instance with the StudentID from the URL Parameter
                Todo updatedToDo = (from Todo in db.Todos
                                    where Todo.TodoID == todoID
                                    select Todo).FirstOrDefault();

                // map the to do properties to the form controls
                if (updatedToDo != null)
                {
                    NameTextBox.Text  = updatedToDo.TodoName;
                    NotesTextBox.Text = updatedToDo.TodoNotes;
                }
            }
        }
Exemple #10
0
        protected void GetToDo()
        {
            //Populate the form with existing data from the database
            int toDoID = Convert.ToInt32(Request.QueryString["TodoID"]);

            //Connect to the Entity Framework Database
            using (TodoConnection db = new TodoConnection())
            {
                //Populate a student object instance with the StudentID from the URL Param
                Todo updatedStudent = (from student in db.Todos
                                       where student.TodoID == toDoID
                                       select student).FirstOrDefault();

                //Map the student properties to the from controls
                if (updatedStudent != null)
                {
                    TodoNameTextBox.Text  = updatedStudent.TodoName;
                    TodoNotesTextBox.Text = updatedStudent.TodoNotes;
                }
            }
        }
        /**
         * <summary>
         * This method processes the todo delete functionality.
         * </summary>
         *
         * @method TodoDataList_DeleteCommand
         * @return {void}
         */
        protected void TodoDataList_DeleteCommand(object source, DataListCommandEventArgs e)
        {
            int TodoID = Convert.ToInt32(TodoDataList.DataKeys[e.Item.ItemIndex]);

            using (TodoConnection db = new TodoConnection())
            {
                // create object of the todo class and store the query string inside of it
                Todo deletedTodo = (from TodoRecords in db.Todos
                                    where TodoRecords.TodoID == TodoID
                                    select TodoRecords).FirstOrDefault();

                // remove the selected todo from the db
                db.Todos.Remove(deletedTodo);

                // save changes back to the db
                db.SaveChanges();

                // refresh
                this.GetTodos();
            }
        }
Exemple #12
0
        protected void ToDoGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int selectedRow = e.RowIndex;
            //get the select list id using the grids
            int toDoID = Convert.ToInt32(ToDoGridView.DataKeys[selectedRow].Values["toDoID"]);

            //Removing  the data
            using (TodoConnection db = new TodoConnection())
            {
                Todo deletedList = (from todoRecords in db.Todos
                                    where todoRecords.TodoID == toDoID
                                    select todoRecords).FirstOrDefault();

                //delete the selected todolist from the database
                db.Todos.Remove(deletedList);

                db.SaveChanges();
                //Refresh the grid
                this.GetList();
            }
        }
Exemple #13
0
        /**
         * <summary>
         * This method saves the todo on click
         * </summary>
         *
         * @method SaveButton_Click
         * @return {void}
         */
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            // connect to the server
            using (TodoConnection db = new TodoConnection())
            {
                // Use the todo model to create a new todo object and also save a new record
                Todo newTodo = new Todo();

                int TodoID = 0;

                if (Request.QueryString.Count > 0) // our URL has a TodoID in it
                {
                    // get the id from the URL
                    TodoID = Convert.ToInt32(Request.QueryString["TodoID"]);

                    // get the current todo from the database
                    newTodo = (from todo in db.Todos
                               where todo.TodoID == TodoID
                               select todo).FirstOrDefault();
                }

                // add data to the new todo record
                newTodo.TodoName  = TodoNameTextBox.Text;
                newTodo.TodoNotes = TodoNotesTextBox.Text;
                // newTodo.Completed = todoCheckBox.Checked;

                // insert new todo into the database
                if (TodoID == 0)
                {
                    db.Todos.Add(newTodo);
                }

                // save our changes
                db.SaveChanges();

                // redirect back to the updated todolist
                Response.Redirect("~/TodoList.aspx");
            }
        }
Exemple #14
0
        protected void TodoGridview_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //store what row was clicked
            int selectedRow = e.RowIndex;

            //get the selected TodoID using the grids DataKey Collection
            int TodoId = Convert.ToInt32(TodoGridview.DataKeys[selectedRow].Values["TodoID"]);

            //Use Ef to find select and remove the Todo
            using (TodoConnection db = new TodoConnection()) {
                //create object of the todo class and store the query in a string
                Todo deletedTodo = (from TodoRecords in db.Todos
                                    where TodoRecords.TodoID == TodoId
                                    select TodoRecords).FirstOrDefault();

                db.Todos.Remove(deletedTodo);

                db.SaveChanges();

                this.GetTodo();
            }
        }
Exemple #15
0
        /**
         * <summary>
         * This method gets the user data from the database using Todo id
         * </summary>
         *
         * @method GetTodoData
         * @returns {void}
         */
        protected void GetTodoData()
        {
            // populate the form with existing data from the database
            int TodoID = Convert.ToInt32(Request.QueryString["GameID"]);

            //connect to the EF framework
            using (TodoConnection db = new TodoConnection())
            {
                //populate a game object instance with the GameID from the URL paramerter
                Todo updatedTodo = (from Todo in db.Todos
                                    where Todo.TodoID == TodoID
                                    select Todo).FirstOrDefault();

                //map the game properties to the form controls
                if (updatedTodo != null)
                {
                    TodoNameTextBox.Text   = updatedTodo.TodoName;
                    TodoNotesTextBox.Text  = updatedTodo.TodoNotes;
                    CompletedCheckBox.Text = updatedTodo.Completed;
                }
            }
        }
Exemple #16
0
        /**
         * <summary>
         * This method gets the Todo list data from the DB
         * </summary>
         *
         * @method GetTodoList
         * @returns {void}
         */
        protected void GetTodoList()
        {
            // populate the form with existing TodoList data from the db
            int TodoID = Convert.ToInt32(Request.QueryString["TodoID"]);

            // connect to the EF DB
            using (TodoConnection db = new TodoConnection())
            {
                // populate a TodoList instance with the TodoID from the URL parameter
                Todo updatedTodoList = (from todoList in db.Todos
                                        where todoList.TodoID == TodoID
                                        select todoList).FirstOrDefault();

                // map the TodoList properties to the form controls
                if (updatedTodoList != null)
                {
                    TodoNameTextBox.Text      = updatedTodoList.TodoName;
                    TodoNotesTextBox.Text     = updatedTodoList.TodoNotes;
                    CompletedCheckBox.Checked = updatedTodoList.Completed.Value;
                }
            }
        }
        protected void DoneCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            // Use EF to connect to the server
            using (TodoConnection db = new TodoConnection())
            {
                // Use the Todo model to create a new Todo object and
                // Save a new record
                Todo newTodo = new Todo();

                int TodoID = 0;

                if (Request.QueryString.Count > 0) // URL has a TodoID in it
                {
                    // Get the id from the URL
                    TodoID = Convert.ToInt32(Request.QueryString["TodoID"]);

                    // Get the current Todo from EF DB
                    newTodo = (from todo in db.Todos
                               where todo.TodoID == TodoID
                               select todo).FirstOrDefault();
                }

                // Add form data to the new Todo record
                newTodo.TodoName  = TodoNameTextBox.Text;
                newTodo.TodoNotes = NotesTextBox.Text;
                newTodo.Completed = DoneCheckBox.Checked;

                // Use LINQ to ADO.NET to add / insert new Todo into the database

                if (TodoID == 0)
                {
                    db.Todos.Add(newTodo);
                }


                // Save changes - also updates and inserts
                db.SaveChanges();
            }
        }
Exemple #18
0
        protected void GetList()
        {
            // populate the form with existing todo data from the db
            int ToDoID = Convert.ToInt32(Request.QueryString["todoID"]);

            // connect to the EF DB
            using (TodoConnection db = new TodoConnection())
            {
                // populate a todo instance with the todoID from the URL parameter
                Todo updatedList = (from List in db.Todos
                                    where List.TodoID == ToDoID
                                    select List).FirstOrDefault();

                // map the todo properties to the form controls
                if (updatedList != null)
                {
                    todoName.Text     = updatedList.TodoName;
                    todoNotes.Text    = updatedList.TodoNotes;
                    todoCheck.Checked = updatedList.Completed.HasValue;
                }
            }
        }
        /**
         * <summary>
         * This method gets the Todo data from the database
         * </summary>
         * @method GetDepartments
         * @return {void}
         * */
        protected void GetTodos()
        {
            // Populate the form with existing data from the database
            int TodoID = Convert.ToInt32(Request.QueryString["TodoID"]);

            // Connect to the EF DB
            using (TodoConnection db = new TodoConnection())
            {
                // Populate a Todo object instance with the TodoID from the URL Parameter
                Todo updatedTodo = (from todo in db.Todos
                                    where todo.TodoID == TodoID
                                    select todo).FirstOrDefault();

                // Map the Todo properties to the form controls
                if (updatedTodo != null)
                {
                    TodoNameTextBox.Text = updatedTodo.TodoName;
                    NotesTextBox.Text    = updatedTodo.TodoNotes;
                    DoneCheckBox.Checked = updatedTodo.Completed ?? false;
                }
            }
        }
Exemple #20
0
        protected void TodoGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // store which row was clicked
            int selectedRow = e.RowIndex;

            // get the selected TodoID using the Grid's DataKey Collection
            int TodoID = Convert.ToInt32(TodoGridView.DataKeys[selectedRow].Values["TodoID"]);

            // use EF to find the selected Todo from DB and remove it
            using (TodoConnection db = new TodoConnection())
            {
                Todo deleteTodo = (from todoRecords in db.Todos
                                   where todoRecords.TodoID == TodoID
                                   select todoRecords).FirstOrDefault();

                // perform the removal in the DB
                db.Todos.Remove(deleteTodo);
                db.SaveChanges();

                // refresh the grid
                this.GetTodos();
            }
        }
        /**
         * <summary>
         * This method gets the Todo List
         * @returns {void}
         */
        protected void GetTodoList()
        {
            // populate the form with existing Todo data from the db
            int TodoID = Convert.ToInt32(Request.QueryString["TodoID"]);

            // connect to the EF DB
            using (TodoConnection db = new TodoConnection())
            {
                // populate a Todo instance with the TodoID from the URL parameter
                Todo updatedTodo = (from todo in db.Todos
                                          where todo.TodoID == TodoID
                                          select todo).FirstOrDefault();

                // map the Todo properties to the form controls
                if (updatedTodo != null)
                {
                    TodoNameTextBox.Text = updatedTodo.TodoName;
                    TodoNotesTextBox.Text = updatedTodo.TodoNotes;
                    CheckBox1.Checked = updatedTodo.Completed.Value;

                }
            }
        }
        /**
         * <summary>
         * Adds data to database
         * </summary>
         * @method SaveButton_Click
         * @param {object} sender
         * @param {EventArgs} e
         * @returns {void}
         */
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            //connect to db
            using (TodoConnection db = new TodoConnection())
            {
                //create new todo
                Todo newTodo = new Todo();

                //add info to todo
                newTodo.TodoName  = TodoNameTextBox.Text;
                newTodo.TodoNotes = NotesTextBox.Text;
                newTodo.Completed = CheckBox.Checked;

                //add todo to db
                db.Todos.Add(newTodo);

                //save changes
                db.SaveChanges();

                //redirect
                Response.Redirect("~/TodoList.aspx");
            }
        }
        protected void TodoGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //Store which row was selected
            int selectedRow = e.RowIndex;

            //Get the selected StudentID using the grids DataKey collection
            int TodoID = Convert.ToInt32(TodoGridView.DataKeys[selectedRow].Values["TodoID"]);

            //Use Entity Framework to find the selected student in the DB and remove it
            using (TodoConnection db = new TodoConnection())
            {
                //Create object of the student class and store the query string inside of it
                Todo deletedTodo = (from toDo in db.Todos
                                    where toDo.TodoID == TodoID
                                    select toDo).FirstOrDefault();

                //Remove the selected student from the database
                db.Todos.Remove(deletedTodo);

                //Save changes to database
                db.SaveChanges();

                //Refresh the gridview
                this.GetToDo();
            }
        }
        protected void TodoGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // store which row was selected for deletion
            int selectedRow = e.RowIndex;

            // get the selected TodoID using the grid's Datakey collection
            int TodoID = Convert.ToInt32(TodoGridView.DataKeys[selectedRow].Values["TodoID"]);

            // use EF to find the selected todo from DB and Remove it
            using (TodoConnection db = new TodoConnection())
            {
                Todo deletedTodo = (from TodoRecords in db.Todos
                                    where TodoRecords.TodoID == TodoID
                                    select TodoRecords).FirstOrDefault();

                // remove the todo record from the database
                db.Todos.Remove(deletedTodo);

                // save changes to the db
                db.SaveChanges();

                // refresh the grid
                this.GetTodo();
            }
        }
        /**
         * <summary>
         * This event handler deletes a todo
         * </summary>
         *
         * @param {object} sender
         * @param {GridViewSortEventArgs} e
         * @returns {void}
         */
        protected void TodoGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // store which row was clicked
            int selectedRow = e.RowIndex;

            // get the selected StudentID using the Grid's DataKey collection
            int TodoID = Convert.ToInt32(TodoGridView.DataKeys[selectedRow].Values["TodoID"]);

            // use EF to find the selected student in the DB and remove it
            using (TodoConnection db = new TodoConnection())
            {
                // create object of the Student class and store the query string inside of it
                Todo deletedTodo = (from todos in db.Todos
                                    where todos.TodoID == TodoID
                                    select todos).FirstOrDefault();

                // remove the selected student from the db
                db.Todos.Remove(deletedTodo);

                // save my changes back to the database
                db.SaveChanges();

                // refresh the grid
                this.GetTodos();
            }
        }
        /**
         * <summary>
         * This method gets all todos from the DB
         * </summary>
         *
         * @returns {void}
         */
        protected void GetTodos()
        {
            using (TodoConnection db = new TodoConnection())
            {
                string SortString = Session["SortColumn"].ToString() + " " + Session["SortDirection"].ToString();

                // query the Students Table using EF and LINQ
                var todos = (from _todos in db.Todos
                             select _todos);

                // Get the total number of todo items
                var totalTodos = todos.Count();

                // Display the total
                lblTotalTodos.Text = totalTodos.ToString();

                // bind the result to the GridView
                TodoGridView.DataSource = todos.AsQueryable().OrderBy(SortString).ToList();
                TodoGridView.DataBind();

            }
        }