コード例 #1
0
        protected void btn_AddTask_Click(object sender, EventArgs e)
        {
            ToDoService.ToDoItemContract toDoItem = new ToDoService.ToDoItemContract();
            toDoItem.Title = txtTask.Text;
            toDoItem.Description = txtDescription.Text;

            Save(toDoItem);

            // update the UI
            LoadTasks();
        }
コード例 #2
0
        protected void dlTasks_UpdateCommand(Object sender, DataListCommandEventArgs e)
        {
            ToDoService.ToDoItemContract toDoItem = new ToDoService.ToDoItemContract();
            toDoItem.Id = e.CommandArgument.ToString();
            toDoItem.Title = (e.Item.FindControl("txtUpdateTitle") as TextBox).Text;
            toDoItem.Description = (e.Item.FindControl("txtUpdateDescription") as TextBox).Text;
            toDoItem.Complete = (e.Item.FindControl("chkComplete") as CheckBox).Checked;

            Save(toDoItem);

            // take the list out of edit mode
            dlTasks.EditItemIndex = -1;

            // update the UI
            LoadTasks();
        }
コード例 #3
0
        protected void btn_AddTask_Click(object sender, EventArgs e)
        {
            // ANDREI: validation should be on the client, make check only here for now
            if (string.IsNullOrEmpty(txtTask.Text) || string.IsNullOrEmpty(txtDescription.Text)) return;
            // ANDREI: added a session mechanism to prevent the insert of the same task and/or insert on the page reload
            if (!IsPostBack) return;
            if (Session["taskAdded"] != null) return;
            var toDoItem = new ToDoService.ToDoItemContract
            {
                Title = txtTask.Text,
                Description = txtDescription.Text
            };

            Save(toDoItem);

            txtTask.Text = "";
            txtDescription.Text = "";

            // update the UI
            LoadTasks();
            Session.Add("taskAdded", true);
        }
コード例 #4
0
        protected void dlTasks_UpdateCommand(Object sender, DataListCommandEventArgs e)
        {
            var title = (e.Item.FindControl("txtUpdateTitle") as TextBox).Text;
            var description = (e.Item.FindControl("txtUpdateDescription") as TextBox).Text;
            // ANDREI: validation should be on the client, make check only here for now
            if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(description)) return;

            var toDoItem = new ToDoService.ToDoItemContract
            {
                Id = e.CommandArgument.ToString(),
                Title = title,
                Description = description,
                Complete = (e.Item.FindControl("chkComplete") as CheckBox).Checked,
                // ANDREI: set a parent task id property
                ParentTaskId = (e.Item.FindControl("cboParentTask") as DropDownList).SelectedValue
            };

            Save(toDoItem);

            // take the list out of edit mode
            dlTasks.EditItemIndex = -1;

            // update the UI
            LoadTasks();
        }