// GET api/<controller> public IEnumerable <BillDestination> Get() { BillDestinationList destinations = new BillDestinationList(); destinations.Load(); return(destinations); }
private void LoadDestinations() { try { HttpClient client = InitializeClient(); string result; dynamic items; HttpResponseMessage response; // Call the api response = client.GetAsync("BillDestination").Result; if (response.StatusCode == System.Net.HttpStatusCode.OK) { // Process the response result = response.Content.ReadAsStringAsync().Result; // REALLY COOL LINE OF CODE HERE items = (JArray)JsonConvert.DeserializeObject(result); billDestinations = items.ToObject <BillDestinationList>(); Rebind(); } else { throw new Exception("Error: " + response.ReasonPhrase); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void LoadTest() { BillDestinationList billdestinations = new BillDestinationList(); billdestinations.Load(); int expected = 2; int actual = billdestinations.Count; Assert.AreEqual(expected, actual); }
public void DeleteTest() { BillDestinationList billdestinations = new BillDestinationList(); billdestinations.Load(); BillDestination billdestination = billdestinations.FirstOrDefault(c => c.BusinessName == "Updated BillDestination"); int actual = billdestination.Delete(); Assert.IsTrue(actual > 0); }
public void UpdateTest() { BillDestinationList billdestinations = new BillDestinationList(); billdestinations.Load(); BillDestination billdestination = billdestinations.FirstOrDefault(c => c.BusinessName == "New BillDestination"); billdestination.BusinessName = "Updated BillDestination"; billdestination.Update(); billdestination.LoadById(); Assert.AreEqual(billdestination.BusinessName, "Updated BillDestination"); }
private void BtnAdd_Click(object sender, RoutedEventArgs e) { BillDestination destination = new BillDestination(); destination.Id = Guid.NewGuid(); destination.BusinessName = txtName.Text; destination.BusinessAddress = txtAddress.Text; BillDestinationList destinations = new BillDestinationList(); HttpClient client = InitializeClient(); string serializedDestination = JsonConvert.SerializeObject(destination); var content = new StringContent(serializedDestination); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); HttpResponseMessage response = client.PostAsync("BillDestination", content).Result; destinations.Add(destination); lblLog.Content = "Destination Added"; }