예제 #1
0
        public ActionResult Create(HelpLevel3 helpLevel3)
        {
            if (ModelState.IsValid)
            {
                if (helpLevel3.URLObj != null)
                {
                    string fileName = Path.GetFileName(helpLevel3.URLObj.FileName);
                    //Get Upload path from Web.Config file AppSettings.
                    string uploadPath = ConfigurationManager.AppSettings["HelpOnlineHTMLPath"].ToString();
                    //Its Create complete path to store in server.
                    helpLevel3.URL = fileName;
                    //To copy and save file into server.
                    helpLevel3.URLObj.SaveAs(Server.MapPath(uploadPath + fileName));
                }
                else
                {
                    helpLevel3.URL = "";
                }


                helpLevel3DB.InsertLevel3(helpLevel3);
                return(RedirectToAction("Index/" + helpLevel3.ParentId));
            }
            makeParentList();
            return(View());
        }
예제 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            HelpLevel3 helpLevel3 = helpLevel3DB.GetHelpLevel3ById(id);

            helpLevel3DB.DeleleLevel3(id);
            return(RedirectToAction("Index/" + helpLevel3.ParentId));
        }
예제 #3
0
        // GET: HelpOnline/AdminLevel3/Details/5
        public ActionResult Details(int id)
        {
            HelpLevel3 helpLevel3 = helpLevel3DB.GetHelpLevel3ById(id);

            if (helpLevel3 == null)
            {
                return(HttpNotFound());
            }
            HelpLevel2 parent = helpLevel2DB.GetHelpLevel2ById(helpLevel3.ParentId);

            helpLevel3.ParentTopic = parent;
            return(View(helpLevel3));
        }
예제 #4
0
        // GET: HelpOnline/AdminLevel3/Delete/5
        public ActionResult Delete(int id)
        {
            if (id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HelpLevel3 helpLevel3 = helpLevel3DB.GetHelpLevel3ById(id);

            if (helpLevel3 == null)
            {
                return(HttpNotFound());
            }
            //helpLevel3DB.DeleleLevel3(id);
            return(View(helpLevel3));
        }
예제 #5
0
        public ActionResult ToPDFContent(int id)
        {
            HelpLevel3 helpLevel3 = helpLevel3DB.GetHelpLevel3ById(id);

            if (helpLevel3 == null)
            {
                ViewBag.ErrorMessage = "Can not find this recource";
                return(RedirectToAction("Index"));
            }
            string    url      = ConfigurationManager.AppSettings["HelpOnlineHTMLPath"].ToString() + helpLevel3.URL;
            WebClient client   = new WebClient();
            String    htmlCode = client.DownloadString(Server.MapPath(url));

            using (MemoryStream stream = new System.IO.MemoryStream())
            {
                StringReader sr         = new StringReader(htmlCode);
                Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
                HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);
                PdfWriter    writer     = PdfWriter.GetInstance(pdfDoc, stream);
                pdfDoc.Open();
                htmlparser.Parse(sr);
                pdfDoc.Close();
                byte[] bytes = stream.ToArray();
                Response.ContentType = "application/pdf";
                // Adds an HTTP header to the output stream
                Response.AddHeader("Content-Disposition", "attachment; filename=Download.pdf");
                //Gets or sets a value indicating whether to buffer output and send it after
                // the complete response is finished processing.
                Response.Buffer = true;
                // Sets the Cache-Control header to one of the values of System.Web.HttpCacheability.
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                // Writes a string of binary characters to the HTTP output stream. it write the generated bytes .
                Response.BinaryWrite(bytes);
                // Sends all currently buffered output to the client, stops execution of the
                // page, and raises the System.Web.HttpApplication.EndRequest event.

                Response.End();
                // Closes the socket connection to a client. it is a necessary step as you must close the response after doing work.its best approach.
                Response.Close();
            }

            return(RedirectToAction("Index"));
        }
예제 #6
0
        // GET: HelpOnline/AdminLevel3/Edit/5
        public ActionResult Edit(int id)
        {
            if (id == 0)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HelpLevel3 helpLevel3 = helpLevel3DB.GetHelpLevel3ById(id);

            if (helpLevel3 == null)
            {
                return(HttpNotFound());
            }
            HelpLevel2 helpLevel2 = helpLevel2DB.GetHelpLevel2ById(helpLevel3.ParentId);

            if (helpLevel2 == null)
            {
                return(HttpNotFound());
            }
            helpLevel3.ParentTopic = helpLevel2;
            return(View(helpLevel3));
        }
예제 #7
0
        public ActionResult PrintContent(int id)
        {
            HelpLevel3 helpLevel3 = helpLevel3DB.GetHelpLevel3ById(id);

            if (helpLevel3 == null)
            {
                ViewBag.ErrorMessage = "Can not find this recource";
                return(RedirectToAction("Index"));
            }
            SelectPdf.HtmlToPdf converter = new SelectPdf.HtmlToPdf();
            string    url      = ConfigurationManager.AppSettings["HelpOnlineHTMLPath"].ToString() + helpLevel3.URL;
            WebClient client   = new WebClient();
            String    htmlCode = client.DownloadString(Server.MapPath(url));

            SelectPdf.PdfDocument doc = converter.ConvertHtmlString(htmlCode);
            string fileToSave         = ConfigurationManager.AppSettings["HelpOnlineHTMLPath"].ToString();

            fileToSave += "Download.pdf";
            fileToSave  = Server.MapPath(fileToSave);
            doc.Save(fileToSave);
            doc.Close();
            byte[] FileBytes = System.IO.File.ReadAllBytes(fileToSave);
            return(File(FileBytes, "application/pdf"));
        }