Example #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();
        }
Example #2
0
        protected void btnCreate_Click(object sender, EventArgs e)
        {
            MyDataModel context  = new MyDataModel();
            string      userName = Page.User.Identity.Name;
            T_ACCOUNT   account  = T_ACCOUNTservice.GetAccountByEmail(context, userName);
            T_GOAL      newGoal  = T_GOALservice.AddNewGoal(context, userName, account);

            Response.Redirect("~/_GoalPage.aspx?GoalID=" + newGoal.GoalID);
        }
Example #3
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            MyDataModel context = new MyDataModel();
            int         goalID;

            if (!int.TryParse(Request.QueryString["GoalID"], out goalID))
            {
                lblGoalName.Text      = Messages.goalName + Messages.errorMissingGoalID;
                lblGoalName.ForeColor = Color.Red;
                return;
            }

            string taskName = tbxTaskName.Text;

            if (string.IsNullOrEmpty(taskName))
            {
                taskName = "noname";
            }
            string description = tbxDescription.Text;
            bool   isDone      = bool.Parse(dlstDone.SelectedItem.Value);

            T_GOAL goal = T_GOALservice.GetGoalByID(context, goalID);

            if (goal == null)
            {
                lblGoalName.Text      = Messages.goalName + Messages.errorIncorrectGoalID;
                lblGoalName.ForeColor = Color.Red;
                return;
            }

            int taskID;

            //create(if TaskID absent) or update task
            if (int.TryParse(Request.QueryString["TaskID"], out taskID))
            {
                if (!T_TASKservice.IsTaskExists(context, taskID))
                {
                    return;
                }
                T_TASK task = T_TASKservice.GetTaskByID(context, taskID);
                task.GoalID      = goalID;
                task.TaskName    = taskName;
                task.Description = description;
                task.Done        = isDone;
                task.UpdateDate  = DateTime.Now;
            }
            else
            {
                T_TASK newTask = new T_TASK {
                    GoalID = goalID, TaskName = taskName, Description = description, Done = isDone, UpdateDate = DateTime.Now, T_GOAL = goal
                };
                context.T_TASK.Add(newTask);
            }
            context.SaveChanges();
            Response.Redirect("~/_GoalPage.aspx?GoalID=" + goalID);
        }
Example #4
0
        public static T_GOAL AddNewGoal(MyDataModel db, string email, T_ACCOUNT account)
        {
            T_GOAL newGoal = new T_GOAL {
                Email = email, T_ACCOUNT = account, Done = false, GoalName = "New Goal", CreateDate = DateTime.Now
            };

            db.T_GOAL.Add(newGoal);
            db.SaveChanges();
            return(newGoal);
        }
Example #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.User.Identity.IsAuthenticated)
            {
                FormsAuthentication.SignOut();
                FormsAuthentication.RedirectToLoginPage();
            }

            MyDataModel context = new MyDataModel();

            int  goalID      = 0;
            bool isGetGoalID = int.TryParse(Request.QueryString["GoalID"], out goalID);

            lblHiddenGoalID.Text = goalID.ToString();

            if (!IsPostBack)
            {
                if (isGetGoalID && goalID != 0)
                {
                    tbxGoalName.Visible = true;
                    T_GOAL currentGoal    = T_GOALservice.GetGoalByID(context, goalID);
                    string actualUserName = Page.User.Identity.Name;

                    if (currentGoal == null)
                    {
                        BadGoalID(Messages.errorMissingGoalID);
                        return;
                    }
                    else if (currentGoal.T_ACCOUNT.Email != actualUserName)
                    {
                        BadGoalID(Messages.errorIncorrectGoalID);
                        return;
                    }
                    else
                    {
                        tbxGoalName.Text = currentGoal.GoalName;
                    }
                }
                else
                {
                    BadGoalID(Messages.errorMissingGoalID);
                }
                BindData();
            }
        }
Example #6
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");
        }
Example #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            MyDataModel context              = new MyDataModel();
            int         tasknameMaxLength    = 50;
            int         descriptionMaxLength = 50;

            Label1.Text = tbxDescription.Text.Length.ToString();
            tbxDescription.Attributes.Add("MaxLength", tbxDescription.MaxLength.ToString());
            string actualUserName = Page.User.Identity.Name;

            int goalID;

            if (!int.TryParse(Request.QueryString["GoalID"], out goalID))
            {
                tbxTaskName.MaxLength  = tasknameMaxLength;
                tbxTaskName.ToolTip    = string.Format("Max {0} characters", tasknameMaxLength);
                tbxDescription.ToolTip = string.Format("Max {0} characters", descriptionMaxLength);
                lblGoalName.Text       = Messages.goalName + Messages.errorMissingGoalID;
                lblGoalName.ForeColor  = Color.Red;
                return;
            }
            else
            {
                T_GOAL goalAbsentOrDeleted = T_GOALservice.GetGoalByID(context, goalID);
                if (goalAbsentOrDeleted == null)
                {
                    BadGoalID(Messages.goalName + " is absent!");
                    return;
                }
                else if (goalAbsentOrDeleted.T_ACCOUNT.Email != actualUserName)
                {
                    BadGoalID(Messages.goalName + " is incorrect!");
                    return;
                }
                else
                {
                    lblGoalName.ForeColor = Color.Empty;
                    btnSave.Enabled       = true;
                    lblGoalName.Text      = Messages.goalName + goalAbsentOrDeleted.GoalName;
                }
            }

            if (!IsPostBack)
            {
                int taskID;

                if (int.TryParse(Request.QueryString["TaskID"], out taskID))
                {
                    if (!T_TASKservice.IsTaskExists(context, taskID))
                    {
                        return;
                    }
                    T_TASK task = T_TASKservice.GetTaskByID(context, taskID);
                    tbxTaskName.Text       = task.TaskName;
                    tbxDescription.Text    = task.Description;
                    Label1.Text            = task.Description.Count().ToString();
                    dlstDone.SelectedValue = task.Done.ToString().ToLower();
                }
                else
                {
                    Label1.Text = tbxDescription.Text.Length.ToString();
                }
            }
        }