private void RestWebApiUpdate() { if (lstRestWebApi.SelectedItems.Count != 1) { MessageBox.Show("Please select one item in the list.", "REST WebApi - Update"); return; } int theId = 0; if (int.TryParse((string)lstRestWebApi.SelectedItems[0].Tag, out theId)) { ProxyConfiguration config = new ProxyConfiguration("http://localhost:59876/api"); IFooRest fooSvc = SimpleProxy.Proxy.For<IFooRest>(config); Foo foo = fooSvc.GetById(theId); string theBar = BarDialog.ShowDialog(foo.Bar); if (null != theBar) { foo.Bar = theBar; fooSvc.Update(foo.Id, foo); } } else { MessageBox.Show("Invalid Foo.", "REST WebApi - Update"); lstRestWebApi.SelectedItems.Clear(); } RestWebApiRefresh(); }
private void RestWebApi2Delete() { if (lstRestWebApi2.SelectedItems.Count != 1) { MessageBox.Show("Please select one item in the list.", "REST WebApi 2 - Delete"); return; } int theId = 0; if (int.TryParse((string)lstRestWebApi2.SelectedItems[0].Tag, out theId)) { ProxyConfiguration config = new ProxyConfiguration("http://localhost:59876/api"); IFooRest fooSvc = SimpleProxy.Proxy.For<IFooRest2>(config); fooSvc.Delete(theId); } else { MessageBox.Show("Invalid Foo.", "REST WebApi 2 - Delete"); lstRestWebApi2.SelectedItems.Clear(); } RestWebApi2Refresh(); }
private void RestWebApiAdd() { string bar = BarDialog.ShowDialog(string.Empty); ProxyConfiguration config = new ProxyConfiguration("http://localhost:59876/api"); IFooRest fooSvc = SimpleProxy.Proxy.For<IFooRest>(config); fooSvc.Add(new Foo { Bar = bar }); RestWebApiRefresh(); }
private void RestWebApiRefresh() { ProxyConfiguration config = new ProxyConfiguration("http://localhost:59876/api"); IFooRest fooSvc = SimpleProxy.Proxy.For<IFooRest>(config); IEnumerable<Foo> foos = fooSvc.FindAll(); lstRestWebApi.Items.Clear(); foreach (Foo foo in foos) { lstRestWebApi.Items.Add(foo.ToListViewItem()); } }