public async Task <IActionResult> ExportImage(
            string postcode,
            int[] staticClaimIds,
            int[] claimIds, string region)
        {
            var tileClaims = new List <TileViewModel>();

            if (staticClaimIds != null && staticClaimIds.Any())
            {
                var staticClaims = _claimService
                                   .GetStaticClaims(staticClaimIds, region)
                                   .Select(x => new TileViewModel()
                {
                    Value         = x.Value,
                    ImagePath     = x.ImagePath,
                    Heading       = x.Heading,
                    FormattedText = x.ClaimText,
                    ImageDomain   = _asposeOptions.ImageUrl,
                    SourceId      = x.SourceId
                })
                                   .ToList();

                tileClaims.AddRange(staticClaims);
            }

            if (claimIds != null && claimIds.Any())
            {
                var claims = _claimService.GetClaims(claimIds, region);

                var popClaims = _claimService
                                .PopulateValues(claims, postcode, region)
                                .Select(x => new TileViewModel()
                {
                    Heading       = x.ClaimName,
                    Value         = x.ClaimValue,
                    ImagePath     = x.ImagePath,
                    FormattedText = x.FormattedClaimText,
                    ImageDomain   = _asposeOptions.ImageUrl,
                    SourceId      = x.SourceId
                })
                                .ToList();

                tileClaims.AddRange(popClaims);
            }

            var sourceText = _claimService
                             .GetSources(region)
                             .Select(a => $"{a.Id}. {a.Text}")
                             .Aggregate(new StringBuilder(), (a, b) => a.AppendFormat("{0} ", b))
                             .ToString()
                             .Trim();

            var htmls = tileClaims
                        .Select(a => _view.Render(@"Image\SingleView", a))
                        .ToList();

            var authClient = new Auth0.AuthenticationApi.AuthenticationApiClient("mudbath.au.auth0.com");

            var authReq = new AuthenticationRequest()
            {
                ClientId   = _auth0Config.ClientId,
                Username   = _auth0Config.Username,
                Password   = _auth0Config.Password,
                Connection = "Username-Password-Authentication",
                GrantType  = "password",
                Scope      = "openid"
            };

            var resp = await authClient.AuthenticateAsync(authReq);

            var httpClient = new HttpClient
            {
                BaseAddress = new Uri(_asposeOptions.BaseUrl)
            };

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", resp.IdToken);

            var content = JsonConvert.SerializeObject(new { Htmls = htmls, Width = 360 });

            var httpResp = await httpClient.PostAsync(
                "api/image/generate",
                new StringContent(content, Encoding.UTF8, "application/json"));

            if (!httpResp.IsSuccessStatusCode)
            {
                var error = httpResp.Content.ReadAsStringAsync();
                Console.WriteLine(error);
                httpResp.EnsureSuccessStatusCode();
            }

            var images = await httpResp.Content.ReadAsStringAsync();

            var imagesByteList = JsonConvert.DeserializeObject <List <byte[]> >(images);
            var zip            = CreateZip(imagesByteList, sourceText);
            var fileName       = $"image-export-{postcode}-{DateTime.Now.ToString("dd-MM-yyy HH:mm")}.zip";

            return(File(zip, "application/zip", fileName));
        }
        public async Task <IActionResult> ExportPdf(
            string postcode,
            double lat,
            double lng,
            int[] staticClaimIds,
            int[] claimIds,
            Industry industry, string region)
        {
            var sources = _claimService
                          .GetSources(region)
                          .OrderBy(a => a.Id)
                          .ToDictionary(a => a.Id, a => a.Text);

            var pdfModel = new SingleViewPdfViewModel()
            {
                Postcode    = postcode,
                Lat         = lat,
                Lng         = lng,
                Industry    = industry,
                MapsUrl     = await _claimService.GetPathToPostalCodeImage(postcode, region),
                ImageDomain = _asposeOptions.ImageUrl,
                Sources     = sources
            };

            if (staticClaimIds != null && staticClaimIds.Any())
            {
                pdfModel.StaticClaims = _claimService.GetStaticClaims(staticClaimIds, region).ToList();
            }

            if (claimIds != null && claimIds.Any())
            {
                var claims = _claimService.GetClaims(claimIds, region);
                pdfModel.Claims = _claimService.PopulateValues(claims, postcode, region).ToList();
            }

            var html = _view.Render(@"Pdf\SingleView", pdfModel);

            var authClient = new Auth0.AuthenticationApi.AuthenticationApiClient("mudbath.au.auth0.com");

            var authReq = new AuthenticationRequest()
            {
                ClientId   = _auth0Config.ClientId,
                Username   = _auth0Config.Username,
                Password   = _auth0Config.Password,
                Connection = "Username-Password-Authentication",
                GrantType  = "password",
                Scope      = "openid"
            };
            var resp = await authClient.AuthenticateAsync(authReq);

            var httpClient = new HttpClient
            {
                BaseAddress = new Uri(_asposeOptions.BaseUrl)
            };

            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", resp.IdToken);

            var content = JsonConvert.SerializeObject(new { Html = html });

            var httpResp = await httpClient.PostAsync(
                "api/pdf/generate",
                new StringContent(content, Encoding.UTF8, "application/json"));

            if (!httpResp.IsSuccessStatusCode)
            {
                var error = httpResp.Content.ReadAsStringAsync();
                Console.WriteLine(error);
                httpResp.EnsureSuccessStatusCode();
            }

            var pdf = await httpResp.Content.ReadAsStreamAsync();

            return(File(pdf, "application/pdf", $"Export-{postcode}-{DateTime.Now.ToString("dd-MM-yyy HH:mm")}.pdf"));
        }
        public async Task <IActionResult> GeneratePdf(string[] postcodes, string[] svgGuids, Industry industry, string region)
        {
            var sources = _claimService
                          .GetSources(region)
                          .OrderBy(a => a.Id)
                          .ToDictionary(a => a.Id, a => a.Text);

            var pdfModel = new ComparePdfViewModel()
            {
                Industry = industry,
                Sources  = sources
            };

            var populatedPostcodes = new List <ComparisonPostcode>();

            foreach (var code in postcodes)
            {
                populatedPostcodes.Add(_claimService.ComparePostcode(code, industry, region));
            }

            pdfModel.Postcodes          = populatedPostcodes;
            pdfModel.TotalCards         = populatedPostcodes.Sum(x => x.Cards);
            pdfModel.TotalTransactions  = populatedPostcodes.Sum(x => x.Transactions);
            pdfModel.TotalMerchantSpend = populatedPostcodes.Sum(x => x.MerchantSpend);

            pdfModel.ImageDomain = _asposeOptions.ImageUrl;

            var cardSvgPath  = Path.Combine(_env.WebRootPath, "svgs", svgGuids[0] + ".svg");
            var transSvgPath = Path.Combine(_env.WebRootPath, "svgs", svgGuids[1] + ".svg");
            var spendSvgPath = Path.Combine(_env.WebRootPath, "svgs", svgGuids[2] + ".svg");

            pdfModel.CardSvg  = System.IO.File.ReadAllText(cardSvgPath);
            pdfModel.TransSvg = System.IO.File.ReadAllText(transSvgPath);
            pdfModel.SpendSvg = System.IO.File.ReadAllText(spendSvgPath);

            var html = _view.Render(@"Pdf\CompareView", pdfModel);

            var authClient = new Auth0.AuthenticationApi.AuthenticationApiClient("mudbath.au.auth0.com");

            var authReq = new AuthenticationRequest()
            {
                ClientId   = _auth0Config.ClientId,
                Username   = _auth0Config.Username,
                Password   = _auth0Config.Password,
                Connection = "Username-Password-Authentication",
                GrantType  = "password",
                Scope      = "openid"
            };
            var resp = await authClient.AuthenticateAsync(authReq);

            var httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(this._asposeOptions.BaseUrl);
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", resp.IdToken);

            var content = JsonConvert.SerializeObject(new { Html = html });

            var httpResp = await httpClient.PostAsync("api/pdf/generate", new StringContent(content, Encoding.UTF8, "application/json"));

            if (!httpResp.IsSuccessStatusCode)
            {
                var error = httpResp.Content.ReadAsStringAsync();
                Console.WriteLine(error);
                httpResp.EnsureSuccessStatusCode();
            }

            var pdf = await httpResp.Content.ReadAsStreamAsync();

            System.IO.File.Delete(cardSvgPath);
            System.IO.File.Delete(transSvgPath);
            System.IO.File.Delete(spendSvgPath);

            return(File(pdf, "application/pdf", $"comparison-{DateTime.Now.ToString("dd-MM-yyy HH:mm")}.pdf"));
        }