public List <PhotoModel> getListaPhotos(ALbumModel request)
        {
            List <PhotoModel> PhotoInfo = new List <PhotoModel>();

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Clear();

                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                //Sending request to find web api REST service resource GetAllEmployees using HttpClient
                var Res = client.GetAsync("https://jsonplaceholder.typicode.com/photos").Result;

                //Checking the response is successful or not which is sent using HttpClient
                if (Res.IsSuccessStatusCode)
                {
                    //Storing the response details recieved from web api
                    var Response = Res.Content.ReadAsStringAsync().Result;

                    //Deserializing the response recieved from web api and storing into the Employee list
                    PhotoInfo = JsonConvert.DeserializeObject <List <PhotoModel> >(Response);
                }
                //returning the employee list to view
                return(PhotoInfo.Where(x => x.albumId == request.id).ToList());
            }
        }
Пример #2
0
        public JsonResult AlbumPhotos(ALbumModel request)
        {
            var result = service.getListaPhotos(request);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }