예제 #1
0
        public void UpdateKeg(BeerKegs objBeer)
        {
            objBeer.Delivered = true;
            var client = new RestClient(@"http://threefatpigs.azurewebsites.net/");

            var request = new RestRequest("api/BeerKegs/" + objBeer.P_Id, Method.PUT);


            // Json to post.
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(objBeer);

            request.AddParameter("application/json; charset=utf-8", json, ParameterType.RequestBody);
            request.RequestFormat = DataFormat.Json;

            try
            {
                client.ExecuteAsync(request, response =>
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        Toast.MakeText(this, "Record updated Successfully", ToastLength.Long).Show();
                    }
                    else
                    {
                        Toast.MakeText(this, "Something went wrong", ToastLength.Long).Show();
                    }
                });

                getbeerkegs();
            }
            catch (Exception error)
            {
                Toast.MakeText(this, "Something went wrong" + error.Message, ToastLength.Long).Show();
            }
        }
        public List <BeerKegs> ExecuteRequest()
        {
            var client = new RestClient(url);

            response = client.Execute(request);

            BeerKegs objRoot = new BeerKegs();

            List <BeerKegs> LstBeerKegs = new List <BeerKegs>();

            LstBeerKegs = JsonConvert.DeserializeObject <List <BeerKegs> >(response.Content);

            return(LstBeerKegs);
        }
예제 #3
0
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            // Uri requestUri = new Uri("http://threefatpigs.azurewebsites.net/api/BeerKegs");
            string json = "";

            BeerKegs objBeer = new BeerKegs();

            objBeer.Name          = txtName.Text;
            objBeer.Address       = txtAddress.Text;
            objBeer.City          = txtCity.Text;
            objBeer.Barcode       = txtBarcode.Text;
            objBeer.InvoiceNumber = Convert.ToInt16(txtInvoice.Text);

            var client = new RestClient(@"http://threefatpigs.azurewebsites.net/");

            var request = new RestRequest("api/BeerKegs", Method.POST);

            // Json to post.
            json = Newtonsoft.Json.JsonConvert.SerializeObject(objBeer);

            request.AddParameter("application/json; charset=utf-8", json, ParameterType.RequestBody);
            request.RequestFormat = DataFormat.Json;

            try
            {
                client.ExecuteAsync(request, response =>
                {
                    if (response.StatusCode == HttpStatusCode.Created)
                    {
                        Toast.MakeText(this, "Record Added Successfully", ToastLength.Long).Show();
                    }
                    else
                    {
                        Toast.MakeText(this, "Something went wrong", ToastLength.Long).Show();
                    }
                });
            }
            catch (Exception error)
            {
                Toast.MakeText(this, "Something went wrong" + error.Message, ToastLength.Long).Show();
            }
            txtBarcode.Text = "";
            txtAddress.Text = "";
            txtCity.Text    = "";
            txtInvoice.Text = "";
            txtName.Text    = "";
        }