Exemplo n.º 1
0
        public List <PlantNameDTO> GetPlantNamesByType(long plantTypeId)
        {
            List <PlantNameDTO> plantNameList = new List <PlantNameDTO>();

            try
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(((App)App.Current).LAN_Address);
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("plain/text"));

                client.DefaultRequestHeaders.Add("EO-Header", User + " : " + Pwd);

                HttpResponseMessage httpResponse =
                    client.GetAsync("api/Login/GetPlantNamesByType?plantTypeId=" + plantTypeId.ToString()).Result;

                if (httpResponse.IsSuccessStatusCode)
                {
                    string strData = httpResponse.Content.ReadAsStringAsync().Result;
                    GetPlantNameResponse response = JsonConvert.DeserializeObject <GetPlantNameResponse>(strData);

                    plantNameList = response.PlantNames;
                }
                else
                {
                    MessageBox.Show("There was an error retreiving plant names");
                }
            }
            catch (Exception ex)
            {
                Exception ex2 = new Exception("Admin - GetPlantNamesByType", ex);
                ((App)App.Current).LogError(ex2.Message, "plantTypeId = " + plantTypeId.ToString());
            }

            return(plantNameList);
        }
Exemplo n.º 2
0
        public async Task <GetPlantNameResponse> GetPlantNamesByType(long typeId)
        {
            GenericGetRequest    request  = new GenericGetRequest("GetPlantNamesByType", "plantTypeId", typeId);
            GetPlantNameResponse response = await GetRequest <GetPlantNameResponse>(request);

            return(response);
        }
        private void PlantNamesLoaded(ObservableCollection <KeyValuePair <long, string> > list1, GetPlantNameResponse names)
        {
            plantNames = names.PlantNames;

            foreach (PlantNameDTO plantName in plantNames)
            {
                list1.Add(new KeyValuePair <long, string>(plantName.PlantNameId, plantName.PlantName));
            }

            Device.BeginInvokeOnMainThread(() =>
            {
                Name.ItemsSource = list1;

                SearchButton_Click(null, new EventArgs());
            });
        }