Exemplo n.º 1
0
        private async Task <string> AssembleReferralHtml(PrintRequestingUser requestingUser, IEnumerable <PrintReferral> referrals, bool includeSummary, bool addWatermark)
        {
            var referralHtml = string.Empty;

            foreach (var referral in referrals)
            {
                referral.VolunteerFirstName = requestingUser.FirstName;
                referral.VolunteerLastName  = requestingUser.LastName;
                referral.DisplayWatermark   = addWatermark;

                var newHtml = CreateReferralHtmlPages(referral);
                referralHtml = $"{referralHtml}{newHtml}";
            }
            var summaryHtml = includeSummary ? await CreateReferalHtmlSummary(referrals, requestingUser, addWatermark) : string.Empty;

            var finalHtml = $"{summaryHtml}{referralHtml}";

            var handleBars = Handlebars.Create();

            handleBars.RegisterTemplate("stylePartial", GetCSSPartialView());
            handleBars.RegisterTemplate("bodyPartial", finalHtml);
            var template      = handleBars.Compile(LoadTemplate("MasterLayout"));
            var assembledHtml = template(string.Empty);

            return(assembledHtml);
        }
Exemplo n.º 2
0
        private async Task <string> CreateReferalHtmlSummary(IEnumerable <PrintReferral> supports, PrintRequestingUser requestingUser, bool addWatermark)
        {
            await Task.CompletedTask;
            var handleBars = CreateHandleBars();

            var result            = string.Empty;
            var itemsHtml         = string.Empty;
            var summaryBreakCount = 0;
            var printedCount      = 0;

            foreach (var printReferral in supports)
            {
                summaryBreakCount += 1;
                printedCount      += 1;
                var partialViewType        = printReferral.Type;
                var partialViewDisplayName = partialViewType.GetType()
                                             .GetMember(partialViewType.ToString())
                                             .First()
                                             .GetCustomAttribute <DisplayAttribute>()
                                             .GetName();
                handleBars.RegisterTemplate("titlePartial", partialViewDisplayName);

                var useSummaryVersion  = partialViewType == PrintReferralType.Hotel || partialViewType == PrintReferralType.Billeting;
                var partialItemsSource = GetItemsPartialView(partialViewType, useSummaryVersion);
                handleBars.RegisterTemplate("itemsPartial", partialItemsSource);

                handleBars.RegisterTemplate("itemsDetailTitle", "Details");

                var partialNotesSource = GetNotesPartialView(partialViewType);
                handleBars.RegisterTemplate("notesPartial", partialNotesSource);

                var template = handleBars.Compile(LoadTemplate(ReferalMainViews.SummaryItem.ToString()));

                var purchaserName      = printReferral.PurchaserName;
                var volunteerFirstName = requestingUser.FirstName;
                var volunteerLastName  = requestingUser.LastName;
                var itemResult         = template(printReferral);
                itemsHtml = $"{itemsHtml}{itemResult}";

                if (summaryBreakCount == 3 || printedCount == supports.Count())
                {
                    summaryBreakCount = 0;
                    handleBars.RegisterTemplate("summaryItemsPartial", itemsHtml);

                    var mainTemplate = handleBars.Compile(LoadTemplate(ReferalMainViews.Summary.ToString()));
                    var data         = new { volunteerFirstName, volunteerLastName, purchaserName };
                    result    = $"{result}{mainTemplate(data)}{pageBreak}";
                    itemsHtml = string.Empty;
                }
            }

            return(result);
        }