Esempio n. 1
0
        public HttpResponseMessage GetPopularPlaceDetails([FromBody] PopularPlacesModel aPopularPlace)
        {
            PopularPlaceDetailModel popularPlaceDetail = null;

            if (aPopularPlace != null)
            {
                popularPlaceDetail = HereService.GetPopularPlaceDetail(aPopularPlace);
            }

            //return null when detecting invalid
            return(Request.CreateResponse(HttpStatusCode.OK, popularPlaceDetail));
        }
Esempio n. 2
0
        public static PopularPlaceDetailModel GetPopularPlaceDetail(PopularPlacesModel aPopularPlace)
        {
            string detailHref = aPopularPlace.DetailHref;
            bool   validHref  = IsValidPlaceDetailHref(detailHref);

            if (!validHref)
            {
                return(null);
            }

            //using the href with credentials
            detailHref = AppendCredentialsDetailHref(detailHref);

            var activityHref = detailHref; //use for making another http request
            PopularPlaceDetailModel placeDetail = null;

            if (activityHref != null)
            {
                WebClient client       = new WebClient();
                var       itemHrefJson = client.DownloadString(activityHref);
                var       itemHref     = JsonConvert.DeserializeObject <ItemsHref>(itemHrefJson);

                placeDetail = new PopularPlaceDetailModel()
                {
                    Name            = itemHref.name,
                    PlaceId         = itemHref.placeId,
                    FullTextAddress = itemHref.location.address.text,
                };

                placeDetail.Category   = aPopularPlace.Category;
                placeDetail.MapViewUrl = itemHref.view;
                placeDetail.PlaceId    = itemHref.placeId;


                var allContacts = new List <Contact>();
                //add website
                foreach (var site in itemHref.contacts.website)
                {
                    if (site != null)
                    {
                        Contact contact = new Contact()
                        {
                            Value = site.value,
                            Label = site.label
                        };

                        allContacts.Add(contact);
                    }
                }

                //add phone contact
                foreach (var phone in itemHref.contacts.phone)
                {
                    if (phone != null)
                    {
                        Contact phoneContact = new Contact()
                        {
                            Value = phone.value,
                            Label = phone.label
                        };

                        allContacts.Add(phoneContact);
                    }
                }

                placeDetail.Contacts = allContacts;
            }

            return(placeDetail);
        }