// Users
IEnumerable<String> selected_user_ids = from ListItem item in SelectedUsersListBox.Items select item.Value;
IEnumerable<RuleUser> existing_rule_users = dc.RuleUsers.Where(ru => ru.RuleID == ruleId && selected_user_ids.Contains(ru.MFAUserID.ToString()));
IEnumerable<String> existing_user_ids = existing_rule_users.Select(ru => ru.MFAUserID.ToString());
IEnumerable<RuleUser> delete_rule_users = dc.RuleUsers.Where(ru => ru.RuleID == ruleId).Except(existing_rule_users);
IEnumerable<String> new_user_ids = selected_user_ids.Except(existing_user_ids);
dc.RuleUsers.DeleteAllOnSubmit(delete_rule_users);
foreach (String userid in new_user_ids)
{
RuleUser rule_user = new RuleUser();
rule_user.MFAUserID = new Guid(userid);
rule_user.RuleID = ruleId;
dc.RuleUsers.InsertOnSubmit(rule_user);
}
protected void AddUserButton_Click(object sender, EventArgs e)
{
ListItem item;
while ((item = UnselectedUsersListBox.SelectedItem) != null)
{
SelectedUsersListBox.Items.Add(item);
UnselectedUsersListBox.Items.Remove(item);
}
}
protected void RemoveUserButton_Click(object sender, EventArgs e)
{
ListItem item;
while ((item = SelectedUsersListBox.SelectedItem) != null)
{
UnselectedUsersListBox.Items.Add(item);
SelectedUsersListBox.Items.Remove(item);
}
}