コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnCreateTask_Click(object sender, EventArgs e)
        {
            lblCreateTaskResults.Text = "";

            if (Page.IsValid)
            {
                // Make sure the user selected a team
                if (ddlCreateTaskTeam.SelectedValue.Equals("") || ddlCreateTaskTeam.SelectedValue.Equals("0") ||
                    ddlCreateTaskTeam.SelectedValue == null)
                {
                    lblCreateTaskResults.ForeColor = Color.Red;
                    lblCreateTaskResults.Text      = "You must select a team. ";
                    return;
                }

                // Make sure name and description are not empty
                if (tbxCreateTaskName.Text.Equals("") || tbxCreateDescription.Equals(""))
                {
                    lblCreateTaskResults.ForeColor = Color.Red;
                    lblCreateTaskResults.Text      = "Must complete all fields. ";
                    return;
                }

                // Make sure current user is the admin of the selected team
                // First make sure the current user is the admin of the selected team
                Team team = TeamDAL.GetTeamById(Convert.ToInt64(ddlCreateTaskTeam.SelectedValue));

                // If the user is NOT the team admin...
                if (currentUser.ID != team.TeamOwner)
                {
                    lblCreateTaskResults.ForeColor = Color.Red;
                    lblCreateTaskResults.Text     += "Cannot add tasks to a team that you are not the admin of. ";
                    return;
                }

                // Now all data is valid... so create task
                Int64 newTaskID = TaskDAL.CreateNewTask(tbxCreateTaskName.Text, cdlCreateCalendar.SelectedDate,
                                                        tbxCreateDescription.Text, Convert.ToInt64(ddlCreateTaskTeam.SelectedValue));
                lblCreateTaskResults.ForeColor = Color.Blue;
                lblCreateTaskResults.Text      = "Successfully created task. ";

                // Now refresh all of the drop down lists on the page
                this.RefreshAllDropDownLists();

                // Clear the fields in the Create Task View
                tbxCreateTaskName.Text         = "";
                tbxCreateDescription.Text      = "";
                cdlCreateCalendar.SelectedDate = DateTime.Now;
            }
        }