Пример #1
0
        public bool Save_Changes()
        {
            // Go through the each repeater item for this week
            foreach (RepeaterItem item in rptThisWeek.Items)
            {
                TextBox  txtPromiseDescription = ((TextBox)item.FindControl("twPromiseDescription"));
                CheckBox cbPromiseComplete     = ((CheckBox)item.FindControl("twPromiseComplete"));
                Label    lblPromiseID          = ((Label)item.FindControl("twPromiseID"));
                int      promiseID             = Convert.ToInt32(lblPromiseID.Text);

                // See if the promise exists in the database
                var promises = from p in entities.Promises
                               where p.PromiseID == promiseID
                               select p;

                if (promises.Count() != 0)
                {
                    // It does exist
                    FRT.DAL.Promise promise = promises.First();

                    // If the new textbox is empty, delete the row
                    if (txtPromiseDescription.Text == "")
                    {
                        entities.DeleteObject(promise);
                    }
                    else
                    {
                        // Otherwise update the promisedescription
                        if (!promise.PromiseDescription.Equals(txtPromiseDescription.Text))
                        {
                            promise.PromiseDescription = txtPromiseDescription.Text;
                        }

                        // If the promisecomplete has changed, update that too.
                        if (!promise.PromiseComplete.Equals(cbPromiseComplete.Checked))
                        {
                            promise.PromiseComplete = cbPromiseComplete.Checked;
                        }
                    }
                }
                else
                {
                    // it doesn't exist. wtf??
                }
            }
            // Save changes and refresh data
            entities.SaveChanges();
            BindRepeaters();

            // Always return true (we have the option to in the future return false for failure)
            return(true);
        }
Пример #2
0
        protected void SaveGoals_Click(object sender, EventArgs e)
        {
            FRT.DAL.frtEntities entities = new FRT.DAL.frtEntities();

            // Go through each of the items in the repeater and update
            foreach (RepeaterItem item in rptTrainingGoals.Items)
            {
                HiddenField lblGoalID  = (HiddenField)item.FindControl("lblGoalID");
                TextBox     txtGoal    = (TextBox)item.FindControl("txtGoal");
                TextBox     txtGoalURL = (TextBox)item.FindControl("txtGoalURL");

                int goalID = Convert.ToInt32(lblGoalID.Value);

                // See if the goal exists in the database
                var goals = from g in entities.TrainingGoals
                            where g.GoalID == goalID
                            select g;

                if (goals.Count() != 0)
                {
                    // It does exist
                    FRT.DAL.TrainingGoal goal = goals.First();

                    // If the textbox is empty, delete the row
                    if (txtGoal.Text.Equals(""))
                    {
                        entities.DeleteObject(goal);
                    }
                    else
                    {
                        // Otherwise update the goal
                        goal.Goal = txtGoal.Text;
                        goal.URL  = txtGoalURL.Text;
                    }
                }
                else
                {
                    // it doesn't exist. wtf??
                }
            }
            // Save changes and refresh data
            entities.SaveChanges();
            RefreshTrainingGoals();
            pnlTrainingGoals.Visible = false;
        }