public static bool StartContainer(this IHtmlHelper helper, string tag, string identifier, object attrs = null, string tabVariable = null) { var access = proc.Process(helper, identifier.ToLower(), "Container"); if (access.Read) { dynamic other = new ExpandoObject(); string stringified = attrs == null ? "" : RazorUtils.ToAttributeString(attrs); if (attrs == null || !attrs.HasProperty("id")) { other.id = identifier; } if (tabVariable != null) { other.calc__show_if = $"{tabVariable}=='{identifier}'"; other.@class = "tab-page"; } if (other != null) { stringified += RazorUtils.ToAttributeStringDynamic(other); } stringified += " #" + identifier; helper.ViewContext.Writer.Write(string.Format("<{0} {1}>\n", tag, stringified)); } return(access.Read); }
public static IHtmlContent ChartBlock( this IHtmlHelper helper, ChartTypes type, string item, int size = 4, string loadedField = "true", object attrs = null, object componentAttrs = null, string classes = null) { var acc = proc.Process(helper, "chart_block_" + item, "DashboardItem__" + type.ToString()); if (!acc.Read) { return(null); } else { var model = new DashboardBlockModel { Attributes = attrs != null?RazorUtils.ToAttributeString(attrs) : null, ComponentAttrs = componentAttrs != null?RazorUtils.ToAttributeString(componentAttrs) : null, Selector = GetTypeSelector(type), Size = size, SingleItem = true, DataField = item, IsLoadedField = loadedField }; return(helper.GetComponent("Components/DashboardBlock", model)); } }
public async Task SendSubscriberEmailAsync(string name, string fromEmail, string message) { Dictionary <string, string> templateData = new Dictionary <string, string> { { "name", name.GetFirstName() } }; var template = RazorUtils.RenderViewToString(memoryCache, "ThanksMessage", templateData, $"Hi {name.GetFirstName()}, I've received your message. As soon as possible, I will answer you."); try { await emailService.SendEmailAsync(fromEmail, "I've received your message", template); } catch (System.Exception e) { throw e; } }
public CellWriter SelectCell <T, TValue>( IHtmlHelper <T> helper, Expression <Func <T, TValue> > exp, Lister source, string displayMember, string valueMember, bool required, bool multi, bool nullable, object cellAttributes, object inputAttr, string classes, string readOnlyProp, string rowIndex) { var writer = base.SelectCell(helper, exp, source, displayMember, valueMember, required, multi, cellAttributes, inputAttr, classes, nullable, rowIndex); writer.ColumnModel.Attributes = RazorUtils.ToAttributeString(cellAttributes); ((SelectNgInput)writer.InputModel).Nullable = nullable; writer.Accessibility = proc.ProcessCell(helper, exp, InputControls.Select); writer.Initialize(null, null, cellAttributes, inputAttr, classes); helper.AddSource(source); if (!writer.Accessibility.Write) { if (readOnlyProp != null) { writer.InputModel.MemberName = readOnlyProp; } } writer.InputModel.RowIndex = rowIndex; return(writer); }
/// <summary> /// Return the HTML for the tab contents. /// </summary> /// <returns></returns> public override string GetHtml() { string msg; string retval; var model = new DbReplaceModel(); model.Context = Context; model.Help = Localization.GetString("Help.Html", "~\\DesktopModules\\40Fingers\\DnnMassManipulate\\ManipulatorModules\\DbReplace\\App_LocalResources\\DbReplace.resx"); foreach (ConnectionStringSettings cs in ConfigurationManager.ConnectionStrings) { model.ConnectionStrings.Add(new KeyValuePair <string, string>(cs.Name, cs.ConnectionString)); } if (RazorUtils.Render(model, "DbReplace.cshtml", ScriptsPath, null, out retval, out msg)) { return(retval); } else if (UserController.Instance.GetCurrentUserInfo().IsSuperUser) { return(msg); } else { return("Something went wrong"); } }
public async Task SendContactFromSite(string name, string fromEmail, string message, string ownerEmail) { Dictionary <string, string> templateData = new Dictionary <string, string> { { "name", name.GetFirstName() }, { "email", fromEmail }, { "message", message } }; var template = RazorUtils.RenderViewToString(memoryCache, "ContactViaSite", templateData, $"{name} contact you via Austin's site. Their email {fromEmail}. Their message {message}"); try { await emailService.SendEmailAsync(ownerEmail, "Contact via Austin's Site", template); } catch (System.Exception e) { throw e; } }
public async Task RenderAsync_Test() { // Arrange var template = @" @{ string AddHello(string Name) { return $""Hello, {Name}""; } var model = @Model as Tests.Web.TestModel; } <p>@AddHello(model.Name)</p>@foreach(var item in model.Items){<h1>@item.Name</h1>} "; var model = new TestModel { Name = "ETSOO", Items = new List <TestModelItem> { new TestModelItem("Item 1"), new TestModelItem("Item 2") } }; // Act var result = (await RazorUtils.RenderAsync("test", template, model)).Trim(); // Assert Assert.IsTrue(result.Equals("<p>Hello, ETSOO</p><h1>Item 1</h1><h1>Item 2</h1>"), result); }
public virtual string GetLink <T, TValue>(IHtmlHelper <T> helper, string id, Expression <Func <T, TValue> > idProperty, string def) { string prop = RazorUtils.GetMemberName(idProperty); var link = new PageLink(id, def, null, prop); return(GetLink(helper, link)); }
public string SaveSinglePageData(HttpContext context) { try { //get uploaded params var ajaxInfo = RazorUtils.GetAjaxFields(context); var itemid = ajaxInfo.GetXmlProperty("genxml/hidden/itemid"); if (Utils.IsNumeric(itemid)) { var editlang = ajaxInfo.GetXmlProperty("genxml/hidden/editlang"); var nbi = Get(Convert.ToInt32(itemid)); if (nbi != null) { // get data passed back by ajax var strIn = HttpUtility.UrlDecode(Utils.RequestParam(context, "inputxml")); // update record with ajax data nbi.UpdateAjax(strIn); Update(nbi); // do langauge record var nbi2 = GetDataLang(Convert.ToInt32(itemid), editlang); nbi2.UpdateAjax(strIn); Update(nbi2); } DataCache.ClearCache(); // clear ALL cache. } return(""); } catch (Exception e) { return(e.ToString()); } }
public void AddToButtons(IHtmlContent content = null, string function = null, string url = null, BtnClass btn = BtnClass.Default, string icon = null, string identifier = null, string classes = null, string title = null, object attr = null) { if (url != null) { url = RazorUtils.ApplyConvension(url, AppParts.Route); } Buttons.Add(LinkModel.Make(content, function, url, btn, icon, identifier, classes, title, attr)); }
public virtual void Initialize(string placeHolder = null, string width = null, object attrs = null, object inputAttr = null, string classes = "") { ColumnModel.Attributes = RazorUtils.ToAttributeString(attrs); ColumnModel.Width = width == null ? "" : $"style='width:{width}'"; InputModel.PlaceHolder = placeHolder ?? TextProvider.Column(ColumnId); InputModel.Classes = classes; InputModel.AttributeObject = inputAttr; }
public static NgControlGroup FromExpression <T, TValue>(Expression <Func <T, TValue> > exp) { string columnId = RazorUtils.GetColumnId(exp); return(new NgControlGroup { Label = RazorConfig.LocaleTextProvider.Column(columnId) }); }
public CellWriter AutoCompleteSelectCell <T, TValue>(IHtmlHelper <T> helper, Expression <Func <T, TValue> > exp, Lister source, string displayMember, string valueMember, bool required, bool multi, bool nullable, object cellAttributes, object inputAttr, string classes) { var writer = base.SelectCell(helper, exp, source, displayMember, valueMember, required, multi, cellAttributes, inputAttr, classes, false, null); writer.ColumnModel.Attributes = RazorUtils.ToAttributeString(cellAttributes); ((SelectNgInput)writer.InputModel).Nullable = nullable; writer.Accessibility = proc.ProcessCell(helper, exp, InputControls.Select); writer.Initialize(null, null, cellAttributes, inputAttr, classes); return(writer); }
public virtual void SetOptions(int size, string alternateLabel = null, string placeHolder = null, object attrs = null, object inputAttr = null, string classes = "", string grClasses = "") { GroupModel.Label = alternateLabel ?? GroupModel.Label; GroupModel.Size = size == -1 ? Helper.GetTheme().DefaultControlGroupSize : size; GroupModel.Attributes = RazorUtils.ToAttributeString(attrs); GroupModel.GroupCssClass = grClasses; InputModel.PlaceHolder = placeHolder ?? GroupModel.Label; InputModel.Classes = classes; InputModel.AttributeObject = inputAttr; }
public IHtmlContent ValueBinding <T, TValue>(IHtmlHelper <T> helper, Expression <Func <T, TValue> > ex, string pipe) { string content = helper.GetModelName() + "." + RazorUtils.GetMemberName(ex); if (pipe == "translate") { content = "'Words.'+" + content; } pipe = pipe == null ? "" : " | " + pipe; return(new HtmlString("{{" + content + pipe + "}}")); }
public virtual IHtmlContent Button(IHtmlHelper helper, string text, string function, string url, BtnClass btn, string icon, string identifier, IHtmlContent content, string classes, string title, object attr) { content = content != null ? content : (text == null ? null : helper.Word(text)); if (url != null) { url = RazorUtils.ApplyConvension(url, AppParts.Route); } LinkModel model = LinkModel.Make(content, function, url, btn, icon, identifier, classes, title, attr); return(helper.GetComponent("Buttons/Button", model)); }
public virtual CellWriter HeaderCell(IHtmlHelper helper, string textId, string size, bool isColumn, object cellAttributes, bool sorting) { using (var writer = new CellWriter(helper)) { writer.ColumnModel.MemberName = textId; writer.ColumnModel.Sorting = sorting; writer.ColumnModel.Attributes = cellAttributes == null ? "" : RazorUtils.ToAttributeString(cellAttributes); writer.InputModel.PlaceHolder = isColumn ? RazorConfig.LocaleTextProvider.Column(textId) : RazorConfig.LocaleTextProvider.Word(textId); return(writer); } }
public static void WriteContainerStart(ViewContext con, string tag, object attr, dynamic otherAttr = null) { if (tag != null) { string attrs = RazorUtils.ToAttributeString(attr); if (otherAttr != null) { attrs += RazorUtils.ToAttributeStringDynamic(otherAttr); } con.Writer.Write(string.Format("<{0} {1}>\n", tag, attrs)); } }
protected override void WriteOpeningTag(object attr) { string attrs = RazorUtils.ToAttributeString(attr); Helper.ViewContext.Writer.Write(string.Format("<{0} #{1}=\"ngForm\" {2}>\n", TagName, FormName, attrs)); if (ModelName != null) { currentNgModel = Helper.GetModelName(); Helper.SetNgModel(ModelName); } currentNgForm = Helper.GetFormName(); Helper.SetNgForm(FormName); }
public static Accessibility GetAccessibility <T, TVal>(this IHtmlHelper <T> helper, Expression <Func <T, TVal> > ex, bool cell = false) { if (helper.CollectingData()) { return(new Accessibility(2)); } var id = RazorUtils.GetColumnId(ex); if (cell) { id = "cell__" + id; } return(helper.Config().GetAccessibility(id.ToLower())); }
static void GetRazorFoldingRegions(RazorCSharpParserContext context, List <FoldingRegion> foldingRegions) { var blocks = new List <Block> (); GetBlocks(context.EditorParser.CurrentParseTree, blocks); foreach (var block in blocks) { var beginLine = context.Document.GetLineByOffset(block.Start.AbsoluteIndex); var endLine = context.Document.GetLineByOffset(block.Start.AbsoluteIndex + block.Length); if (beginLine != endLine) { foldingRegions.Add(new FoldingRegion(RazorUtils.GetShortName(block), new DocumentRegion(context.Document.OffsetToLocation(block.Start.AbsoluteIndex), context.Document.OffsetToLocation(block.Start.AbsoluteIndex + block.Length)))); } } }
private void DisplayProductError(String msg) { //display the error if superuser (don;t want to log it.) var errmsg = ModCtrl.GetTemplateData(ModSettings, "productunavailable.html", Utils.GetCurrentCulture(), DebugMode); if (UserInfo.IsSuperUser) { errmsg += msg; } var obj = new NBrightInfo(true); var razorTemplateKey = "NBrightBuyRazorKey*productunavailable" + PortalId.ToString() + "*" + Utils.GetCurrentCulture(); errmsg = RazorUtils.RazorRender(obj, errmsg, razorTemplateKey, StoreSettings.Current.DebugMode); var l = new Literal(); l.Text = errmsg; phData.Controls.Add(l); //Response.StatusCode = 404; //causes 404 page on live site??? }
protected void Page_Load(object sender, EventArgs e) { JavaScript.RequestRegistration(CommonJs.DnnPlugins); ClientResourceManager.RegisterScript(Page, "desktopmodules/40fingers/DnnMassManipulate/js/40F-Common.js", FileOrder.Js.jQuery); config = new MassManipulateConfig(Settings, ModuleId, TabModuleId); string msg; string retval; if (RazorUtils.Render(GetModel(), "Index.cshtml", ScriptsPath, ModuleContext, out retval, out msg)) { ContentLiteralControl.Text = retval; } else if (UserInfo.IsSuperUser) { ContentLiteralControl.Text = msg; } }
public override void UseExpression <T, TValue>(Expression <Func <T, TValue> > exp) { ColumnId = RazorUtils.GetColumnId(exp); MemberName = RazorUtils.GetMemberName(exp); MemberExpression = RazorUtils.GetMemberExpression(exp); ModelName = Helper.GetModelName(); ColumnModel = new ColumnModel(); ColumnModel.MemberName = RazorUtils.GetMemberNameDefault(exp); InputModel = new NgInput { MemberName = MemberName, NgModelName = Helper.GetModelName(), NgFormName = Helper.GetFormName() }; Helper.AddText(StringType.Column, ColumnId); }
public static void AddBreadCrumbMoldster <T>(this IHtmlHelper <T> helper, string identifier, string idExpression = null, string idProperty = null, string def = null, IHtmlContent title = null) { var Provider = helper.GetService <IMoldsterGeneralHelper>(); var lnk = Provider.GetLink(helper, new PageLink(identifier, def, idExpression, idProperty)); if (lnk != null) { if (title == null) { var pag = helper.GetViewParams().GetFromOther(identifier, def); var pageId = RazorUtils.UrlToPageId(pag); title = helper.Page(pageId); } helper.HeaderModel().BreadCrums.Add(new Models.BreadCrumbModel { Title = title, Link = "{{" + lnk + "}}" }); } }
public CellWriter LinkCell <T, TValue>(IHtmlHelper <T> helper, Expression <Func <T, TValue> > exp, string url, bool blank, object cellAttributes, object linkAttributes, string pipe) { var writer = new CellWriter(helper); writer.UseExpression(exp); writer.Initialize(null, null, cellAttributes, null); if (url != null) { url = RazorUtils.ApplyConvension(url, AppParts.Route); } writer.InputModel = writer.InputModel.GetLabelInput(pipe, url, blank); pipe = pipe == null ? "" : " | " + pipe; if (pipe.Contains("translate")) { writer.InputModel.NgModelName = "'Words.'+" + writer.InputModel.NgModelName; } writer.InputModel.MemberName += pipe; return(writer); }
public override string GetHtml() { string msg; string retval; var model = new CopyPagePermissionsModel(); model.Context = Context; if (RazorUtils.Render(model, "CopyPagePermissions.cshtml", ScriptsPath, null, out retval, out msg)) { return(retval); } else if (UserController.Instance.GetCurrentUserInfo().IsSuperUser) { return(msg); } else { return("Something went wrong"); } }
public override string GetHtml() { string msg; string retval; var model = new GenerateTabsModel(); model.Context = Context; model.Tabs = GetTabs(true, true, true); if (RazorUtils.Render(model, "GenerateTabs.cshtml", ScriptsPath, null, out retval, out msg)) { return(retval); } else if (UserController.Instance.GetCurrentUserInfo().IsSuperUser) { return(msg); } else { return("Something went wrong"); } }
public override ControlGroupWriter SearchableControlGroup <T, TValue>(IHtmlHelper <T> helper, Expression <Func <T, TValue> > exp, Lister source, string display, string valueMember, bool multi, bool required, int size, string alternateLabel, object attrs, object inputAttr, string inputClasses, string groupClasses, string readOnlyProperty, bool nullable) { var mod = base.SearchableControlGroup(helper, exp, source, display, valueMember, multi, required, size, alternateLabel, attrs, inputAttr, inputClasses, groupClasses, readOnlyProperty, nullable); mod.Accessibility = proc.Process(helper, exp, InputControls.CalendarTextBox); if (mod.Accessibility.Read) { source.CollectionIdentifier = helper.GetCollectionName(RazorUtils.GetIdentifier(exp)); helper.AddSource(source); } if (!mod.Accessibility.Write) { if (readOnlyProperty != null) { // mod.InputModel.NgModelName = (readOnlyPipe == "translate" ? "'Words.'+" : "") + mod.InputModel.NgModelName; mod.InputModel.MemberName = readOnlyProperty; } } return(mod); }
public override ControlGroupWriter SelectInputControl <T, TValue>(IHtmlHelper <T> helper, Expression <Func <T, TValue> > exp, Lister lister, string display, string valueMember, bool required, string readOnlyProperty, bool nullable, object attrs, string inputClasses, string readOnlyPipe, string idExtra) { var mod = base.SelectInputControl(helper, exp, lister, display, valueMember, required, readOnlyProperty, nullable, attrs, inputClasses, readOnlyPipe, idExtra); mod.Accessibility = proc.Process(helper, exp, InputControls.Select); if (mod.Accessibility.Read) { lister.CollectionIdentifier = helper.GetCollectionName(RazorUtils.GetIdentifier(exp)); helper.AddSource(lister); } if (!mod.Accessibility.Write) { if (readOnlyProperty != null) { mod.InputModel.NgModelName = (readOnlyPipe == "translate" ? "'Words.'+" : "") + mod.InputModel.NgModelName; mod.InputModel.MemberName = readOnlyProperty + (readOnlyPipe == null ? "" : " | " + readOnlyPipe); } } return(mod); }