/// <summary>
        /// Genera un pdf a partir de una vista y un modelo
        /// </summary>
        /// <param name="view">ruta de la vista (por ejemplo ~/Views/Home/Index.cshtml)</param>
        /// <param name="model">Modelo</param>
        /// <returns></returns>
        public byte[] GetDocument(string view, object model)
        {
            var htmlString = RenderViewHelper.Render(this.Configuration, view, model);
            var document   = DocumentHelper.GetDocumentFromHtml(this.Configuration, htmlString);

            return(document);
        }
Ejemplo n.º 2
0
        public ActionResult AutoLoad(int p_lastIndex, int p_itemStatus)
        {
            decimal p_begin = SessionData.TotalRecord + 1;
            decimal p_end   = CommonSystem.defaultEnd * p_lastIndex;
            var     _lst    = new List <ItemInfo>();

            try
            {
                _lst = ItemBL.ItemLoad(p_itemStatus, p_begin, p_end);
                if (_lst.Count() == 0)
                {
                    p_lastIndex = 0;
                }
                SessionData.TotalRecord = p_end;
            }
            catch (Exception ex)
            {
            }
            return(Json(new
            {
                success = -2,
                _lastpage = p_lastIndex,
                _html = RenderViewHelper.RenderRazorViewToString("~/Views/Home/_ItemList.cshtml", _lst, this.ViewData, this.ControllerContext, this.TempData)
            }));
        }
Ejemplo n.º 3
0
        private Object ToJson(AdminUser model, DataTableParams dtParams)
        {
            var json = model.AsJson() as Hashtable;

            json.Add("Actions", RenderViewHelper.RenderToString("_Actions", model, dtParams.Controller));

            return(json);
        }
Ejemplo n.º 4
0
        public virtual ActionResult Index()
        {
            if (Session["cartId"] == null)
            {
                return(RedirectToAction(MVC.Store.Cart.Index()));
            }
            var cart = _CartService.GetCart((int)Session["cartId"]);

            // Cart empty?
            if (cart.LineItems.Count() == 0)
            {
                return(RedirectToAction(MVC.Store.Cart.Index()));
            }


            var vm = Mapper.Map <CheckoutIndex>(cart);

            vm.Countries = Mapper.Map <CheckoutIndex.Country[]>(db.Countries);

            var checkoutHtml = RenderViewHelper.RenderViewToString(ControllerContext, "Index", vm);

            IThemeItem layoutItem;
            var        theme = _ThemeService.GetTheme(ViewBag.ThemeName);

            if (ViewBag.Unpublished != null)
            {
                layoutItem = theme.GetUnpublishedItem("layout.checkout.liquid", "layouts")
                             ?? theme.GetUnpublishedItem("layout.liquid", "layouts");
            }
            else
            {
                layoutItem = theme.GetItem("layout.checkout.liquid", "layouts")
                             ?? theme.GetItem("layout.liquid", "layouts");
            }

            Template.FileSystem = new LiquidFileSystem(theme, ViewBag.Unpublished ?? false);

            Template.RegisterFilter(typeof(ScriptTagFilter));
            Template.RegisterFilter(typeof(StylesheetTagFilter));
            Template.RegisterFilter(typeof(ImageUrlFilter));

            // Template lesen. TODO: Cache.
            var layout = Template.Parse(layoutItem.ReadContent());

            return(RenderTemplate(layout, checkoutHtml));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 导出文件
        /// </summary>
        /// <returns></returns>
        public FileResult Export(int id, string type = "txt")
        {
            BaseDBContext db   = new BaseDBContext();
            var           exam = db.Exam.Find(id);


            switch (type)
            {
            case "doc":
                return(File(Encoding.Default.GetBytes(ExprotTxt(exam)), "application/msword", exam.Name + ".doc"));

            case "html":

                var s = RenderViewHelper.ToString(this, RenderViewHelper.FromFilePath + "试卷html导出模板.cshtml", exam);
                return(File(System.Text.Encoding.Default.GetBytes(s), "text/html", exam.Name + ".html"));

            case "htmldoc":

                var ss = RenderViewHelper.ToString(this, RenderViewHelper.FromFilePath + "试卷htmldoc导出模板.cshtml", exam);
                return(File(System.Text.Encoding.Default.GetBytes(ss), "application/msword", exam.Name + ".doc"));

            case "word":
                ComponentInfo.SetLicense("FREE-LIMITED-KEY");
                var s1 = RenderViewHelper.ToString(this, RenderViewHelper.FromFilePath + "试卷html导出模板.cshtml", exam);
                var t1 = new System.IO.MemoryStream();
                var hd = LoadOptions.HtmlDefault;
                hd.Encoding = Encoding.UTF8;
                var doc = SaveOptions.DocxDefault;

                DocumentModel.Load(new System.IO.MemoryStream(Encoding.UTF8.GetBytes(s1)), hd).Save(Server.MapPath("/Content/temp.docx"), doc);
                return(File(t1, "application/msword", exam.Name + ".doc"));

            default:
                return(File(Encoding.Default.GetBytes(ExprotTxt(exam)), "text/plain"));
            }
        }