Exemplo n.º 1
0
        public async Task <ActionResult <List <Selfie> > > GetTopSelfiesAsync(int?cameraId)
        {
            var           topVoteEntries = _repository.GetTopEntriesAsync(5, cameraId);
            List <Selfie> topImages      = new List <Selfie>();

            foreach (var entry in await topVoteEntries)
            {
                TextCamImage image = await _textCamService.GetImageAsync(entry);

                topImages.Add(new Selfie(image));
            }
            return(topImages);
        }
Exemplo n.º 2
0
        internal async Task <TextCamImage> GetImageAsync(Tuple <string, int> entry)
        {
            TextCamImage        image    = null;
            var                 camera   = _repository.GetCameraByCameraNameAsync(entry.Item1.Substring(0, 2));
            var                 imageId  = entry.Item1.Substring(2);
            HttpResponseMessage response = await client.GetAsync($"/images/camera/{camera.Result.CameraId_API}/{imageId}");

            if (response.IsSuccessStatusCode)
            {
                var jsonResult = await response.Content.ReadAsStringAsync();

                JObject apiResponse = JObject.Parse(jsonResult);
                JToken  result      = apiResponse["image"].Children().FirstOrDefault();
                image        = result.ToObject <TextCamImage>();
                image.Camera = await camera;
            }
            return(image);
        }
Exemplo n.º 3
0
        internal async Task <List <TextCamImage> > GetCameraImagesAsync(Camera camera)
        {
            List <TextCamImage> camImages = new List <TextCamImage>();
            HttpResponseMessage response  = await client.GetAsync($"/images/camera/{camera.CameraId_API}/vote");

            if (response.IsSuccessStatusCode)
            {
                var jsonResult = await response.Content.ReadAsStringAsync();

                JObject        apiResponse = JObject.Parse(jsonResult);
                IList <JToken> results     = apiResponse["images"].Children().ToList();
                foreach (JToken result in results)
                {
                    TextCamImage image = result.ToObject <TextCamImage>();
                    image.Camera = camera;
                    camImages.Add(image);
                }
            }
            return(camImages);
        }