public ActionResult ViewPdf(string pageTitle, string viewName, object model, string orientation)
        {
            string userId = base.ValidateUser();
            // Render the view html to a string.
            string htmlText = this.htmlViewRenderer.RenderViewToString(this, viewName, model);

            // Let the html be rendered into a PDF document through iTextSharp.
            byte[] buffer = standardPdfRenderer.Render(htmlText, pageTitle, orientation);

            if (viewName == "SingleInvoice")
            {
                SingleInvoice si = (SingleInvoice)model;
                PDFDocuments  PD = IS.GetPDFDocumentsDetailsByControlId(si.UNID);
                if (PD != null)
                {
                    PD.DocumentData = buffer;
                    long id = IS.SaveOrUpdatePDFDocuments(PD, userId);
                    SaveDocumentToRecentDownloads(null, PD, string.Empty, null, string.Empty);
                }
                else
                {
                    PDFDocuments          pd  = new PDFDocuments();
                    InvoiceManagementView Imv = IS.GetInvoiceManagementViewDetailsByControlId(si.UNID);
                    pd.ControlId      = Imv.ControlId;
                    pd.OrderId        = Imv.OrderId;
                    pd.InvoiceId      = Imv.Id;
                    pd.Location       = Imv.Location;
                    pd.Name           = Imv.Name;
                    pd.ContingentType = Imv.ContingentType;
                    pd.Period         = Imv.Period;
                    pd.PeriodYear     = Imv.PeriodYear;
                    pd.Sector         = Imv.Sector;
                    pd.Week           = Imv.Week;
                    pd.DocumentData   = buffer;
                    pd.DocumentType   = "PDF-Single";
                    pd.DocumentName   = si.Reference;
                    long id = IS.SaveOrUpdatePDFDocuments(pd, userId);
                    SaveDocumentToRecentDownloads(null, pd, string.Empty, null, string.Empty);
                }
            }
            else if (viewName == "InvFPUWK3234")
            {
                InvoiceList ci         = (InvoiceList)model;
                var         InvNoSplit = ci.InvoiceNo.ToString().Split('-');
                var         Period     = ci.Period.ToString().Split('/');
                //To check weather cosolidate sheet is already exsist or not in PDF Documents table
                PDFDocuments PD = GetPDFDocumentForConsolidate(InvNoSplit[1], InvNoSplit[3], Period[0], Period[1]);
                if (PD != null && PD.Id > 0)
                {
                    PD.DocumentData = buffer;
                    long id = IS.SaveOrUpdatePDFDocuments(PD, userId);
                    SaveDocumentToRecentDownloads(null, PD, string.Empty, null, string.Empty);
                }
                else
                {
                    PDFDocuments pd = new PDFDocuments();
                    pd.ControlId      = ci.InvoiceNo;
                    pd.ContingentType = InvNoSplit[3];
                    pd.Period         = Period[0];
                    pd.PeriodYear     = Period[1];
                    pd.Sector         = InvNoSplit[1];
                    pd.DocumentData   = buffer;
                    pd.DocumentType   = "PDF-Consol";
                    pd.DocumentName   = ci.InvoiceNo;
                    long id = IS.SaveOrUpdatePDFDocuments(pd, userId);
                    SaveDocumentToRecentDownloads(null, pd, string.Empty, null, string.Empty);
                }
            }
            // Return the PDF as a binary stream to the client.
            return(new BinaryContentResult(buffer, "application/pdf"));
        }
        public void ViewPdfForParallel(string pageTitle, string viewName, object model, string orientation)
        {
            string userId = "Binoe";
            // Render the view html to a string.
            string htmlText = this.htmlViewRendererforParallel.RenderViewToString(this, viewName, model);

            // Let the html be rendered into a PDF document through iTextSharp.
            byte[] buffer = standardPdfRendererforParallel.Render(htmlText, pageTitle, orientation);

            if (viewName == "SingleInvoice")
            {
                SingleInvoice si = (SingleInvoice)model;
                //PDFDocuments PD = IS.GetPDFDocumentsDetailsByControlId(si.UNID);
                InvoiceManagementView Imv = IS.GetInvoiceManagementViewDetailsByControlId(si.UNID);
                //To check weather cosolidate sheet is already exsist or not in PDF Documents table
                PDFDocuments PD = GetPDFDocumentForConsolidateByOrderId(Imv.OrderId, "PDF-Single");
                if (PD != null && PD.Id > 0)
                {
                    PD.DocumentData = buffer;
                    long id = IS.SaveOrUpdatePDFDocuments(PD, userId);
                }
                else
                {
                    PDFDocuments pd = new PDFDocuments();
                    //InvoiceManagementView Imv = IS.GetInvoiceManagementViewDetailsByControlId(si.UNID);
                    pd.ControlId      = Imv.ControlId;
                    pd.OrderId        = Imv.OrderId;
                    pd.InvoiceId      = Imv.Id;
                    pd.Location       = Imv.Location;
                    pd.Name           = Imv.Name;
                    pd.ContingentType = Imv.ContingentType;
                    pd.Period         = Imv.Period;
                    pd.PeriodYear     = Imv.PeriodYear;
                    pd.Sector         = Imv.Sector;
                    pd.Week           = Imv.Week;
                    pd.DocumentData   = buffer;
                    pd.DocumentType   = "PDF-Single";
                    pd.DocumentName   = si.Reference;
                    long id = IS.SaveOrUpdatePDFDocuments(pd, userId);
                }
            }
            else if (viewName == "InvFPUWK3234")
            {
                InvoiceList ci             = (InvoiceList)model;
                var         InvNoSplit     = ci.InvoiceNo.ToString().Split('-');
                var         Period         = ci.Period.ToString().Split('/');
                var         ControlIdArray = ci.ControlId.Split('-');
                //To check weather cosolidate sheet is already exsist or not in PDF Documents table
                PDFDocuments PD = GetPDFDocumentForConsolidateByOrderId(ci.OrderId, "PDF-Consol");
                //PDFDocuments PD = GetPDFDocumentForConsolidate(InvNoSplit[1], InvNoSplit[3], Period[0], Period[1]);
                if (PD != null && PD.Id > 0)
                {
                    PD.DocumentData = buffer;
                    long id = IS.SaveOrUpdatePDFDocuments(PD, userId);
                }
                else
                {
                    InvoiceManagementView Imv = new InvoiceManagementView();
                    if (ci.ControlId != "N/A")
                    {
                        Imv = IS.GetInvoiceManagementViewDetailsByControlId(ci.ControlId);
                        PDFDocuments pd = new PDFDocuments();


                        pd.OrderId        = ci.OrderId;
                        pd.InvoiceId      = Imv.Id;
                        pd.Name           = ControlIdArray[3];
                        pd.ContingentType = InvNoSplit.Length > 1?InvNoSplit[3]:"";
                        pd.Location       = ControlIdArray[4];
                        pd.ControlId      = ci.ControlId;
                        pd.Period         = ControlIdArray[5];
                        pd.Sector         = ControlIdArray[2];
                        pd.Week           = ci.Week;
                        pd.PeriodYear     = ControlIdArray[7];

                        pd.DocumentData = buffer;
                        pd.DocumentType = "PDF-Consol";
                        pd.DocumentName = ci.InvoiceNo;
                        long id = IS.SaveOrUpdatePDFDocuments(pd, userId);
                    }
                }
            }
            // Return the PDF as a binary stream to the client.
        }