Ejemplo n.º 1
0
        /// <summary>
        /// Created By: Harinder Kaur
        /// Created Date: 28 Dec, 2016
        /// Descrition: Get Service Data List
        /// <param>Url(url of webservice which return json data)</param>
        /// <returns>class(Service data)</returns>
        ///</summary>
        public static async Task <wsTypeModel> GetServiceData(string url)
        {
            wsTypeModel objData = new wsTypeModel();

            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(url);
                    var result = await client.GetAsync(url);

                    objData = JsonConvert.DeserializeObject <wsTypeModel>(await result.Content.ReadAsStringAsync());
                }
            }
            catch (Exception ex)
            {
            }
            return(objData);
        }
        async void LoadFestivals(string todate      = "", string fromdate = "", string province = "", string region = "", string search = "",
                                 bool isfilterClick = false)
        {
            if (!availableLanguage.Contains(systemLanguage))
            {
                systemLanguage = "it";
            }
            //string url = "http://api.faitango.it/tango.php?type=festival&lang" + systemLanguage + "&to&from&provincia&region&search";
            string url = "http://api.faitango.it/tango.php?type=festival&lang=" + systemLanguage + "";

            if (todate != string.Empty)
            {
                url += "&to=" + todate + "";
            }
            else
            {
                url += "&to";
            }
            if (fromdate != string.Empty)
            {
                url += "&from=" + fromdate + "";
            }
            else
            {
                url += "&from";
            }
            if (province != string.Empty && province != "0")
            {
                url += "&provincia=" + province + "";
            }
            else
            {
                url += "&provincia";
            }
            if (region != string.Empty && region != "0")
            {
                url += "&region=" + region + "";
            }
            else
            {
                url += "&region";
            }
            if (search != string.Empty && search.Trim() != "Enter text here!")
            {
                url += "&search=" + search;
            }
            else
            {
                url += "&search";
            }
            try
            {
                progresRing.IsActive   = true;
                progresRing.Visibility = Visibility.Visible;
                if (NetworkStatus.CheckInternetAccess())
                {
                    wsTypeModel _result = new wsTypeModel();
                    _result = await Common.CommonClass.GetServiceData(url);

                    progresRing.IsActive     = false;
                    progresRing.Visibility   = Visibility.Collapsed;
                    lstFestivals.ItemsSource = null;

                    if (_result != null)
                    {
                        if (_result.data == null || _result.data.Count == 0)
                        {
                            MessageDialog msgbox = new MessageDialog(_result.mesg);
                            await msgbox.ShowAsync();

                            return;
                        }
                        if (isfilterClick)
                        {
                            btnFilter.Source = new BitmapImage(new Uri(
                                                                   "ms-appx:///Assets/filter-icon.png", UriKind.Absolute));
                        }
                        lstFestivals.ItemsSource = _result.data;
                        lstRecords = _result.data;
                    }
                    else
                    {
                        MessageDialog msgbox = new MessageDialog("Server error.");
                        await msgbox.ShowAsync();
                    }
                }
                else
                {
                    MessageDialog msgbox = new MessageDialog("Internet connection is not available.");
                    await msgbox.ShowAsync();
                }
            }
            catch
            {
            }
            finally
            {
                progresRing.IsActive   = false;
                progresRing.Visibility = Visibility.Collapsed;
            }
        }