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"));
        }
        public string Success()
        {
            var html = _view.Render("Modal/success", new { Title = "Success", Message = "" });

            return(html);
        }
示例#4
0
        /// <summary>
        ///     Html für EMail Registrierung generieren
        /// </summary>
        /// <param name="request">UserInfos</param>
        /// <returns></returns>
        public string GetMessageOnlyEmail(ExEMailMessageOnly request)
        {
            var htmlEMailOrder = ViewRenderer.Render("EMail/EMailMessageOnly", request);

            return(htmlEMailOrder);
        }