Esempio n. 1
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            MyDataModel context = new MyDataModel();

            foreach (GridViewRow row in GridView1.Rows)
            {
                CheckBox chkTask = (CheckBox)row.FindControl("chkGoal");

                if (chkTask.Checked)
                {
                    int goalID = int.Parse(((Label)row.FindControl("HiddenGoalID")).Text.Trim());
                    IQueryable <T_TASK> tasksForDelete = T_TASKservice.GetTasksByGoalID(context, goalID);
                    if (tasksForDelete.Any())
                    {
                        foreach (var task in tasksForDelete)
                        {
                            context.T_TASK.Remove(task);
                        }
                    }
                    T_GOAL goalForDelete = T_GOALservice.GetGoalByID(context, goalID);
                    context.T_GOAL.Remove(goalForDelete);
                    context.SaveChanges();
                }
            }

            BindData();
        }
Esempio n. 2
0
        protected void chkDone_CheckedChanged(object sender, EventArgs e)
        {
            MyDataModel context  = new MyDataModel();
            CheckBox    checkbox = (CheckBox)sender;
            GridViewRow row      = (GridViewRow)((checkbox).NamingContainer);
            int         goalID   = int.Parse(((Label)row.FindControl("HiddenGoalID")).Text.Trim());

            if (checkbox.Checked)
            {
                T_GOALservice.GetGoalByID(context, goalID).Done = true;
                foreach (var task in T_TASKservice.GetTasksByGoalID(context, goalID))
                {
                    task.Done = true;
                }
            }
            else
            {
                T_GOALservice.GetGoalByID(context, goalID).Done = false;
                foreach (var task in T_TASKservice.GetTasksByGoalID(context, goalID))
                {
                    task.Done = false;
                }
            }
            context.SaveChanges();

            BindData();
        }
Esempio n. 3
0
        protected void btnBack_Click(object sender, EventArgs e)
        {
            MyDataModel         context     = new MyDataModel();
            int                 goalID      = int.Parse(lblHiddenGoalID.Text.Trim());
            IQueryable <T_TASK> tasks       = T_TASKservice.GetTasksByGoalID(context, goalID);
            T_TASK              isFalseDone = T_TASKservice.GetIncompliteTasks(tasks, false).FirstOrDefault(); //created goal have null tasks and t.Done always null
            T_GOAL              currentGoal = T_GOALservice.GetGoalByID(context, goalID);

            if (currentGoal != null)
            {
                if (isFalseDone != null || tasks.Count() == 0)
                {
                    currentGoal.Done = false;
                }
                else
                {
                    currentGoal.Done = true;
                }
                context.SaveChanges();
            }

            Response.Redirect("~/_GoalsPage.aspx");
        }