Example #1
0
        /// <summary>
        /// Parsing json data from url and add into a list.
        /// </summary>
        /// <param name="parameterValue"></param>
        public object GetCityItemDetails(CityData selectedCategory)
        {
            object result = null;

            try
            {
                this.CityCategoryPushpinsList.Clear();

                POSH.Socrata.Entity.Models.CityData cityData = new POSH.Socrata.Entity.Models.CityData();
                cityData.Coordinate = new Altitude();

                cityData.Address              = selectedCategory.Address;
                cityData.Coordinate.Latitude  = Convert.ToDouble(selectedCategory.Coordinate.Latitude);
                cityData.Coordinate.Longitude = Convert.ToDouble(selectedCategory.Coordinate.Longitude);
                cityData.Phone           = selectedCategory.Phone;
                cityData.Name            = selectedCategory.Name;
                cityData.Distance        = selectedCategory.Distance;
                cityData.Comments        = selectedCategory.Comments;
                cityData.IndexNo         = selectedCategory.IndexNo;
                cityData.SubTitle        = selectedCategory.SubTitle;
                cityData.Category        = selectedCategory.Category;
                cityData.BackgroundImage = selectedCategory.BackgroundImage;
                cityData.CompositeKey    = selectedCategory.CompositeKey;
                this.CityCategoryItem    = cityData;
                if (cityData.Coordinate.Latitude != 0 && cityData.Coordinate.Longitude != 0)
                {
                    this.CityCategoryPushpinsList.Add(cityData);
                }

                this.MapCenterPoint = this.CityCategoryItem.Coordinate;
            }

            catch (Exception)
            {
                result = "There is an error on loading report data.";
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// Gets city item details for secondary tile
        /// </summary>
        /// <param name="parameterValue"></param>
        /// <param name="categoryName"></param>
        /// <param name="currentLocation"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public void GetTileCityItemDetails(string parameterValue, GovFinderData cityDetail, Altitude currentLocation, string compositeKey)
        {
            try
            {
                var responseText = string.Empty;
                if (NetworkInterface.GetIsNetworkAvailable())
                {
                    //HttpClient client = new HttpClient();
                    //HttpResponseMessage response = client.GetAsync(parameterValue).Result;

                    //response.EnsureSuccessStatusCode();
                    //string responseBody = response.Content.ReadAsStringAsync().Result;

                    //List<CityData> tempCityDataList = new List<CityData>();
                    //var dataSetItems = Newtonsoft.Json.JsonConvert.DeserializeObject<List<CityAllData>>(responseBody);
                    //if (dataSetItems != null)
                    //{
                    //    foreach (var item in dataSetItems)
                    //    {
                    //        try
                    //        {
                    //            POSH.Socrata.Entity.Models.CityData cityData = new POSH.Socrata.Entity.Models.CityData();
                    //            cityData.Coordinate = new Altitude();

                    //            if (!string.IsNullOrEmpty(item.address))
                    //            {
                    //                cityData.Address = item.address.ToString();
                    //            }
                    //            else if (!string.IsNullOrEmpty(item.human_address))
                    //            {
                    //                cityData.Address = item.human_address.ToString();
                    //            }
                    //            else if (!string.IsNullOrEmpty(item.street_address))
                    //            {
                    //                cityData.Address = item.street_address.ToString();
                    //            }
                    //            else
                    //            {
                    //                cityData.Address = "No address";
                    //            }

                    //            if (!string.IsNullOrEmpty(item.latitude))
                    //            {
                    //                cityData.Coordinate.Latitude = Convert.ToDouble(item.latitude.ToString());
                    //            }
                    //            else if (item.location != null && !string.IsNullOrEmpty(item.location.latitude))
                    //            {
                    //                cityData.Coordinate.Latitude = Convert.ToDouble(item.location.latitude.ToString());
                    //            }
                    //            else
                    //            {
                    //                cityData.Coordinate.Latitude = 0;
                    //            }

                    //            if (!string.IsNullOrEmpty(item.longitude))
                    //            {
                    //                cityData.Coordinate.Longitude = Convert.ToDouble(item.longitude.ToString());
                    //            }
                    //            else if (item.location != null && !string.IsNullOrEmpty(item.location.longitude))
                    //            {
                    //                cityData.Coordinate.Longitude = Convert.ToDouble(item.location.longitude.ToString());
                    //            }
                    //            else
                    //            {
                    //                cityData.Coordinate.Longitude = 0;
                    //            }

                    //            if (cityData.Coordinate.Latitude == 0 && cityData.Coordinate.Longitude == 0)
                    //            {
                    //                cityData.Distance = "No distance";
                    //            }
                    //            else
                    //            {
                    //                var distance = CityDetailsViewModel.CalculateDistance(currentLocation.Latitude, currentLocation.Longitude, cityData.Coordinate.Latitude, cityData.Coordinate.Longitude);
                    //                cityData.Distance = distance.ToString() + " miles";
                    //            }

                    //            if (!string.IsNullOrEmpty(item.phone))
                    //            {
                    //                cityData.Phone = item.phone.ToString();
                    //            }
                    //            else
                    //            {
                    //                cityData.Phone = "No phone number";
                    //            }

                    //            if (!string.IsNullOrEmpty(item.name))
                    //            {
                    //                cityData.Name = item.name.ToString();
                    //            }
                    //            else if (!string.IsNullOrEmpty(item.station_name))
                    //            {
                    //                cityData.Name = item.station_name.ToString();
                    //            }
                    //            else if (!string.IsNullOrEmpty(item.architect))
                    //            {
                    //                cityData.Name = item.architect.ToString();
                    //            }
                    //            else if (!string.IsNullOrEmpty(item.Event))
                    //            {
                    //                cityData.Name = item.Event.ToString();
                    //            }
                    //            else
                    //            {
                    //                cityData.Name = "No name";
                    //            }

                    //            if (!string.IsNullOrEmpty(item.sub_category))
                    //            {
                    //                cityData.SubTitle = item.sub_category;
                    //            }
                    //            else if (!string.IsNullOrEmpty(item.fuel_type_code))
                    //            {
                    //                cityData.SubTitle = item.fuel_type_code;
                    //            }
                    //            else if (!string.IsNullOrEmpty(item.building_code))
                    //            {
                    //                cityData.SubTitle = item.building_code;
                    //            }
                    //            else
                    //            {
                    //                cityData.SubTitle = "No subtitle";
                    //            }

                    //            if (!string.IsNullOrEmpty(item.image))
                    //            {
                    //                cityData.BackgroundImage = item.image;
                    //            }
                    //            else
                    //            {
                    //                cityData.BackgroundImage = "/Assets/CommunityCenters.png";
                    //            }

                    //            cityData.Category = categoryName;

                    //            cityData.CompositeKey = CityDetailsViewModel.GenerateCompositeKey(cityData);
                    //            cityData.Comments = this.GetCommentCount(cityData).Result;

                    //            tempCityDataList.Add(cityData);

                    //            if (currentLocation.Latitude != 0 && currentLocation.Longitude != 0 && this.MapCenterPoint.Latitude == 0 && this.MapCenterPoint.Longitude == 0)
                    //            {
                    //                this.MapCenterPoint = currentLocation;
                    //            }
                    //            else
                    //            {
                    //                if (this.MapCenterPoint.Latitude == 0 && this.MapCenterPoint.Longitude == 0)
                    //                {
                    //                    this.MapCenterPoint = cityData.Coordinate;
                    //                }
                    //            }
                    //        }
                    //        catch (Exception)
                    //        {
                    //            continue;
                    //        }
                    //    }
                    //}
                    //var sortList = tempCityDataList.OrderBy(item => item.Distance).ThenBy(item => item.Name).ToList();

                    //this.CityCategoryItemsList = new ObservableCollection<CityData>();
                    //this.CityCategoryPushpinsList = new ObservableCollection<CityData>();
                    //foreach (var item in sortList)
                    //{
                    //    item.IndexNo = this.CityCategoryItemsList.Count + 1;
                    //    this.CityCategoryItemsList.Add(item);
                    //    if (this.CityCategoryPushpinsList.Count < 40)
                    //    {
                    //        if (item.Coordinate.Latitude != 0 && item.Coordinate.Longitude != 0)
                    //        {
                    //            this.CityCategoryPushpinsList.Add(item);
                    //        }
                    //    }
                    //}

                    //if (this.CityCategoryItemsList.FirstOrDefault() != null)
                    //{
                    //    var pinnedItem = this.CityCategoryItemsList.Where(item => item.CompositeKey.ToLower() == compositeKey.ToLower()).FirstOrDefault();
                    //    if (pinnedItem != null)
                    //    {
                    //        if (pinnedItem.Coordinate.Latitude != 0 && pinnedItem.Coordinate.Longitude != 0)
                    //        {
                    //            this.MapCenterPoint = pinnedItem.Coordinate;
                    //        }
                    //        else
                    //        {
                    //            this.MapCenterPoint = currentLocation;
                    //        }

                    //        GetCityItemDetails(pinnedItem);
                    //    }
                    //}

                    HttpClient          client           = new HttpClient();
                    HttpResponseMessage response         = client.GetAsync(parameterValue).Result;
                    List <CityData>     tempCityDataList = new List <CityData>();
                    if (response.IsSuccessStatusCode)
                    {
                        response.EnsureSuccessStatusCode();
                        responseText = response.Content.ReadAsStringAsync().Result;



                        XElement xmlData = XElement.Parse(responseText, LoadOptions.PreserveWhitespace);
                        foreach (XElement curElement in xmlData.Descendants("row").Descendants("row"))
                        {
                            try
                            {
                                POSH.Socrata.Entity.Models.CityData cityData = new POSH.Socrata.Entity.Models.CityData();
                                cityData.Coordinate = new Altitude();

                                cityData.Name            = GetContents(curElement, cityDetail.Name);
                                cityData.SubTitle        = GetContents(curElement, cityDetail.SubTitle);
                                cityData.Phone           = GetContents(curElement, cityDetail.Phone);
                                cityData.BackgroundImage = "/Assets/CommunityCenters.png";

                                if (cityDetail.Latitude != "NA")
                                {
                                    if (cityDetail.Latitude == "location.latitude")
                                    {
                                        cityData.Coordinate.Latitude = Convert.ToDouble(curElement.Element("location").Attribute("latitude").Value);
                                    }
                                    else
                                    {
                                        cityData.Coordinate.Latitude = Convert.ToDouble(GetContents(curElement, cityDetail.Latitude));
                                    }
                                }
                                else
                                {
                                    cityData.Coordinate.Latitude = 0;
                                }

                                if (cityDetail.Longitude != "NA")
                                {
                                    if (cityDetail.Longitude == "location.longitude")
                                    {
                                        cityData.Coordinate.Longitude = Convert.ToDouble(curElement.Element("location").Attribute("longitude").Value);
                                    }
                                    else
                                    {
                                        cityData.Coordinate.Longitude = Convert.ToDouble(GetContents(curElement, cityDetail.Longitude));
                                    }
                                }
                                else
                                {
                                    cityData.Coordinate.Longitude = 0;
                                }


                                if (cityData.Coordinate.Latitude == 0 && cityData.Coordinate.Longitude == 0)
                                {
                                    cityData.Distance = "No distance";
                                }
                                else
                                {
                                    var distance = CityDetailsViewModel.CalculateDistance(currentLocation.Latitude, currentLocation.Longitude, cityData.Coordinate.Latitude, cityData.Coordinate.Longitude);
                                    cityData.Distance = distance.ToString() + " miles";
                                }



                                cityData.Category     = cityDetail.DataSetName;
                                cityData.CompositeKey = CityDetailsViewModel.GenerateCompositeKey(cityData);
                                cityData.Comments     = GetCommentCount(cityData).Result;
                                tempCityDataList.Add(cityData);

                                if (currentLocation.Latitude != 0 && currentLocation.Longitude != 0 && this.MapCenterPoint.Latitude == 0 && this.MapCenterPoint.Longitude == 0)
                                {
                                    this.MapCenterPoint = currentLocation;
                                }
                                else
                                {
                                    if (this.MapCenterPoint.Latitude == 0 && this.MapCenterPoint.Longitude == 0)
                                    {
                                        this.MapCenterPoint = cityData.Coordinate;
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                    }
                    var sortList = tempCityDataList.OrderBy(item => item.Distance).ThenBy(item => item.Name).ToList();

                    this.CityCategoryItemsList    = new ObservableCollection <CityData>();
                    this.CityCategoryPushpinsList = new ObservableCollection <CityData>();
                    foreach (var item in sortList)
                    {
                        item.IndexNo = this.CityCategoryItemsList.Count + 1;
                        this.CityCategoryItemsList.Add(item);
                        if (this.CityCategoryPushpinsList.Count < 40)
                        {
                            if (item.Coordinate.Latitude != 0 && item.Coordinate.Longitude != 0)
                            {
                                this.CityCategoryPushpinsList.Add(item);
                            }
                        }
                    }

                    if (this.CityCategoryItemsList.FirstOrDefault() != null)
                    {
                        var pinnedItem = this.CityCategoryItemsList.Where(item => item.CompositeKey.ToLower() == compositeKey.ToLower()).FirstOrDefault();
                        if (pinnedItem != null)
                        {
                            if (pinnedItem.Coordinate.Latitude != 0 && pinnedItem.Coordinate.Longitude != 0)
                            {
                                this.MapCenterPoint = pinnedItem.Coordinate;
                            }
                            else
                            {
                                this.MapCenterPoint = currentLocation;
                            }

                            GetCityItemDetails(pinnedItem);
                        }
                    }
                }
            }
            catch (Exception)
            {
                this.ErrorMessage = "There is an error on fetching data from server. Please try again...";
            }
        }
 /// <summary>
 /// Gets comment count
 /// </summary>
 /// <param name="cityData"></param>
 public async Task<string> GetCommentCount(CityData cityData)
 {
     CommentViewModel commentViewModel = new CommentViewModel();
     return commentViewModel.GetCommentCount(cityData.CompositeKey, GlobalVariables.CityName, cityData.Category).Result;
 }
        /// <summary>
        /// Generates a composite key for city item
        /// </summary>
        /// <param name="cityItem"></param>
        /// <returns></returns>
        public static string GenerateCompositeKey(CityData cityItem)
        {
            try
            {
                string compositeKey = string.Empty;
                compositeKey = string.Format("{0}|{1}|{2}|{3}|{4}|{5}|{6}", cityItem.Name, cityItem.Category, cityItem.Address, cityItem.Coordinate.Latitude.ToString(), cityItem.Coordinate.Longitude.ToString(), cityItem.Phone, cityItem.SubTitle);

                return compositeKey.Replace(" ", "");
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Parsing json data from url and add into a list.
        /// </summary>
        /// <param name="parameterValue"></param>
        public  void GetCityItemDetails(string parameterValue, GovFinderData cityDetail)
        {
            try
            {
                this.IsDataLoading = true;
                var responseText = string.Empty;
                if (NetworkInterface.GetIsNetworkAvailable())
                {
                    HttpClient client = new HttpClient();
                    HttpResponseMessage response =  client.GetAsync(parameterValue).Result;
                    List<CityData> tempCityDataList = new List<CityData>();
                    if (response.IsSuccessStatusCode)
                    {
                        response.EnsureSuccessStatusCode();
                        responseText =  response.Content.ReadAsStringAsync().Result;

                      

                        XElement xmlData = XElement.Parse(responseText, LoadOptions.PreserveWhitespace);
                        foreach (XElement curElement in xmlData.Descendants("row").Descendants("row"))
                        {
                           
                            try
                            {
                                POSH.Socrata.Entity.Models.CityData cityData = new POSH.Socrata.Entity.Models.CityData();
                                cityData.Coordinate = new Altitude();

                                cityData.Name = GetContents(curElement, cityDetail.Name);
                                cityData.SubTitle = GetContents(curElement, cityDetail.SubTitle);
                                cityData.Phone = GetContents(curElement, cityDetail.Phone);
                                cityData.BackgroundImage = "/Assets/CommunityCenters.png";

                                if (cityDetail.Latitude != "NA")
                                {   
                                    if (cityDetail.Latitude == "location.latitude")
                                    {
                                        cityData.Coordinate.Latitude = Convert.ToDouble(curElement.Element("location").Attribute("latitude").Value);
                                    }
                                    else
                                    {
                                        cityData.Coordinate.Latitude = Convert.ToDouble(GetContents(curElement, cityDetail.Latitude));
                                    }
                                }
                                else
                                {
                                    cityData.Coordinate.Latitude = 0; 
                                }

                                if (cityDetail.Longitude != "NA")
                                {
                                    if (cityDetail.Longitude == "location.longitude")
                                    {
                                        cityData.Coordinate.Longitude = Convert.ToDouble(curElement.Element("location").Attribute("longitude").Value);
                                    }
                                    else
                                    {
                                        cityData.Coordinate.Longitude = Convert.ToDouble(GetContents(curElement, cityDetail.Longitude));
                                    }
                                }
                                else
                                {
                                    cityData.Coordinate.Longitude = 0;
                                }


                                if (cityData.Coordinate.Latitude == 0 && cityData.Coordinate.Longitude == 0)
                                {
                                    cityData.Distance = "No distance";
                                }
                                else
                                {
                                    var distance = CalculateDistance(this.CurrentLocationCoordinates.Latitude, this.CurrentLocationCoordinates.Longitude, cityData.Coordinate.Latitude, cityData.Coordinate.Longitude);
                                    cityData.Distance = distance.ToString() + " miles";
                                }

                            

                                cityData.Category = cityDetail.DataSetName;
                                cityData.CompositeKey = GenerateCompositeKey(cityData);
                                cityData.Comments = GetCommentCount(cityData).Result;
                                tempCityDataList.Add(cityData);
                                this.AllCityItems.Add(cityData);

                                if (this.CurrentLocationCoordinates.Latitude != 0 && this.CurrentLocationCoordinates.Longitude != 0 && this.MapCenterPoint.Latitude == 0 && this.MapCenterPoint.Longitude == 0)
                                {
                                    this.MapCenterPoint = this.CurrentLocationCoordinates;
                                }
                                else
                                {
                                    if (this.MapCenterPoint.Latitude == 0 && this.MapCenterPoint.Longitude == 0)
                                    {
                                        this.MapCenterPoint = cityData.Coordinate;
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                    }
                    var sortList = tempCityDataList.OrderBy(item => item.Distance).ThenBy(item => item.Name).ToList();
                    this.CityCategoryItemsList = new ObservableCollection<CityData>();
                    this.CityCategoryPushpinsList = new ObservableCollection<CityData>();
                    foreach (var item in sortList)
                    {
                        item.IndexNo = this.CityCategoryItemsList.Count + 1;
                        this.CityCategoryItemsList.Add(item);
                        if (this.CityCategoryPushpinsList.Count < 40)
                        {
                            if (item.Coordinate.Latitude != 0 && item.Coordinate.Longitude != 0)
                            {
                                this.CityCategoryPushpinsList.Add(item);
                            }
                        }
                    }

                    if (this.CityCategoryItemsList.FirstOrDefault() != null)
                    {
                        var item = this.CityCategoryItemsList.FirstOrDefault();
                        if (item.Coordinate.Latitude != 0 && item.Coordinate.Longitude != 0)
                        {
                            this.MapCenterPoint = item.Coordinate;
                        }
                        else
                        {
                            this.MapCenterPoint = this.CurrentLocationCoordinates;
                        }
                    }
                    if (!this.AllCityCategoryItems.ContainsKey(cityDetail.DataSetName))
                    {
                        this.AllCityCategoryItems.Add(cityDetail.DataSetName, this.CityCategoryItemsList.ToList());
                    }

                    this.IsDataLoading = false;
                }
                else
                {
                    this.IsDataLoading = false;
                    this.MessageDialog = "No internet connection found. Please check your connection and try again.";
                }
            }
            catch (Exception)
            {
                if (this.CurrentCategoryName.ToLower() == cityDetail.DataSetName.ToLower())
                {
                    this.MessageDialog = "There is some problem on fetching data from server. Please check your internet connection and try again.";
                    this.IsDataLoading = false;
                }
            }
        }
        /// <summary>
        /// Gets city item details for secondary tile
        /// </summary>
        /// <param name="parameterValue"></param>
        /// <param name="categoryName"></param>
        /// <param name="currentLocation"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public void GetTileCityItemDetails(string parameterValue, GovFinderData cityDetail, Altitude currentLocation, string compositeKey)
        {
            try
            {
                var responseText = string.Empty;
                if (NetworkInterface.GetIsNetworkAvailable())
                {
                    //HttpClient client = new HttpClient();
                    //HttpResponseMessage response = client.GetAsync(parameterValue).Result;

                    //response.EnsureSuccessStatusCode();
                    //string responseBody = response.Content.ReadAsStringAsync().Result;

                    //List<CityData> tempCityDataList = new List<CityData>();
                    //var dataSetItems = Newtonsoft.Json.JsonConvert.DeserializeObject<List<CityAllData>>(responseBody);
                    //if (dataSetItems != null)
                    //{
                    //    foreach (var item in dataSetItems)
                    //    {
                    //        try
                    //        {
                    //            POSH.Socrata.Entity.Models.CityData cityData = new POSH.Socrata.Entity.Models.CityData();
                    //            cityData.Coordinate = new Altitude();

                    //            if (!string.IsNullOrEmpty(item.address))
                    //            {
                    //                cityData.Address = item.address.ToString();
                    //            }
                    //            else if (!string.IsNullOrEmpty(item.human_address))
                    //            {
                    //                cityData.Address = item.human_address.ToString();
                    //            }
                    //            else if (!string.IsNullOrEmpty(item.street_address))
                    //            {
                    //                cityData.Address = item.street_address.ToString();
                    //            }
                    //            else
                    //            {
                    //                cityData.Address = "No address";
                    //            }

                    //            if (!string.IsNullOrEmpty(item.latitude))
                    //            {
                    //                cityData.Coordinate.Latitude = Convert.ToDouble(item.latitude.ToString());
                    //            }
                    //            else if (item.location != null && !string.IsNullOrEmpty(item.location.latitude))
                    //            {
                    //                cityData.Coordinate.Latitude = Convert.ToDouble(item.location.latitude.ToString());
                    //            }
                    //            else
                    //            {
                    //                cityData.Coordinate.Latitude = 0;
                    //            }

                    //            if (!string.IsNullOrEmpty(item.longitude))
                    //            {
                    //                cityData.Coordinate.Longitude = Convert.ToDouble(item.longitude.ToString());
                    //            }
                    //            else if (item.location != null && !string.IsNullOrEmpty(item.location.longitude))
                    //            {
                    //                cityData.Coordinate.Longitude = Convert.ToDouble(item.location.longitude.ToString());
                    //            }
                    //            else
                    //            {
                    //                cityData.Coordinate.Longitude = 0;
                    //            }

                    //            if (cityData.Coordinate.Latitude == 0 && cityData.Coordinate.Longitude == 0)
                    //            {
                    //                cityData.Distance = "No distance";
                    //            }
                    //            else
                    //            {
                    //                var distance = CityDetailsViewModel.CalculateDistance(currentLocation.Latitude, currentLocation.Longitude, cityData.Coordinate.Latitude, cityData.Coordinate.Longitude);
                    //                cityData.Distance = distance.ToString() + " miles";
                    //            }

                    //            if (!string.IsNullOrEmpty(item.phone))
                    //            {
                    //                cityData.Phone = item.phone.ToString();
                    //            }
                    //            else
                    //            {
                    //                cityData.Phone = "No phone number";
                    //            }

                    //            if (!string.IsNullOrEmpty(item.name))
                    //            {
                    //                cityData.Name = item.name.ToString();
                    //            }
                    //            else if (!string.IsNullOrEmpty(item.station_name))
                    //            {
                    //                cityData.Name = item.station_name.ToString();
                    //            }
                    //            else if (!string.IsNullOrEmpty(item.architect))
                    //            {
                    //                cityData.Name = item.architect.ToString();
                    //            }
                    //            else if (!string.IsNullOrEmpty(item.Event))
                    //            {
                    //                cityData.Name = item.Event.ToString();
                    //            }
                    //            else
                    //            {
                    //                cityData.Name = "No name";
                    //            }

                    //            if (!string.IsNullOrEmpty(item.sub_category))
                    //            {
                    //                cityData.SubTitle = item.sub_category;
                    //            }
                    //            else if (!string.IsNullOrEmpty(item.fuel_type_code))
                    //            {
                    //                cityData.SubTitle = item.fuel_type_code;
                    //            }
                    //            else if (!string.IsNullOrEmpty(item.building_code))
                    //            {
                    //                cityData.SubTitle = item.building_code;
                    //            }
                    //            else
                    //            {
                    //                cityData.SubTitle = "No subtitle";
                    //            }

                    //            if (!string.IsNullOrEmpty(item.image))
                    //            {
                    //                cityData.BackgroundImage = item.image;
                    //            }
                    //            else
                    //            {
                    //                cityData.BackgroundImage = "/Assets/CommunityCenters.png";
                    //            }

                    //            cityData.Category = categoryName;

                    //            cityData.CompositeKey = CityDetailsViewModel.GenerateCompositeKey(cityData);
                    //            cityData.Comments = this.GetCommentCount(cityData).Result;

                    //            tempCityDataList.Add(cityData);

                    //            if (currentLocation.Latitude != 0 && currentLocation.Longitude != 0 && this.MapCenterPoint.Latitude == 0 && this.MapCenterPoint.Longitude == 0)
                    //            {
                    //                this.MapCenterPoint = currentLocation;
                    //            }
                    //            else
                    //            {
                    //                if (this.MapCenterPoint.Latitude == 0 && this.MapCenterPoint.Longitude == 0)
                    //                {
                    //                    this.MapCenterPoint = cityData.Coordinate;
                    //                }
                    //            }
                    //        }
                    //        catch (Exception)
                    //        {
                    //            continue;
                    //        }
                    //    }
                    //}
                    //var sortList = tempCityDataList.OrderBy(item => item.Distance).ThenBy(item => item.Name).ToList();

                    //this.CityCategoryItemsList = new ObservableCollection<CityData>();
                    //this.CityCategoryPushpinsList = new ObservableCollection<CityData>();
                    //foreach (var item in sortList)
                    //{
                    //    item.IndexNo = this.CityCategoryItemsList.Count + 1;
                    //    this.CityCategoryItemsList.Add(item);
                    //    if (this.CityCategoryPushpinsList.Count < 40)
                    //    {
                    //        if (item.Coordinate.Latitude != 0 && item.Coordinate.Longitude != 0)
                    //        {
                    //            this.CityCategoryPushpinsList.Add(item);
                    //        }
                    //    }
                    //}

                    //if (this.CityCategoryItemsList.FirstOrDefault() != null)
                    //{
                    //    var pinnedItem = this.CityCategoryItemsList.Where(item => item.CompositeKey.ToLower() == compositeKey.ToLower()).FirstOrDefault();
                    //    if (pinnedItem != null)
                    //    {
                    //        if (pinnedItem.Coordinate.Latitude != 0 && pinnedItem.Coordinate.Longitude != 0)
                    //        {
                    //            this.MapCenterPoint = pinnedItem.Coordinate;
                    //        }
                    //        else
                    //        {
                    //            this.MapCenterPoint = currentLocation;
                    //        }

                    //        GetCityItemDetails(pinnedItem);
                    //    }
                    //}
                    
                    HttpClient client = new HttpClient();
                    HttpResponseMessage response = client.GetAsync(parameterValue).Result;
                    List<CityData> tempCityDataList = new List<CityData>();
                    if (response.IsSuccessStatusCode)
                    {
                        response.EnsureSuccessStatusCode();
                        responseText = response.Content.ReadAsStringAsync().Result;



                        XElement xmlData = XElement.Parse(responseText, LoadOptions.PreserveWhitespace);
                        foreach (XElement curElement in xmlData.Descendants("row").Descendants("row"))
                        {

                            try
                            {
                                POSH.Socrata.Entity.Models.CityData cityData = new POSH.Socrata.Entity.Models.CityData();
                                cityData.Coordinate = new Altitude();

                                cityData.Name = GetContents(curElement, cityDetail.Name);
                                cityData.SubTitle = GetContents(curElement, cityDetail.SubTitle);
                                cityData.Phone = GetContents(curElement, cityDetail.Phone);
                                cityData.BackgroundImage = "/Assets/CommunityCenters.png";

                                if (cityDetail.Latitude != "NA")
                                {
                                    if (cityDetail.Latitude == "location.latitude")
                                    {
                                        cityData.Coordinate.Latitude = Convert.ToDouble(curElement.Element("location").Attribute("latitude").Value);
                                    }
                                    else
                                    {
                                        cityData.Coordinate.Latitude = Convert.ToDouble(GetContents(curElement, cityDetail.Latitude));
                                    }
                                }
                                else
                                {
                                    cityData.Coordinate.Latitude = 0;
                                }

                                if (cityDetail.Longitude != "NA")
                                {
                                    if (cityDetail.Longitude == "location.longitude")
                                    {
                                        cityData.Coordinate.Longitude = Convert.ToDouble(curElement.Element("location").Attribute("longitude").Value);
                                    }
                                    else
                                    {
                                        cityData.Coordinate.Longitude = Convert.ToDouble(GetContents(curElement, cityDetail.Longitude));
                                    }
                                }
                                else
                                {
                                    cityData.Coordinate.Longitude = 0;
                                }


                                if (cityData.Coordinate.Latitude == 0 && cityData.Coordinate.Longitude == 0)
                                {
                                    cityData.Distance = "No distance";
                                }
                                else
                                {
                                    var distance = CityDetailsViewModel.CalculateDistance(currentLocation.Latitude, currentLocation.Longitude, cityData.Coordinate.Latitude, cityData.Coordinate.Longitude);
                                    cityData.Distance = distance.ToString() + " miles";
                                }



                                cityData.Category = cityDetail.DataSetName;
                                cityData.CompositeKey = CityDetailsViewModel.GenerateCompositeKey(cityData);
                                cityData.Comments = GetCommentCount(cityData).Result;
                                tempCityDataList.Add(cityData);
                               
                                if (currentLocation.Latitude != 0 && currentLocation.Longitude != 0 && this.MapCenterPoint.Latitude == 0 && this.MapCenterPoint.Longitude == 0)
                                {
                                    this.MapCenterPoint = currentLocation;
                                }
                                else
                                {
                                    if (this.MapCenterPoint.Latitude == 0 && this.MapCenterPoint.Longitude == 0)
                                    {
                                        this.MapCenterPoint = cityData.Coordinate;
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                    }
                    var sortList = tempCityDataList.OrderBy(item => item.Distance).ThenBy(item => item.Name).ToList();

                    this.CityCategoryItemsList = new ObservableCollection<CityData>();
                    this.CityCategoryPushpinsList = new ObservableCollection<CityData>();
                    foreach (var item in sortList)
                    {
                        item.IndexNo = this.CityCategoryItemsList.Count + 1;
                        this.CityCategoryItemsList.Add(item);
                        if (this.CityCategoryPushpinsList.Count < 40)
                        {
                            if (item.Coordinate.Latitude != 0 && item.Coordinate.Longitude != 0)
                            {
                                this.CityCategoryPushpinsList.Add(item);
                            }
                        }
                    }

                    if (this.CityCategoryItemsList.FirstOrDefault() != null)
                    {
                        var pinnedItem = this.CityCategoryItemsList.Where(item => item.CompositeKey.ToLower() == compositeKey.ToLower()).FirstOrDefault();
                        if (pinnedItem != null)
                        {
                            if (pinnedItem.Coordinate.Latitude != 0 && pinnedItem.Coordinate.Longitude != 0)
                            {
                                this.MapCenterPoint = pinnedItem.Coordinate;
                            }
                            else
                            {
                                this.MapCenterPoint = currentLocation;
                            }

                            GetCityItemDetails(pinnedItem);
                        }
                    }
                }
            }
            catch (Exception)
            {
                this.ErrorMessage = "There is an error on fetching data from server. Please try again...";
            }
        }
        /// <summary>
        /// Parsing json data from url and add into a list.
        /// </summary>
        /// <param name="parameterValue"></param>
        public object GetCityItemDetails(CityData selectedCategory)
        {
            object result = null;
            try
            {
                this.CityCategoryPushpinsList.Clear();

                POSH.Socrata.Entity.Models.CityData cityData = new POSH.Socrata.Entity.Models.CityData();
                cityData.Coordinate = new Altitude();

                cityData.Address = selectedCategory.Address;
                cityData.Coordinate.Latitude = Convert.ToDouble(selectedCategory.Coordinate.Latitude);
                cityData.Coordinate.Longitude = Convert.ToDouble(selectedCategory.Coordinate.Longitude);
                cityData.Phone = selectedCategory.Phone;
                cityData.Name = selectedCategory.Name;
                cityData.Distance = selectedCategory.Distance;
                cityData.Comments = selectedCategory.Comments;
                cityData.IndexNo = selectedCategory.IndexNo;
                cityData.SubTitle = selectedCategory.SubTitle;
                cityData.Category = selectedCategory.Category;
                cityData.BackgroundImage = selectedCategory.BackgroundImage;
                cityData.CompositeKey = selectedCategory.CompositeKey;
                this.CityCategoryItem = cityData;
                if (cityData.Coordinate.Latitude != 0 && cityData.Coordinate.Longitude != 0)
                {
                    this.CityCategoryPushpinsList.Add(cityData);
                }

                this.MapCenterPoint = this.CityCategoryItem.Coordinate;
            }

            catch (Exception)
            {
                result = "There is an error on loading report data.";
            }
            return result;
        }
 /// <summary>
 /// Constructor
 /// </summary>
 public CityCategoryDetailViewModel()
 {
     this.MapCenterPoint = new Altitude();
     this.CityCategoryPushpinsList = new ObservableCollection<CityData>();
     this.CityCategoryItemsList = new ObservableCollection<CityData>();
     this.CityCategoryItem = new CityData();
 }
Example #9
0
        /// <summary>
        /// Parsing json data from url and add into a list.
        /// </summary>
        /// <param name="parameterValue"></param>
        public void GetCityItemDetails(string parameterValue, GovFinderData cityDetail)
        {
            try
            {
                this.IsDataLoading = true;
                var responseText = string.Empty;
                if (NetworkInterface.GetIsNetworkAvailable())
                {
                    HttpClient          client           = new HttpClient();
                    HttpResponseMessage response         = client.GetAsync(parameterValue).Result;
                    List <CityData>     tempCityDataList = new List <CityData>();
                    if (response.IsSuccessStatusCode)
                    {
                        response.EnsureSuccessStatusCode();
                        responseText = response.Content.ReadAsStringAsync().Result;



                        XElement xmlData = XElement.Parse(responseText, LoadOptions.PreserveWhitespace);
                        foreach (XElement curElement in xmlData.Descendants("row").Descendants("row"))
                        {
                            try
                            {
                                POSH.Socrata.Entity.Models.CityData cityData = new POSH.Socrata.Entity.Models.CityData();
                                cityData.Coordinate = new Altitude();

                                cityData.Name            = GetContents(curElement, cityDetail.Name);
                                cityData.SubTitle        = GetContents(curElement, cityDetail.SubTitle);
                                cityData.Phone           = GetContents(curElement, cityDetail.Phone);
                                cityData.BackgroundImage = "/Assets/CommunityCenters.png";

                                if (cityDetail.Latitude != "NA")
                                {
                                    if (cityDetail.Latitude == "location.latitude")
                                    {
                                        cityData.Coordinate.Latitude = Convert.ToDouble(curElement.Element("location").Attribute("latitude").Value);
                                    }
                                    else
                                    {
                                        cityData.Coordinate.Latitude = Convert.ToDouble(GetContents(curElement, cityDetail.Latitude));
                                    }
                                }
                                else
                                {
                                    cityData.Coordinate.Latitude = 0;
                                }

                                if (cityDetail.Longitude != "NA")
                                {
                                    if (cityDetail.Longitude == "location.longitude")
                                    {
                                        cityData.Coordinate.Longitude = Convert.ToDouble(curElement.Element("location").Attribute("longitude").Value);
                                    }
                                    else
                                    {
                                        cityData.Coordinate.Longitude = Convert.ToDouble(GetContents(curElement, cityDetail.Longitude));
                                    }
                                }
                                else
                                {
                                    cityData.Coordinate.Longitude = 0;
                                }


                                if (cityData.Coordinate.Latitude == 0 && cityData.Coordinate.Longitude == 0)
                                {
                                    cityData.Distance = "No distance";
                                }
                                else
                                {
                                    var distance = CalculateDistance(this.CurrentLocationCoordinates.Latitude, this.CurrentLocationCoordinates.Longitude, cityData.Coordinate.Latitude, cityData.Coordinate.Longitude);
                                    cityData.Distance = distance.ToString() + " miles";
                                }



                                cityData.Category     = cityDetail.DataSetName;
                                cityData.CompositeKey = GenerateCompositeKey(cityData);
                                cityData.Comments     = GetCommentCount(cityData).Result;
                                tempCityDataList.Add(cityData);
                                this.AllCityItems.Add(cityData);

                                if (this.CurrentLocationCoordinates.Latitude != 0 && this.CurrentLocationCoordinates.Longitude != 0 && this.MapCenterPoint.Latitude == 0 && this.MapCenterPoint.Longitude == 0)
                                {
                                    this.MapCenterPoint = this.CurrentLocationCoordinates;
                                }
                                else
                                {
                                    if (this.MapCenterPoint.Latitude == 0 && this.MapCenterPoint.Longitude == 0)
                                    {
                                        this.MapCenterPoint = cityData.Coordinate;
                                    }
                                }
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                    }
                    var sortList = tempCityDataList.OrderBy(item => item.Distance).ThenBy(item => item.Name).ToList();
                    this.CityCategoryItemsList    = new ObservableCollection <CityData>();
                    this.CityCategoryPushpinsList = new ObservableCollection <CityData>();
                    foreach (var item in sortList)
                    {
                        item.IndexNo = this.CityCategoryItemsList.Count + 1;
                        this.CityCategoryItemsList.Add(item);
                        if (this.CityCategoryPushpinsList.Count < 40)
                        {
                            if (item.Coordinate.Latitude != 0 && item.Coordinate.Longitude != 0)
                            {
                                this.CityCategoryPushpinsList.Add(item);
                            }
                        }
                    }

                    if (this.CityCategoryItemsList.FirstOrDefault() != null)
                    {
                        var item = this.CityCategoryItemsList.FirstOrDefault();
                        if (item.Coordinate.Latitude != 0 && item.Coordinate.Longitude != 0)
                        {
                            this.MapCenterPoint = item.Coordinate;
                        }
                        else
                        {
                            this.MapCenterPoint = this.CurrentLocationCoordinates;
                        }
                    }
                    if (!this.AllCityCategoryItems.ContainsKey(cityDetail.DataSetName))
                    {
                        this.AllCityCategoryItems.Add(cityDetail.DataSetName, this.CityCategoryItemsList.ToList());
                    }

                    this.IsDataLoading = false;
                }
                else
                {
                    this.IsDataLoading = false;
                    this.MessageDialog = "No internet connection found. Please check your connection and try again.";
                }
            }
            catch (Exception)
            {
                if (this.CurrentCategoryName.ToLower() == cityDetail.DataSetName.ToLower())
                {
                    this.MessageDialog = "There is some problem on fetching data from server. Please check your internet connection and try again.";
                    this.IsDataLoading = false;
                }
            }
        }