protected void RemoveButton_Click(object sender, EventArgs e) { var db = new ApplicationDbContext(); foreach (var item in UserStateTransitionListView.Items) { var chk = item.FindControl("chkSelectOneUser") as CheckBox; if (chk.Checked) { var ustID = (long)UserStateTransitionListView.DataKeys[item.DisplayIndex].Value; var ust = db.UserStateTransitions.Single(u => u.UserStateTransitionID == ustID); db.UserStateTransitions.Remove(ust); } } if (db.ChangeTracker.HasChanges()) { db.SaveChanges(); UserStateTransitionListView.DataBind(); UsersListView.DataBind(); } }
protected void AddButton_Click(object sender, EventArgs e) { var db = new ApplicationDbContext(); foreach (var item in UsersListView.Items) { var chk = item.FindControl("chkSelectOneUser") as CheckBox; if (chk.Checked) { var ust = new UserStateTransition(); ust.UserID = UsersListView.DataKeys[item.DisplayIndex].Value.ToString(); ust.WorkflowStateTransitionID = long.Parse(Request.QueryString["WorkflowStateTransitionID"]); db.UserStateTransitions.Add(ust); //string dii = UsersListView.DataKeys[item.DataItemIndex].Value.ToString(); } } if (db.ChangeTracker.HasChanges()) { db.SaveChanges(); UserStateTransitionListView.DataBind(); UsersListView.DataBind(); } }