public async Task PostData(Haspel haspel)
        {
            if (!myParent.IsConnected)
            {
                return;
            }

            var json = JsonConvert.SerializeObject(haspel);
            var data = new StringContent(json, Encoding.UTF8, "application/json");

            var client = new HttpClient();

            var response = await client.PostAsync(myApiEndPoint, data);

            string result = response.Content.ReadAsStringAsync().Result;

            client.Dispose();
        }
        public async Task <Haspel> GetHaspelByBarcode(string barcode)
        {
            try
            {
                if (!myParent.IsConnected)
                {
                    return(new Haspel
                    {
                        Barcode = "Not found",
                        UsedBy = "-",
                        Status = Enums.EHaspelStatus.Unkown
                    });
                }
                string getBarcodeUrl = $"{myApiEndPoint}/{barcode}";
                Uri    url           = new Uri(getBarcodeUrl);
                var    httpClient    = new HttpClient();
                var    response      = await httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);

                if (!response.IsSuccessStatusCode)
                {
                    return(new Haspel
                    {
                        Barcode = "Not found",
                        UsedBy = "-",
                        Status = Enums.EHaspelStatus.Unkown
                    });
                }
                Haspel result = JsonConvert.DeserializeObject <Haspel>(await response.Content.ReadAsStringAsync());

                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(new Haspel
                {
                    Barcode = "Not found",
                    UsedBy = "-",
                    Status = Enums.EHaspelStatus.Unkown
                });
            }
        }
Beispiel #3
0
 public void Post([FromBody] Haspel value)
 {
     myFileService.Update(value);
 }