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(); }
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(); }
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); }
protected void tbxGoalName_TextChanged(object sender, EventArgs e) { int goalID = int.Parse(Request.QueryString["GoalID"]); MyDataModel context = new MyDataModel(); string newGoalName = tbxGoalName.Text; if (string.IsNullOrEmpty(newGoalName)) { newGoalName = "noname"; } T_GOALservice.GetGoalByID(context, goalID).GoalName = newGoalName; context.SaveChanges(); }
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(); } }
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"); }
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(); } } }