public void GeneratePdf(string invoiceNumber, Stream pdfStream)
        {
            string           name;
            GetInvoiceResult invoice = this.InvoiceService.GetInvoice(new GetInvoiceParameter(invoiceNumber)
            {
                GetInvoiceLines = true
            });
            InvoiceModel invoiceModel = this.GetInvoiceMapper.MapResult(invoice, null);
            Theme        theme        = base.UnitOfWork.GetRepository <Theme>().Get(SiteContext.Current.WebsiteDto.ThemeId);

            if (theme.ThemeSource == null)
            {
                name = (theme.IsSystemTheme ? "System" : "User");
            }
            else
            {
                name = theme.ThemeSource.Name;
            }
            string          str    = string.Format("~/frontendresources/{0}/{1}/pdfviews/invoicedetails.cshtml", name, theme.Name);
            ThemeContentDto byPath = this.ThemeContentProvider.GetByPath(str);

            if (invoiceModel.InvoiceNumber.Contains("-"))
            {
                string[] invoiceNumberArray = invoiceModel.InvoiceNumber.Split('-');
                if (invoiceNumberArray.Length > 0)
                {
                    invoiceModel.InvoiceNumber = invoiceNumberArray[0];
                }
            }
            dynamic  expando     = invoiceModel.ToJson(false).ToExpando();
            DateTime invoiceDate = invoiceModel.InvoiceDate;

            expando.InvoiceDateDisplay = invoiceDate.ToShortDateString();
            invoiceDate            = invoiceModel.DueDate;
            expando.DueDateDisplay = invoiceDate.ToShortDateString();
            decimal invoiceTotal = invoiceModel.InvoiceTotal - invoiceModel.CurrentBalance;

            expando.PaymentTotalDisplay = invoiceTotal.ToString("0.00");

            foreach (dynamic obj in (IEnumerable)expando.InvoiceLines)
            {
                obj.QtyInvoicedDisplay = obj.QtyInvoiced.ToString("0");
            }

            //Display Company logo based on website
            CustomSettings customSettings = new CustomSettings();

            expando.CompanyIdentifier = customSettings.CompanyNameIdentifier;

            PdfGeneratorHelper.GeneratePdf(this.EmailTemplateRenderer.Render(byPath.Content, expando), pdfStream);
        }
        public void GeneratePdf(string orderNumber, string stEmail, string stPostalCode, Stream pdfStream)
        {
            string         name;
            string         str;
            object         shortDateString;
            GetOrderResult getOrderResult = this.OrderService.GetOrder(new GetOrderParameter(orderNumber)
            {
                GetOrderLines = true,
                GetShipments  = true,
                STPostalCode  = stPostalCode,
                STEmail       = stEmail
            });

            if (getOrderResult.ResultCode != ResultCode.Success)
            {
                return;
            }
            OrderModel orderModel = this.GetOrderMapper.MapResult(getOrderResult, null);
            Theme      theme      = base.UnitOfWork.GetRepository <Theme>().Get(SiteContext.Current.WebsiteDto.ThemeId);

            if (theme.ThemeSource == null)
            {
                name = (theme.IsSystemTheme ? "System" : "User");
            }
            else
            {
                name = theme.ThemeSource.Name;
            }
            string          frontEndResourcePath = string.Format("~/frontendresources/{0}/{1}/pdfviews/orderdetails.cshtml", name, theme.Name);
            ThemeContentDto themeContentDto      = this.ThemeContentProvider.GetByPath(frontEndResourcePath);
            dynamic         model         = orderModel.ToJson(false).ToExpando();
            decimal         totalDiscount = this.GetTotalDiscount(orderModel);
            dynamic         obj           = model;

            str = (totalDiscount > decimal.Zero ? totalDiscount.ToString("0.00") : string.Empty);
            obj.TotalDiscountDisplay = str;
            DateTime orderDate = orderModel.OrderDate;

            model.OrderDateDisplay = orderDate.ToShortDateString();
            dynamic  obj1 = model;
            DateTime?requestedDeliveryDateDisplay = orderModel.RequestedDeliveryDateDisplay;

            if (requestedDeliveryDateDisplay.HasValue)
            {
                shortDateString = requestedDeliveryDateDisplay.GetValueOrDefault().ToShortDateString();
            }
            else
            {
                shortDateString = null;
            }
            if (shortDateString == null)
            {
                shortDateString = string.Empty;
            }
            obj1.RequestedDeliveryDate = (string)shortDateString;
            foreach (dynamic shipmentPackage in (IEnumerable)model.ShipmentPackages)
            {
                dynamic obj2 = shipmentPackage;
                obj2.ShipmentDateDisplay = Convert.ToDateTime(shipmentPackage.ShipmentDate).ToShortDateString();
            }
            foreach (dynamic orderLine in (IEnumerable)model.OrderLines)
            {
                orderLine.QtyOrderedDisplay = orderLine.QtyOrdered.ToString("0");
            }

            //Display Company logo based on website
            CustomSettings customSettings = new CustomSettings();

            model.CompanyIdentifier = customSettings.CompanyNameIdentifier;

            PdfGeneratorHelper.GeneratePdf(this.EmailTemplateRenderer.Render(themeContentDto.Content, model), pdfStream);
        }