Ejemplo n.º 1
0
        public void GeneratePdfBasicTest()
        {
            var tempPath = Environment.GetEnvironmentVariable("temp");

            var fileCreated = _pdfGenerator.Generate(RoasterUrl, tempPath + @"\", "");

            Assert.IsNotNull(fileCreated);

            FileInfo fileInfo = new FileInfo(tempPath + @"\" + fileCreated);

            fileInfo.Delete();
        }
Ejemplo n.º 2
0
        public override async Task <ConvertReply> Convert(ConvertRequest request, ServerCallContext context)
        {
            var data = await _generator.Generate(request.Data.ToStringUtf8());

            return(await Task.FromResult(new ConvertReply
            {
                Data = ByteString.CopyFrom(data),
                ResultStatus = ResultStatus.Success
            }));
        }
        public async Task <IActionResult> Download(string accountRef)
        {
            var value = RouteData.Values["id"];

            if (value == null)
            {
                return(RedirectToAction("Index", "MyAccounts"));
            }

            Guid.TryParse(value.ToString(), out var id);

            string lowellReference = ApplicationSessionState.GetLowellReferenceFromSurrogate(id);

            if (string.IsNullOrEmpty(lowellReference))
            {
                throw new Exception("No lowell reference found in cache");
            }

            Account account = ApplicationSessionState.GetAccount(lowellReference);

            if (account == null)
            {
                account = await _accountsService.GetAccount(LoggedInUserId, lowellReference);

                ApplicationSessionState.SaveAccount(account, lowellReference);
            }

            List <Transaction> transactions = ApplicationSessionState.GetTransactions(lowellReference);

            if (transactions == null)
            {
                transactions = await _transactionsService.GetTransactions(account.AccountReference);

                ApplicationSessionState.SaveTransactions(transactions, lowellReference);
            }

            transactions.OrderByDescending(x => x.Date).ToList();

            var transactionsVm = _mapper.Map <List <Transaction>, List <TransactionVm> >(transactions);

            var vm = new PdfViewModel()
            {
                AccountBalance   = account.OutstandingBalance,
                AccountName      = account.OriginalCompany,
                AccountReference = account.AccountReference,
                PaymentDetails   = transactionsVm
            };

            var pdf = _pdfGenerator.Generate(vm);

            await _webActivityService.LogStatementDownloaded(account.AccountReference, LoggedInUserId);

            return(File(new MemoryStream(pdf), "application/pdf",
                        $"{account.AccountReference}_{DateTime.UtcNow:ddMMMyyyyHHmmss}.pdf"));
        }
Ejemplo n.º 4
0
        public async Task <PrintRequestQueryResult> Handle(PrintRequestQuery query)
        {
            if (string.IsNullOrEmpty(query.PrintRequestId))
            {
                throw new ArgumentNullException(nameof(query.PrintRequestId));
            }
            if (string.IsNullOrEmpty(query.RequestingUserId))
            {
                throw new ArgumentNullException(nameof(query.RequestingUserId));
            }

            //get the print request
            var printRequest = (await printingRepository.Query(new QueryPrintRequests {
                ById = query.PrintRequestId
            })).Cast <ReferralPrintRequest>().SingleOrDefault();

            if (printRequest == null)
            {
                throw new NotFoundException("print request not found", query.PrintRequestId);
            }

            //get requesting user
            if (printRequest.RequestingUserId != query.RequestingUserId)
            {
                throw new BusinessLogicException($"User {query.RequestingUserId} cannot query print for another user ({printRequest.RequestingUserId})");
            }
            var requestingUser = (await teamRepository.GetMembers(userId: printRequest.RequestingUserId, includeStatuses: activeOnlyStatus)).Cast <Resources.Teams.TeamMember>().SingleOrDefault();

            if (requestingUser == null)
            {
                throw new NotFoundException($"User {printRequest.RequestingUserId} not found", printRequest.RequestingUserId);
            }

            //load the file
            var file = mapper.Map <EvacuationFile>((await caseRepository.QueryCase(new Resources.Cases.EvacuationFilesQuery {
                FileId = printRequest.FileId
            })).Items.Cast <Resources.Cases.Evacuations.EvacuationFile>().SingleOrDefault());

            if (file == null)
            {
                throw new NotFoundException($"Evacuation file {printRequest.FileId} not found", printRequest.Id);
            }
            await evacuationFileLoader.Load(file);

            //Find referrals to print
            var referrals = mapper.Map <IEnumerable <PrintReferral> >(file.Supports.Where(s => printRequest.SupportIds.Contains(s.Id)), opts => opts.Items.Add("evacuationFile", file)).ToArray();

            if (referrals.Length != printRequest.SupportIds.Count())
            {
                throw new BusinessLogicException($"Print request {printRequest.Id} has {printRequest.SupportIds.Count()} linked supports, but evacuation file {printRequest.FileId} doesn't have all of them");
            }

            //replace community codes with readable name
            var communities = await metadataRepository.GetCommunities();

            foreach (var referral in referrals)
            {
                referral.HostCommunity = communities.Where(c => c.Code == referral.HostCommunity).SingleOrDefault()?.Name;
            }

            var isProduction = env.IsProduction();

            //convert referrals to html
            var printedReferrals = await supportsService.GetReferralHtmlPagesAsync(new SupportsToPrint()
            {
                Referrals      = referrals,
                AddSummary     = printRequest.IncludeSummary,
                AddWatermark   = !isProduction,
                RequestingUser = new PrintRequestingUser {
                    Id = requestingUser.Id, FirstName = requestingUser.FirstName, LastName = requestingUser.LastName
                }
            });

            //convert to pdf
            var content = await pdfGenerator.Generate(printedReferrals);

            var contentType = "application/pdf";

            await printingRepository.Manage(new MarkPrintRequestAsComplete { PrintRequestId = printRequest.Id });

            return(new PrintRequestQueryResult
            {
                Content = content,
                ContentType = contentType,
                PrintedOn = DateTime.UtcNow
            });
        }
Ejemplo n.º 5
0
        public async Task <PrintRequestQueryResult> Handle(PrintRequestQuery query)
        {
            if (string.IsNullOrEmpty(query.PrintRequestId))
            {
                throw new ArgumentNullException(nameof(query.PrintRequestId));
            }
            if (string.IsNullOrEmpty(query.RequestingUserId))
            {
                throw new ArgumentNullException(nameof(query.RequestingUserId));
            }

            //get the print request
            var printRequest = (await printingRepository.Query(new QueryPrintRequests {
                ById = query.PrintRequestId
            })).Cast <ReferralPrintRequest>().SingleOrDefault();

            if (printRequest == null)
            {
                throw new NotFoundException("print request not found", query.PrintRequestId);
            }

            //get requesting user
            if (printRequest.RequestingUserId != query.RequestingUserId)
            {
                throw new Exception($"User {query.RequestingUserId} cannot query print for another user ({printRequest.RequestingUserId})");
            }
            var requestingUser = (await teamRepository.GetMembers(userId: printRequest.RequestingUserId)).Cast <Resources.Team.TeamMember>().SingleOrDefault();

            if (requestingUser == null)
            {
                throw new Exception($"User {printRequest.RequestingUserId} not found");
            }

            //load the file
            var file = mapper.Map <Shared.Contracts.Submissions.EvacuationFile>((await caseRepository.QueryCase(new Resources.Cases.EvacuationFilesQuery {
                FileId = printRequest.FileId
            })).Items.Cast <Resources.Cases.EvacuationFile>().SingleOrDefault());

            if (file == null)
            {
                throw new NotFoundException($"Evacuation file {printRequest.FileId} not found", printRequest.Id);
            }
            await evacuationFileLoader.Load(file);

            //Find referrals to print
            var referrals = mapper.Map <IEnumerable <PrintReferral> >(file.Supports.Where(s => printRequest.SupportIds.Contains(s.Id)), opts => opts.Items.Add("evacuationFile", file)).ToArray();

            if (referrals.Count() != printRequest.SupportIds.Count())
            {
                throw new Exception($"Print request {printRequest.Id} has {printRequest.SupportIds.Count()} linked supports, but evacuation file {printRequest.FileId} doesn't have all of them");
            }

            //convert referrals to html
            var printedReferrals = await supportsService.GetReferralHtmlPagesAsync(new SupportsToPrint()
            {
                Referrals      = referrals,
                AddSummary     = printRequest.IncludeSummary,
                RequestingUser = new PrintRequestingUser {
                    Id = requestingUser.Id, DisplayName = $"{requestingUser.FirstName} {requestingUser.LastName[0]}."
                }
            });

            //convert to pdf
            var content = await pdfGenerator.Generate(printedReferrals);

            var contentType = "application/pdf";

            await printingRepository.Manage(new MarkPrintRequestAsComplete { PrintRequestId = printRequest.Id });

            return(new PrintRequestQueryResult
            {
                Content = content,
                ContentType = contentType,
                PrintedOn = DateTime.Now
            });
        }