Ejemplo n.º 1
0
        /// <summary>
        /// Преглед в pdf
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private async Task <IActionResult> blankPreview(BlankEditVM model)
        {
            int id = 0;

            int.TryParse(model.SourceId, out id);
            var docTemplate = service.GetById <DocumentTemplate>(id);

            byte[] pdfBytes = null;
            if (docTemplate.HtmlTemplateId > 0)
            {
                string html = await cdnService.LoadHtmlFileTemplate(new CdnFileSelect()
                {
                    SourceType = model.SourceType, SourceId = model.SourceId
                });

                pdfBytes = await new ViewAsPdfByteWriter("CreatePdf", new BlankEditVM()
                {
                    HtmlContent = html
                }, true, GetFooterInfoUrl(userContext.CourtId)).GetByte(this.ControllerContext);
            }
            else
            {
                var headerModel = service.DocumentTemplate_InitHeader(id);

                pdfBytes = await GetFileBytes(headerModel, model.SourceType, model.SourceId);
            }

            return(File(pdfBytes, NomenclatureConstants.ContentTypes.Pdf, "documentTemplatePreview.pdf"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Blank(BlankEditVM model, string btnPreview = null)
        {
            //return new ViewAsPdf("CreatePdf", model);
            var htmlRequest = new CdnUploadRequest()
            {
                SourceType        = model.SourceType,
                SourceId          = model.SourceId,
                FileName          = "draft.html",
                ContentType       = "text/html",
                FileContentBase64 = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(model.HtmlContent ?? ""))
            };

            if (await cdnService.MongoCdn_AppendUpdate(htmlRequest))
            {
                SetSuccessMessage(MessageConstant.Values.SaveOK);
            }
            else
            {
                SetErrorMessage(MessageConstant.Values.SaveFailed);
            }

            if (!string.IsNullOrEmpty(btnPreview))
            {
                return(await blankPreview(model));
            }

            return(RedirectToAction(nameof(Blank), new { id = model.SourceId }));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Blank(long id)
        {
            var actModel = drService.Select(0, id).FirstOrDefault();

            int    sourceType = SourceTypeSelectVM.DocumentResolutionBlank;
            string html       = await cdnService.LoadHtmlFileTemplate(new CdnFileSelect()
            {
                SourceType = sourceType, SourceId = id.ToString()
            });


            var model = new BlankEditVM()
            {
                Title            = "Изготвяне на разпореждане",
                SourceType       = sourceType,
                SourceId         = id.ToString(),
                HtmlHeader       = await this.RenderViewAsync("ActHeader", actModel),
                HtmlContent      = html,
                FooterIsEditable = false,
                ReturnUrl        = Url.Action(nameof(Edit), new { id }),
                HasPreviewButton = true
            };

            ViewBag.breadcrumbs = commonService.Breadcrumbs_DocumentResolution(id);
            SetHelpFile(HelpFileValues.DispositionTask);

            return(View("BlankEdit", model));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Зареждане на данни за запис на файл по документ
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <IActionResult> Blank(int id, bool del = false)
        {
            var         docTemplate = service.GetById <DocumentTemplate>(id);
            BlankEditVM blankModel  = null;

            if (docTemplate.HtmlTemplateId > 0)
            {
                blankModel = await InitBlankFromTemplate(id, del);
            }
            else
            {
                //var actModel = service.CaseSessionAct_GetForBlankPrepare(id);
                int    sourceType = SourceTypeSelectVM.DocumentTemplate;
                string html       = await cdnService.LoadHtmlFileTemplate(new CdnFileSelect()
                {
                    SourceType = sourceType, SourceId = id.ToString()
                });

                if (string.IsNullOrEmpty(html))
                {
                    var tmplt = service.GetById <DocumentTemplate>(id);
                    html = tmplt.Description;
                }
                var headerModel    = service.DocumentTemplate_InitHeader(id);
                var headerTemplate = "Header";
                var headerHTML     = string.Empty;
                if (!string.IsNullOrEmpty(headerModel.HeaderTemplateName))
                {
                    headerTemplate = headerModel.HeaderTemplateName;
                }
                headerHTML = await this.RenderViewAsync(headerTemplate, headerModel);

                var footerHTML = await this.RenderViewAsync("Footer", headerModel);

                blankModel = new BlankEditVM()
                {
                    Title            = "Изготвяне на документ към " + SourceTypeSelectVM.GetSourceTypeName(sourceType).ToLower(),
                    SourceType       = sourceType,
                    SourceId         = id.ToString(),
                    HtmlHeader       = headerHTML,
                    HtmlContent      = html,
                    HtmlFooter       = footerHTML,
                    FooterIsEditable = false,
                    ReturnUrl        = Url.Action(nameof(Edit), new { id }),
                    HasPreviewButton = true,
                };
            }
            ViewBag.breadcrumbs = commonService.Breadcrumbs_GetForDocumentTemplate(docTemplate.SourceType, docTemplate.SourceId);
            return(View("BlankEdit", blankModel));
        }
Ejemplo n.º 5
0
        private async Task <IActionResult> blankPreview(BlankEditVM model)
        {
            long resolutionId = long.Parse(model.SourceId);
            var  actModel     = drService.Select(0, resolutionId).FirstOrDefault();

            string html = await GetActHTML(actModel);

            byte[] pdfBytes = await new ViewAsPdfByteWriter("CreatePdf", new BlankEditVM()
            {
                HtmlContent = html
            }, true).GetByte(this.ControllerContext);

            return(File(pdfBytes, NomenclatureConstants.ContentTypes.Pdf, "documentResolution.pdf"));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Blank(BlankEditVM model, string btnPreview = null, string reset_mode = null)
        {
            int id = int.Parse(model.SourceId);

            if (!string.IsNullOrEmpty(reset_mode))
            {
                await cdnService.MongoCdn_DeleteFiles(new CdnFileSelect()
                {
                    SourceType = model.SourceType, SourceId = model.SourceId
                });

                SetSuccessMessage("Информацията е обновена с данните от бланката.");
                this.SaveLogOperation(this.ControllerName, nameof(Edit), "Обновяване на данните от бланката", IO.LogOperation.Models.OperationTypes.Patch, id);
                return(RedirectToAction(nameof(Blank), new { id = model.SourceId }));
            }

            //return new ViewAsPdf("CreatePdf", model);
            var htmlRequest = new CdnUploadRequest()
            {
                SourceType        = model.SourceType,
                SourceId          = model.SourceId,
                FileName          = "draft.html",
                ContentType       = "text/html",
                FileContentBase64 = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(model.HtmlContent ?? ""))
            };

            if (await cdnService.MongoCdn_AppendUpdate(htmlRequest))
            {
                SetSuccessMessage(MessageConstant.Values.SaveOK);
                this.SaveLogOperation(this.ControllerName, nameof(Edit), "Изготвяне на документ", IO.LogOperation.Models.OperationTypes.Update, id);
                if (!string.IsNullOrEmpty(btnPreview))
                {
                    return(await blankPreview(model));
                }
                return(RedirectToAction(nameof(Edit), new { id = model.SourceId }));
            }
            else
            {
                SetErrorMessage(MessageConstant.Values.SaveFailed);
            }



            return(RedirectToAction(nameof(Blank), new { id = model.SourceId }));
        }
Ejemplo n.º 7
0
        private async Task <BlankEditVM> InitBlankFromTemplate(int id, bool del)
        {
            var docTemplate = service.GetById <DocumentTemplate>(id);
            int sourceType  = SourceTypeSelectVM.DocumentTemplate;

            if (del)
            {
                var deleted = await cdnService.MongoCdn_DeleteFiles(new CdnFileSelect()
                {
                    SourceType = sourceType, SourceId = id.ToString()
                });
            }
            string html = await cdnService.LoadHtmlFileTemplate(new CdnFileSelect()
            {
                SourceType = sourceType, SourceId = id.ToString()
            });

            if (string.IsNullOrEmpty(html))
            {
                TinyMCEVM htmlModel = printService.FillHtmlTemplateDocumentTemplate(id);
                html = htmlModel.Text;
            }

            var model = new BlankEditVM()
            {
                Title            = "Изготвяне на документ към " + SourceTypeSelectVM.GetSourceTypeName(sourceType).ToLower(),
                SourceType       = sourceType,
                SourceId         = id.ToString(),
                HtmlHeader       = string.Empty,
                HtmlContent      = html,
                HtmlFooter       = string.Empty,
                FooterIsEditable = false,
                ReturnUrl        = Url.Action(nameof(Edit), new { id }),
                HasPreviewButton = true,
                HasResetButton   = true,
            };

            if (docTemplate.HtmlTemplateId > 0)
            {
                var htmlTemplate = service.GetById <HtmlTemplate>(docTemplate.HtmlTemplateId);
                var htmlModel    = printService.ConvertToTinyMCVM(htmlTemplate, false);
                model.TemplateStyle = htmlModel.Style;
            }
            return(model);
        }