private void removeAssociated_Button_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Deletion is final, are you sure you want to remove?", "Removal confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { children_GridView.EndEdit(); List <string> services = getSelectedServices(); foreach (string service in services) { using (EnterpriseTestContext context = new EnterpriseTestContext()) { // Get service to remove from parent ResourceWindowsCategory serviceToDelete = ResourceWindowsCategory.SelectByName(context, service, tabControl_Types.SelectedTab.Text); //Get Parent ResourceWindowsCategory parent = ResourceWindowsCategory.SelectByName(context, listBox_Resource.Text, tabControl_Types.SelectedTab.Text); //Remove Parent Child relationship ResourceWindowsCategory.RemoveChild(context, parent.CategoryId, serviceToDelete.CategoryId); context.SaveChanges(); // Update Grid children_GridView.DataSource = null; children_GridView.DataSource = ResourceWindowsCategory.SelectByParent(context, (int)listBox_Resource.SelectedValue); } } } }
private void removeResource_Button_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Deletion is final, are you sure you want to remove?", "Removal confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { using (EnterpriseTestContext context = new EnterpriseTestContext()) { ResourceWindowsCategory resource = ResourceWindowsCategory.SelectByName(context, listBox_Resource.Text, tabControl_Types.SelectedTab.Text); if (resource.Children.Count > 0) { MessageBox.Show("Please remove all associations before deleting '{0}'.".FormatWith(resource.Name), "Delete Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } context.ResourceWindowsCategories.DeleteObject(resource); context.SaveChanges(); listBox_Resource.DataSource = ResourceWindowsCategory.SelectParent(context, SelectedTab.Text).ToList(); } } }