Esempio n. 1
0
        public async Task <IActionResult> GetSiteUrl(string id, string format = "")
        {
            var siteUrl = await _repository.GetUrlById(id);

            if (siteUrl == null)
            {
                return(BadRequest());
            }
            siteUrl.LastViewed = DateTime.Now;
            siteUrl.ViewsCount++;
            await _repository.Update(siteUrl);

            if (string.IsNullOrWhiteSpace(format))
            {
                return(Ok(siteUrl));
            }
            return(await GetUrlAsFile(id, format, siteUrl));
        }
Esempio n. 2
0
        public async Task <IActionResult> GetImage(string id)
        {
            var url = await _israelHikingRepository.GetUrlById(id);

            if (url == null)
            {
                return(NotFound());
            }
            var imageData = await _imageCreationService.Create(JsonConvert.DeserializeObject <DataContainer>(url.JsonData));

            return(new FileContentResult(imageData, new MediaTypeHeaderValue("image/png")));
        }
Esempio n. 3
0
        public async Task <IActionResult> GetHtml(string id)
        {
            _logger.LogDebug("Received a call to get html for: " + id);
            var url = await _repository.GetUrlById(id);

            var contentResult = new ContentResult
            {
                Content     = GetPage(url.Title, Url.Content("~/api/images/" + url.Id), url.Description),
                ContentType = "text/html"
            };

            return(contentResult);
        }
Esempio n. 4
0
        public void GetImage_UrlInDatabase_ShouldCreateIt()
        {
            var siteUrl = new SiteUrl
            {
                Id       = "1",
                JsonData = JsonConvert.SerializeObject(new DataContainer())
            };

            _repository.GetUrlById(siteUrl.Id).Returns(siteUrl);

            var results = _controller.GetImage(siteUrl.Id).Result as FileContentResult;

            Assert.IsNotNull(results);
        }
Esempio n. 5
0
        public void GetSiteUrl_ItemInDatabase_ShouldReturnIt()
        {
            var id = "someId";

            _israelHikingRepository.GetUrlById(id).Returns(new SiteUrl {
                Id = id
            });

            var results = _controller.GetSiteUrl(id).Result as OkObjectResult;

            Assert.IsNotNull(results);
            var content = results.Value as SiteUrl;

            Assert.IsNotNull(results);
            Assert.AreEqual(id, content.Id);
        }