Composite() public method

public Composite ( String Sources, String Query, String Options, String WebSearchOptions, String Market, String Adult, Double Latitude, Double Longitude, String WebFileType, String ImageFilters, String VideoFilters, String VideoSortBy, String NewsLocationOverride, String NewsCategory, String NewsSortBy ) : DataServiceQuery
Sources String Bing search sources Sample Values : web+image+video+news+spell
Query String Bing search query Sample Values : xbox
Options String Specifies options for this request for all Sources. Valid values are: DisableLocationDetection, EnableHighlighting. Sample Values : EnableHighlighting
WebSearchOptions String Specify options for a request to the Web SourceType. Valid values are: DisableHostCollapsing, DisableQueryAlterations. Sample Values : DisableQueryAlterations
Market String Market. Note: Not all Sources support all markets. Sample Values : en-US
Adult String Adult setting is used for filtering sexually explicit content Sample Values : Moderate
Latitude Double Latitude Sample Values : 47.603450
Longitude Double Longitude Sample Values : -122.329696
WebFileType String File extensions to return Sample Values : XLS
ImageFilters String Array of strings that filter the response the API sends based on size, aspect, color, style, face or any combination thereof. Valid values are: Size:Small, Size:Medium, Size:Large, Size:Width:[Width], Size:Height:[Height], Aspect:Square, Aspect:Wide, Aspect:Tall, Color:Color, Color:Monochrome, Style:Photo, Style:Graphics, Face:Face, Face:Portrait, Face:Other. Sample Values : Size:Small+Aspect:Square
VideoFilters String Array of strings that filter the response the API sends based on size, aspect, color, style, face or any combination thereof. Valid values are: Duration:Short, Duration:Medium, Duration:Long, Aspect:Standard, Aspect:Widescreen, Resolution:Low, Resolution:Medium, Resolution:High. Sample Values : Duration:Short+Resolution:High
VideoSortBy String The sort order of results returned Sample Values : Date
NewsLocationOverride String Overrides Bing location detection. This parameter is only applicable in en-US market. Sample Values : US.WA
NewsCategory String The category of news for which to provide results Sample Values : rt_Business
NewsSortBy String The sort order of results returned Sample Values : Date
return DataServiceQuery
        // GET: CarSearch/Details/5
        public async Task<ActionResult> Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Car car = await db.Cars.FindAsync(id);
            if (car == null)
            {
                return HttpNotFound();
            }

            HttpResponseMessage response;

            var client = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/"));
            client.Credentials = new NetworkCredential("accountKey", "bYJ3eVHV+r8dLybppgrXgIetjoLSVumwlpyLDwmbw8w");
            var marketData = client.Composite(
                "image",
                $"{car.model_year} {car.make} {car.model_name} {car.model_trim}",
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null
                ).Execute();
            ViewBag.imageUrl = marketData?.FirstOrDefault()?.Image?.FirstOrDefault()?.MediaUrl;

            

            using (var httpclient = new HttpClient())
            {
                httpclient.BaseAddress = new Uri("Http://www.nhtsa.gov/");

                try
                {
                    response =
                        await httpclient.GetAsync($"webapi/api/Recalls/vehicle/modelyear/{car.model_year}/make/{car.make}/model/{car.model_name}?format=json");
                    ViewBag.recalls = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
                }
                catch (Exception e)
                {
                    return InternalServerError(e);
                }
            }




            return View(car);
        }
示例#2
0
        public async System.Threading.Tasks.Task<ActionResult> Details(int? id)
        {
            CarViewModel cvm = new CarViewModel();
           
           cvm.car = db.Cars.Find(id);
            if (cvm.car == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            HttpResponseMessage response;
            var client = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/")
                   );
            client.Credentials = new NetworkCredential("accountKey", "JDNjFEYyxMGlhlX66nh3S6hQ8aQVOLmI8LJO4QQgdVE");
            var marketData = client.Composite(
                "image",
                $"{cvm.car.model_year} {cvm.car.make} {cvm.car.model_name} {cvm.car.model_trim}",
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null
                ).Execute();

              cvm.imageUrl = marketData.FirstOrDefault()?.Image?.FirstOrDefault()?.MediaUrl;
            
            using (var httpclient = new HttpClient())
            {
                httpclient.BaseAddress = new Uri("Http://www.nhtsa.gov/");

                try
                {
                    response = await httpclient.GetAsync($"webapi/api/Recalls/vehicle/modelyear/{cvm.car.model_year}/make/{cvm.car.make}/model/{cvm.car.model_name}?format=json");
                    cvm.recalls = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
                }

                catch (Exception e)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.InternalServerError);
                }
            }

            return View(cvm);

        }
        // GET: Cars/Details/5
        public async Task<ActionResult> Details(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            CarViewModel carVM = new CarViewModel();
            carVM.Car = db.Cars.Find(id);

            if (carVM.Car == null)
            {
                return HttpNotFound();
            }

            HttpResponseMessage response;
            string content = "";

            carVM.Recalls = "";
            carVM.Image = "";


            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://nhtsa.gov/");

                try
                {
                    response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + carVM.Car.model_year
                        + "/make/" + carVM.Car.make + "/model/" + carVM.Car.model_name + "?format=json");
                    content = await response.Content.ReadAsStringAsync();
                }
                catch (Exception e)
                {
                    return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                }
            }
            carVM.Recalls = JsonConvert.DeserializeObject(content);

            var image = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/"));

            image.Credentials = new NetworkCredential("accountKey", "kz5K3OZBEC4iMUEENmFOEMrosRzd9msMOkZmw6A6YMw");

            var marketData = image.Composite("image", carVM.Car.model_year + " " + carVM.Car.make + " " + carVM.Car.model_name + " " + carVM.Car.model_trim,
                null, null, null, null, null, null, null, null, null, null, null, null, null).Execute();
            carVM.Image = marketData.First().Image.First().MediaUrl;

            return View(carVM);

        }
示例#4
0
        public async Task<IHttpActionResult> getCar(int Id)
        {
            HttpResponseMessage response = new HttpResponseMessage();
            string content = "";
            var Car = db.Cars.Find(Id);
            var Recalls = "";
            var Image = "";
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://www.nhtsa.gov/");
                try
                {
                    content = await response.Content.ReadAsStringAsync();
                    response = await client.GetAsync("webapi/api/recalls/vehicle/modelyear/" + Car.model_year +
                                                                                     "/make/" + Car.make +
                                                                                     "/model/" + Car.model_name + "?format=json");
                }
                catch (Exception e)
                {
                    return InternalServerError(e);
                }
            }
            Recalls = content;

            var image = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/"));

            image.Credentials = new NetworkCredential("accountKey", "uSZdhD53NSOfNv3g0J1hzgObRqsxmFK8iZXUQ3Y2My0");   //"dwmFt1J2rM45AQXkGTk4ebfcVLNcytTxGMHK6dgMreg"
            try
            {
                var marketData = image.Composite(
                    "image",
                    Car.model_year + " " + Car.make + " " + Car.model_name + " " + Car.model_trim,
                    null, null, null, null, null, null, null, null, null, null, null, null, null
                    ).Execute();

                //Image = marketData.First().Image.First().MediaUrl;
                var Images = marketData.FirstOrDefault()?.Image;
                foreach (var Img in Images)
                {
                    if (UrlCtrl.IsUrl(Img.MediaUrl))
                    {
                        Image = Img.MediaUrl;
                        break;
                    }
                    else
                    {
                        continue;
                    }
               }    
            }
            catch (Exception e)
            {
                return InternalServerError(e);
            }
            return Ok(new { car = Car, recalls = Recalls, image = Image });
        }
示例#5
0
        public async Task<IHttpActionResult> GetDetails(CarId id)
        {
            HttpResponseMessage response;
            string content = "";
            var Car = db.Cars.Find(id.id);
            dynamic Recalls;
            var Image = "";

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://www.nhtsa.gov/");
                try
                {
                    response = await client.GetAsync("webapi/api/recalls/vehicle/modelyear/" + Car.model_year +
                                                                                    "/make/" + Car.make +
                                                                                    "/model/" + Car.model_name + "?format=json");
                    content = await response.Content.ReadAsStringAsync();
                }
                catch (Exception e)
                {
                    return InternalServerError(e);
                }
            }
            // Recalls = JsonConvert.DeserializeObject(content);
            Recalls = content;

            var image = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/"));

            image.Credentials = new NetworkCredential("accountKey", "uSZdhD53NSOfNv3g0J1hzgObRqsxmFK8iZXUQ3Y2My0");   //"dwmFt1J2rM45AQXkGTk4ebfcVLNcytTxGMHK6dgMreg"
            var marketData = image.Composite(
                "image",
                    Car.model_year + " " + Car.make + " " + Car.model_name + " " + Car.model_trim,
                    null, null, null, null, null, null, null, null, null, null, null, null, null
                    ).Execute();

            Image = marketData.First().Image.First().MediaUrl;
            return Ok(new { car = Car, recalls = Recalls, image = Image });

        }
示例#6
0
        public async Task<IHttpActionResult> getCar(idClass id)
        {
            HttpResponseMessage response;
            string content = "";
            var Car = db.Cars.Find(id.id);

            var Image = "";
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://www.nhtsa.gov/");
                try
                {
                    response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + Car.model_year +
                                                                                    "/make/" + Car.make +
                                                                                    "/model/" + Car.model_name + "?format=json");
                    content = await response.Content.ReadAsStringAsync();
                }
                catch (Exception e)
                {
                    return InternalServerError(e);
                }
            }

            dynamic Recalls = JsonConvert.DeserializeObject(content);


            var image = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/v1/Image"));

            image.Credentials = new NetworkCredential("accountKey", "9DVmvKlSSAnTU1On117Lu4rMsXdLgjDI+sUWSdxdzIc");   //"dwmFt1J2rM45AQXkGTk4ebfcVLNcytTxGMHK6dgMreg"
            var marketData = image.Composite(
                "image",
                Car.model_year + " " + Car.make + " " + Car.model_name + " " + Car.model_trim + " " + "NOT ebay",
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null
                ).Execute();

            //Image = marketData.First().Image.First().MediaUrl;
            //return Ok(new { car = Car, recalls = Recalls, image = Image });
            //return JSON.parse(new { car = Car, recalls = Recalls, image = Image });
            // return Ok(Recalls);
            var Images = marketData.FirstOrDefault()?.Image;
            //int imgCnt = Images.Count();
            foreach (var Img in Images)
            {

                if (UrlCtrl.IsUrl(Img.MediaUrl))
                {
                    Image = Img.MediaUrl;
                    break;
                }
                else
                {
                    continue;
                }


            }
            if (string.IsNullOrWhiteSpace(Image))
            {
                Image = "images/carnotfound.jpg";
            }
            return Ok(new { car = Car, recalls = Recalls, image = Image });
        }
示例#7
0
 public async Task<IHttpActionResult> getCar(int Id)
 {
     HttpResponseMessage response;
     string content = "";
     var Car = db.Cars.Find(Id);
     var Recalls = "";
     var Image = "";
     using (var client = new HttpClient())
     {
         client.BaseAddress = new Uri("http://www.nhtsa.gov/");
         try
         {
             response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + Car.model_year +
                                                                             "/make/" + Car.make +
                                                                             "/model/" + Car.model_name + "?format=json");
             content = await response.Content.ReadAsStringAsync();
         }
         catch (Exception e)
         {
             return InternalServerError(e);
         }
     }
     Recalls = content;
     ​
     var image = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/"));​
     image.Credentials = new NetworkCredential("accountKey", "9DVmvKlSSAnTU1On117Lu4rMsXdLgjDI+sUWSdxdzIc");   //"dwmFt1J2rM45AQXkGTk4ebfcVLNcytTxGMHK6dgMreg"
     var marketData = image.Composite(
         "image",
         Car.model_year + " " + Car.make + " " + Car.model_name + " " + Car.model_trim,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null,
         null
         ).Execute();​
     Image = marketData.First().Image.First().MediaUrl;
     return Ok(new { car = Car, recalls = Recalls, image = Image });​
 }
示例#8
0
        public async Task<IHttpActionResult> GetCar(IdParm id)
        {
            // Getting car images through Bing Search 
            var car = db.Cars.Find(id.id);
            if (car == null)
                return await Task.FromResult(NotFound());

            HttpResponseMessage response;
            // Get Credentials for Bing from Web Config File
            string searchApiServiceRootUri = ConfigurationManager.AppSettings["searchApiServiceRootUri"];
            string accountKeyPass = ConfigurationManager.AppSettings["searchApiAccountKey"];

            var client = new BingSearchContainer(new Uri(searchApiServiceRootUri));
            client.Credentials = new NetworkCredential("accountKey", accountKeyPass);
            
            var marketData = client.Composite(
                "image",
                car.model_year + ' ' + car.make + ' ' + car.model_name + ' ' + car.model_trim,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null
                ).Execute();

            var result = marketData.FirstOrDefault();
            var image = result != null ? result.Image : null;
            var firstImage = image != null ? image.FirstOrDefault() : null;
            var imgUrl = firstImage != null ? firstImage.MediaUrl : null;

            // Getting recalls from NHTSA
            dynamic recalls;
            string recallBaseAddress = ConfigurationManager.AppSettings["recallBaseAddress"];
            using (var httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri(recallBaseAddress);

                try
                {
                    response = await httpClient.GetAsync("webapi/api/Recalls/vehicle/modelyear/"+car.model_year+"/make/"
                        +car.make+"/model/"+car.model_name +"? FormatException=json");
                    
                    // JSON returns a string so deserialize it before sending it
                    recalls = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
                }
                catch (Exception e)
                {
                    return InternalServerError(e);
                }
            }

            return Ok(new { car, imgUrl, recalls });
        }
示例#9
0
        public async Task<IHttpActionResult> GetCar(IdParam id)
        {
            var car = db.Cars.Find(id.id);

            if (car == null)
            {
                return await Task.FromResult(NotFound());
            }

            HttpResponseMessage response;

            var client = new BingSearchContainer(
        	new Uri("https://api.datamarket.azure.com/Bing/search/")
            	);
            client.Credentials = new NetworkCredential("accountKey", "baDOTqrNCHJ38GxTzgc8o7rpbstAS9VG5gYE8kfkHro");
            var marketData = client.Composite(
	        "image",
	        car.model_year + " " + car.make + " " + car.model_name + " " + car.model_trim,
	        null,
	        null,
	        null,
	        null,
	        null,
	        null,
	        null,
	        null,
	        null,
	        null,
	        null,
	        null,
	        null
	        ).Execute();

            var result = marketData.FirstOrDefault();
            var image = result != null ? result.Image : null;
            var firstImage = image != null ? image.FirstOrDefault() : null;
            var mediaUrl = firstImage != null ? firstImage.MediaUrl : null;

            dynamic recalls;
            var temp = car.model_name;
            if(temp.Contains('&'))
            {
                var buildit = temp.Split('&');
                var count = buildit.Count();
                temp = "";
                foreach(var item in buildit)
                {
                    if(count > 1)
                    {
                        temp += item + "And";
                    }
                    else
                    {
                        temp += item;
                    }
                    count--;
                }
            }

            using (var httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri("http://www.nhtsa.gov/");

                try
                {
                    response = await httpClient.GetAsync("webapi/api/Recalls/vehicle/modelyear/"+car.model_year+"/make/"+car.make+"/model/"+temp+"?format=json");
                    recalls = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
                }
                catch (Exception e)
                {
                    return InternalServerError(e);
                }
            }

            return Ok(new { car, mediaUrl, recalls });
        }
示例#10
0
        public async Task<IHttpActionResult> GetCar(IdParam id)
        {
            var car = db.Cars.Find(id.Id);
            if(car == null)
            {
                return await Task.FromResult(NotFound());
            }

            HttpResponseMessage response;

            var client = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/"));
            client.Credentials = new NetworkCredential("accountKey", "p378hNjOm0HKvheOJd/KFybFEM8wmO0orgleQPGPz9s");
            var marketData = client.Composite(
                "image",
                $"{car.model_year} {car.make} {car.model_name} {car.model_trim}",
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null
                ).Execute();

            var imageUrl = marketData?.FirstOrDefault()?.Image?.FirstOrDefault()?.MediaUrl;

            dynamic recalls;

            using( var httpClient = new HttpClient())
            {
                httpClient.BaseAddress = new Uri("http://www.nhtsa.gov");

                try
                {
                    response = await httpClient.GetAsync($"webapi/api/Recalls/vehicle/modelyear/{car.model_year}/make/{car.make}/model/{car.model_name}?format=json");
                    recalls = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
                }
                catch (Exception e)
                {
                    return InternalServerError(e);
                }
            }

            return Ok(new { car, imageUrl, recalls });
        }
示例#11
0
        public async Task<IHttpActionResult> getCar([FromBody]int Id)
        {
            var car = db.Cars.Find(Id);
            dynamic recalls = "";
            var image = "";

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://www.nhtsa.gov/");
                try
                {
                    var response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + car.model_year + "/make/" + car.make + "/model/" + car.model_name + "?format=json");
                    recalls = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
                }
                catch (Exception e)
                {
                    return InternalServerError(e);
                }
            }

            var images = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/"));
            images.Credentials = new NetworkCredential("accountKey",
                ConfigurationManager.AppSettings["bing"]);
            var marketData = images.Composite(
                "image",
                car.model_year + " " + car.make + " " + car.model_name + " " + car.model_trim,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null
                ).Execute();

            image = marketData.First().Image.First().MediaUrl;

            return Ok(new { car, image, recalls });
        }
示例#12
0
        public async Task<IHttpActionResult> GetCar(IdParam id) //(Selected selected)
        {
            HttpResponseMessage response;
            string content = "";
            var Car = db.Cars.Find(id.id); //(Selected selected) passes in model, make, 
            dynamic Recalls = "";
            var Image = "";
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://www.nhtsa.gov/");
                try
                {
                    response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + Car.model_year +
                                                                                    "/make/" + Car.make +
                                                                                    "/model/" + Car.model_name + "?format=json");
                    content = await response.Content.ReadAsStringAsync();
                }
                catch (Exception e)
                {
                    return InternalServerError(e);
                }
            }
            Recalls = JsonConvert.DeserializeObject(content);

            var image = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/v1/Composite"));

            image.Credentials = new NetworkCredential("accountKey", "/8RvXOXJ4fcq5pAnNMdOtiueBjVHcWUUFAr8ZhHPJsI");
            var marketData = image.Composite(
                "image",
                Car.model_year + " " + Car.make + " " + Car.model_name + " " + Car.model_trim + " " + "NOT ebay",
                null,
                null,
                null,
                "Moderate",
                null,
                null,
                null,
                "Size:Large+Style:Photo",
                null,
                null,
                null,
                null,
                null
                ).Execute();

            var Images = marketData.FirstOrDefault()?.Image;
            foreach (var Img in Images)
            {
                
                if (UrlCtrl.IsUrl(Img.MediaUrl))
                {
                    Image = Img.MediaUrl;
                    break;
                } else
                {
                    continue;
                }

            }

            if (string.IsNullOrWhiteSpace(Image))
            {
                Image = "../img/car404.jpg";
            }

            return Ok(new { car = Car, recalls = Recalls, image = Image });

        }
示例#13
0
        public async Task<IHttpActionResult>GetCar(int id)
        {
            var car = db.Cars.Find(id);
            if (car == null)
            {
                return await Task.FromResult(NotFound());
            }

            HttpResponseMessage response;

            var client = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/")
       );
            client.Credentials = new NetworkCredential("accountKey", "JDNjFEYyxMGlhlX66nh3S6hQ8aQVOLmI8LJO4QQgdVE");
            var marketData = client.Composite(
                "image",
                $"{car.model_year} {car.make} {car.model_name} {car.model_trim}",
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null
                ).Execute();

            var imageUrl = marketData.FirstOrDefault()?.Image?.FirstOrDefault()?.MediaUrl;

            //var result = marketData.FirstOrDefault();
            //var image = result != null ? result.Image : null;
            //var firstImage = image != null ? image.FirstOrDefault() : null;
            //var imageUrl = firstImage != null ? firstImage.MediaUrl : null;


            dynamic recalls;
            using (var httpclient = new HttpClient())
            {
                httpclient.BaseAddress = new Uri("Http://www.nhtsa.gov/");

                try
                {                                          
                    response = await httpclient.GetAsync($"webapi/api/Recalls/vehicle/modelyear/{car.model_year}/make/{car.make}/model/{car.model_name}?format=json");
                    recalls = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());           
                }

                catch (Exception e)
                {
                    return InternalServerError(e);
                }
            }

            return Ok(new { car, imageUrl, recalls });
        } 
示例#14
0
        public async Task<ActionResult> Details(int id) {

            CarSearch car = new CarSearch();
            car.Car = db.Car.Find(id);


            var client = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/"));
            client.Credentials = new NetworkCredential("accountKey", "o+nYHPyZpmhku+bXtDn0AFRZ79Jnxd4KS/QkoHd3B3E");
            var marketData = client.Composite(
                "image",
                car.Car.model_year + car.Car.make + car.Car.model_name + car.Car.model_trim,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null
                ).Execute();

            var result = marketData.FirstOrDefault();
            var image = result != null ? result.Image : null;
            var firstImage = image != null ? image.FirstOrDefault() : null;
            car.ImageUrl = firstImage != null ? firstImage.MediaUrl : "/Images/img_not_found.jpg";

            //dynamic recalls;

            using (var httpClient = new HttpClient()) {
                httpClient.BaseAddress = new Uri("http://www.nhtsa.gov/");

                //try {
                var response = await httpClient.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + car.Car.model_year + "/make/" + car.Car.make + "/model/" + car.Car.model_name + "?format=json");
                car.Recalls = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
                //}
                //catch (Exception e) {
                //    return InternalServerError(e);
                //}
            }

            return View(car);
        }
示例#15
0
        public async Task<IHttpActionResult> getCar(idClass id)
        {
            HttpResponseMessage response;
            string content = "";
            var Car = db.Cars.Find(id.id);
            var Image = "";
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://www.nhtsa.gov/");
                try
                {
                    response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + Car.model_year +
                                                                                    "/make/" + Car.make +
                                                                                    "/model/" + Car.model_name + "?format=json");
                    content = await response.Content.ReadAsStringAsync();
                }
                catch (Exception e)
                {
                    return InternalServerError(e);
                }
            }

            dynamic Recalls = JsonConvert.DeserializeObject(content);

            // Bing Search API
            var image = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/v1/Image"));

            image.Credentials = new NetworkCredential("accountKey", "s8cUIpKPWJ609E7VqtBbx9HNdRp9Z2NbUne/HyPgxbQ");

            var marketData = image.Composite(
               "image",
               Car.model_year + " " + Car.make + " " + Car.model_name + " " + Car.model_trim + " " + "NOT ebay",
               null, null, null, null, null, null, null, null, null, null, null, null, null).Execute();

              var Images = marketData.FirstOrDefault().Image;

            foreach(var Img in Images)
            {
                if(UrlCtrl.isUrl(Img.MediaUrl))
                {
                    Image = Img.MediaUrl;
                    break;
                }
                else
                {
                    continue;
                }
            }

            if(string.IsNullOrWhiteSpace (Image))
            {
                Image = "/images/no-image.png";
            }

            return Ok(new { car = Car, recalls = Recalls, image = Image });
        }
        public async Task<IHttpActionResult> GetCarDetails(IdParam Id)
        {
            // ---- get Recall Information -----

            HttpResponseMessage response;
            string content = "";
            var Car = db.Cars.Find(Id.id);
            dynamic Recalls = "";
            var Image = "";

            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://www.nhtsa.gov/");
                try
                {
                    response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + Car.model_year +
                                                                                    "/make/" + Car.make +
                                                                                    "/model/" + Car.model_name + "?format=json");
                    content = await response.Content.ReadAsStringAsync();
                }
                catch (Exception e)
                {
                    return InternalServerError(e);
                }
            }
            Recalls = JsonConvert.DeserializeObject(content);


            // ---------  Get Image --------

            var image = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/"));

            image.Credentials = new NetworkCredential("accountKey", "ih3uuQpD5VI9IrIcovu/1dEIjaJXkB6eFMgSg9CCxGY");
            var marketData = image.Composite(
                 "image",
                 Car.model_year + " " + Car.make + " " + Car.model_name + " " + Car.model_trim ,
                 null,
                 null,
                 null,
                 null,
                 null,
                 null,
                 null,
                 null,
                 null,
                 null,
                 null,
                 null,
                 null
                 ).Execute();

            var Images = marketData?.FirstOrDefault()?.Image;

            foreach (var Img in Images)
            {
                if (UrlCtrl.IsUrl(Img.MediaUrl))
                {
                    Image = Img.MediaUrl;
                    break;
                }
                else
                {
                    continue;
                }
            }

            return Ok(new { car = Car, recalls = Recalls, image=Image });
        }