Example #1
0
        // GET api/<controller>
        public IEnumerable <BillDestination> Get()
        {
            BillDestinationList destinations = new BillDestinationList();

            destinations.Load();
            return(destinations);
        }
Example #2
0
        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);
            }
        }
Example #3
0
        public void LoadTest()
        {
            BillDestinationList billdestinations = new BillDestinationList();

            billdestinations.Load();
            int expected = 2;
            int actual   = billdestinations.Count;

            Assert.AreEqual(expected, actual);
        }
Example #4
0
        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);
        }
Example #5
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");
        }
Example #6
0
        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";
        }