Example #1
0
 public ActionResult Preview(string secretNumber)
 {
     //if (DerImageController.SecretNumber != secretNumber) {
     //    return HttpNotFound();
     //}
     //var activeDer = _derService.GetActiveDer();
     //var id = activeDer.Id;
     //var response = _derService.GetDerLayout(id);
     //var viewModel = response.MapTo<DerDisplayViewModel>();
     var secretPath = System.IO.Path.Combine(Server.MapPath(PathConstant.DerPath), secretNumber + ".txt");
     var viewModel = new GenerateViewModel {
         Content = System.IO.File.ReadAllText(secretPath)
     };
     System.IO.File.Delete(secretPath);
     return View("Preview3",viewModel);
     //return View("~/Views/Der/Preview2.cshtml",viewModel);
 }
Example #2
0
        public ActionResult Generate(GenerateViewModel viewModel)
        {
            var theDate = DateTime.ParseExact(viewModel.Date, "MM/dd/yyyy", CultureInfo.InvariantCulture).AddDays(1);
            var htmlToPdf = new HtmlToPdfConverter();
            htmlToPdf.Size = PageSize.A3;
            if (!Directory.Exists(Server.MapPath(PathConstant.DerPath)))
            {
                Directory.CreateDirectory(Server.MapPath(PathConstant.DerPath));
            }
            int revision = 0;
            var isExisted = _derService.IsDerExisted(theDate, out revision);
            revision = isExisted ? (revision + 1) : revision;
            var title = "DER/" + theDate.ToString("dd-MMM-yyyy");
            var pdfName = string.Format("{0}_{1}.pdf", title.Replace('/', '-'), revision);
            var pdfPath = Path.Combine(Server.MapPath(PathConstant.DerPath), pdfName);
            var secretNumber = Guid.NewGuid().ToString();
            var secretPath = Path.Combine(Server.MapPath(PathConstant.DerPath), secretNumber + ".txt");
            System.IO.File.WriteAllText(secretPath, viewModel.Content);
            var displayUrl = Url.Action("Preview", "DerImage", new { secretNumber = secretNumber }, this.Request.Url.Scheme);
            htmlToPdf.Margins.Top = 20;
            htmlToPdf.Margins.Bottom = 20;
            htmlToPdf.Margins.Left = 20;
            htmlToPdf.Margins.Right = 20;
            htmlToPdf.GeneratePdfFromFile(displayUrl, null, pdfPath);
            var response = _derService.CreateOrUpdate(new CreateOrUpdateDerRequest
            {
                Filename = PathConstant.DerPath + "/" + pdfName,
                Title = title,
                Date = theDate,
                RevisionBy = UserProfile().UserId
            });
            if (response.IsSuccess)
            {
                return RedirectToAction("Index");
            }

            return base.ErrorPage(response.Message);
            //htmlToPdf.GeneratePdfFromFile(displayUrl, null, pdfPath);
            //return File(pdfPath, "application/pdf");
            //var htmlToImageConverter = new HtmlToImageConverter();
            //htmlToImageConverter.Height = 2481;
            //htmlToImageConverter.Width = 1754;
            //return File(htmlToImageConverter.GenerateImageFromFile(displayUrl, ImageFormat.Png), "image/png", "TheGraph.png");
        }