예제 #1
0
        public async Task <IList <Attachment> > CreateResourceCards(string apiKey, IList <DataAnalyticProject.Resource> resources)
        {
            apiKey = WebConfigurationManager.AppSettings["BingMapsApiKey"];
            var attachments = new List <Attachment>();

            foreach (var resource in resources)
            {
                var heroCard = new HeroCard
                {
                    Title    = resource.Name,
                    Subtitle = resource.Address,
                    Text     = $"Resources Available : Medicine {resource.Medicine}, Shelter {resource.Shelter}, Food {resource.Food}, Clothes {resource.Clothes}"
                };

                attachments.Add(heroCard.ToAttachment());

                if (resource.Address != null)
                {
                    var    helper    = new BingHelper();
                    double lat       = Convert.ToDouble(resource.Lat);
                    double lon       = Convert.ToDouble(resource.Lon);
                    var    locations = await helper.GetLocationsByPointAsync(apiKey, lat, lon);

                    var location = locations.Locations.FirstOrDefault();

                    if (location != null)
                    {
                        var image = new CardImage(helper.GetLocationMapImageUrl(apiKey, location));

                        var action = new CardAction()
                        {
                            Value = $"https://www.bing.com/maps?cp={lat}~{lon}&lvl=14&v=2&sV=2&form=S00027",
                            Type  = "openUrl",
                            Title = "Open in maps"
                        };

                        heroCard.Images = new[] { image };
                    }
                }
            }
            return(attachments);
        }