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 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 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); }
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"); }
private IQueryable <T_GOAL> GetData(string sortExpression = "", SortDirection sortDirection = SortDirection.Ascending) { MyDataModel context = new MyDataModel(); GridView1.PageSize = int.Parse(dlstPageSize.SelectedValue); string userName = Page.User.Identity.Name; IQueryable <T_GOAL> goals = null; goals = T_GOALservice.GetGoalsByEmail(context, userName); string filterName = tbxFilterGoalName.Text; string filterDone = dlstFilterDone.SelectedValue; int countFrom = 0; int.TryParse(tbxCountFrom.Text, out countFrom); int countTo = 0; if (goals.Any()) { countTo = T_GOALservice.GetMaxTasksCount(goals); } if (!string.IsNullOrEmpty(tbxCountTo.Text)) { int.TryParse(tbxCountTo.Text, out countTo); } //filters if (string.IsNullOrEmpty(filterDone)) { goals = T_GOALservice.GetGoalsByFilters(goals, filterName, countFrom, countTo); } else { bool isDone = bool.Parse(filterDone); goals = T_GOALservice.GetGoalsByFilters(goals, filterName, countFrom, countTo, isDone); } int tasksCount = goals.Count(); //sorting if (ViewState["sortexpression"] != null) { string a = ViewState["sortexpression"].ToString().ToUpper(); SortDirection currentDirection = (SortDirection)Enum.Parse(typeof(SortDirection), ViewState["sortdirection"].ToString()); switch (ViewState["sortexpression"].ToString().ToUpper()) { case "DONE": goals = (currentDirection == SortDirection.Ascending) ? goals.OrderBy(n => n.Done) : goals.OrderByDescending(n => n.Done); break; case "GOALNAME": goals = (currentDirection == SortDirection.Ascending) ? goals.OrderBy(n => n.GoalName) : goals.OrderByDescending(n => n.GoalName); break; case "TASKSCOUNT": goals = (currentDirection == SortDirection.Ascending) ? goals.OrderBy(n => n.T_TASK.Count) : goals.OrderByDescending(n => n.T_TASK.Count); break; case "CREATEDATE": goals = (currentDirection == SortDirection.Ascending) ? goals.OrderBy(n => n.CreateDate) : goals.OrderByDescending(n => n.CreateDate); break; default: goals = goals.OrderBy(item => item.GoalID); break; } } else { goals = goals.OrderBy(n => n.GoalID); } //page index int recCount = goals.Count(); if ((GridView1.PageIndex * GridView1.PageSize) > recCount) { GridView1.PageIndex = recCount / GridView1.PageSize; } return(goals); }
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(); } } }