void CustomerViewer_DeleteAsync(object sender, DataActionEventArgs e) { WebsiteAdapter wa = CreateAdapter <WebsiteAdapter>(); CustomerAdapter ca = CreateAdapter <CustomerAdapter>(); int[] indexes = e.GetData <DataViewerOpenArgs>().SelectedIndices; foreach (Customer customer in indexes.Select(i => customerList[i])) { bool removeCustomer = true; Website[] websites = wa.GetFromCustomer(customer.DataID); if (websites.Count() != 0) { string websiteNames = string.Join(", ", websites.Select(w => w.Name).ToArray()); DialogResult result = (DialogResult)Invoke((MessageBoxInvoker) delegate { return(MessageBox.Show( "Removing the customer (" + customer.CodeAndName + ") " + "will remove all associated websites (" + websiteNames + "). " + "Would you like to remove this customer?", "Remove websites", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)); }); removeCustomer = (result == DialogResult.Yes); } if (removeCustomer) { CustomerDeleteResult cdr = ca.Delete(customer.DataID); if (cdr.Errors.Length != 0) { Invoke((MethodInvoker) delegate { MessageBox.Show( "One or more errors occured while deleting " + "customer '" + customer.CodeAndName + "'.\r\n\r\n" + string.Join("\r\n", cdr.Errors.Select(error => "> " + error).ToArray()), "Delete customer", MessageBoxButtons.OK, MessageBoxIcon.Warning); }); } } } }
public void CrudTest() { Customer c = new Customer(RhspDataID.Generate()) { Code = "TEST", Name = "Test Company" }; adapter.Create(c); Customer c2 = adapter.Get(c.DataID); c2.Name += " TEST"; adapter.Update(c2); Customer c3 = adapter.Get(c.DataID); Assert.AreEqual(c2.Name, c3.Name); adapter.Delete(c.DataID); }