public ActionResult IsPageBrowseAuthorized(string id) { AdminPages backEndPages = new AdminPages(); AdminPage backEndPage = backEndPages.GetPageByAction(id); return(Content(backEndPages.IsPermissionGranted(backEndPage.PageId, PermissionCode.Browse).ToString(), "text/plain")); }
public override void OnActionExecuting(ActionExecutingContext filterContext) { string controller = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.ToLower(); string action = filterContext.ActionDescriptor.ActionName; if (BackEndSessions.CurrentUser.IsNull()) { if (!(controller == "admin" && action.ToLower() == "login")) { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { action = "Login", controller = "Admin", ReturnUrl = HttpUtility.UrlEncode(filterContext.HttpContext.Request.Url.AbsoluteUri) })); } } else { AdminPages backEndPages = new AdminPages(); AdminPage backEndPage = backEndPages.GetPageByAction(action); if (backEndPage.IsNotNull()) { if (backEndPages.IsPermissionGranted(backEndPage.PageId, PermissionCode.Browse)) { if (controller == "admin" && action.ToLower() == "login") { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { action = "Index", controller = "Admin" })); } } else { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary( new { action = "ErrorPage", controller = "Admin", errorPage = action, errorMessage = Resources.Strings.PageAccessNotAuthorized } ) ); } } else { filterContext.Result = new RedirectToRouteResult( new RouteValueDictionary( new { action = "ErrorPage", controller = "Admin", errorPage = action, errorMessage = Resources.Strings.Error404 } ) ); } } }
/// <summary> /// Returns an edit button suitable for the GridView. It will be displayed only if the Edit PermissionCode is assigned to the page. /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="htmlHelper"></param> /// <param name="hrefValue"></param> /// <returns></returns> public static MvcHtmlString BootstrapButtonEdit <TModel>(this HtmlHelper <TModel> htmlHelper, string hrefValue) { AdminPages adminPages = new AdminPages(); AdminPage adminPage = adminPages.GetPageByCurrentAction(); if (adminPages.IsPermissionGranted(adminPage.PageId, PermissionCode.Edit)) { return(new MvcHtmlString("<a href=\"" + hrefValue + "\" title=\"" + Resources.Strings.EditItem + "\" ><i class=\"fa fa-pencil\"></i></a>")); } else { return(new MvcHtmlString("")); } }
/// <summary> /// Returns a delete button suitable for the GridView. It will be displayed only if the Delete PermissionCode is assigned to the page. /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="htmlHelper"></param> /// <param name="hrefValue"></param> /// <param name="promptedValue"></param> /// <returns></returns> public static MvcHtmlString BootstrapButtonDelete <TModel>(this HtmlHelper <TModel> htmlHelper, string formActionValue, object idValue, string promptedValue) { AdminPages adminPages = new AdminPages(); AdminPage adminPage = adminPages.GetPageByCurrentAction(); if (adminPages.IsPermissionGranted(adminPage.PageId, PermissionCode.Delete)) { return(new MvcHtmlString("<button type=\"submit\" data-action=\"" + formActionValue + "\" data-id=\"" + idValue + "\" title=\"" + Resources.Strings.DeleteItem + "\" class=\"btn-a action-delete\" data-action-delete-item=\"" + promptedValue + "\"><i class=\"fa fa-trash-o\"></i></button>")); } else { return(new MvcHtmlString("")); } }
/// <summary> /// Returns an add button. It will be displayed only if the Add PermissionCode is assigned to the page. /// </summary> /// <typeparam name="TModel"></typeparam> /// <param name="htmlHelper"></param> /// <param name="hrefValue"></param> /// <returns></returns> public static MvcHtmlString BootstrapButtonAdd <TModel>(this HtmlHelper <TModel> htmlHelper, string hrefValue) { AdminPages adminPages = new AdminPages(); AdminPage adminPage = adminPages.GetPageByCurrentAction(); if (adminPages.IsPermissionGranted(adminPage.PageId, PermissionCode.Add)) { return(new MvcHtmlString("<a href=\"" + hrefValue + "\" class=\"btn btn-success\"><i class=\"fa fa-plus\"></i> " + Resources.Strings.AddNewItem + "</a>")); } else { return(new MvcHtmlString("")); } }
public HelperResult GetExtendedHtml( string tableStyle = "table table-striped table-bordered table-hover footable toggle-square", string headerStyle = "webgrid-header", string footerStyle = "webgrid-footer", string rowStyle = null, string alternatingRowStyle = null, string selectedRowStyle = null, string caption = null, bool displayHeader = true, bool fillEmptyRows = false, string emptyRowCellValue = null, IEnumerable <WebGridColumnHelper> columns = null, IEnumerable <string> exclusions = null, WebGridPagerModes mode = WebGridPagerModes.Numeric | WebGridPagerModes.NextPrevious, string firstText = null, string previousText = null, string nextText = null, string lastText = null, int numericLinksCount = 5, Object htmlAttributes = null, bool displayTotalItems = true, string totalItemsText = "Total items") { HtmlString result; AdminPages adminPages = new AdminPages(); AdminPage adminPage = adminPages.GetPageByCurrentAction(); if (adminPages.IsPermissionGranted(adminPage.PageId, PermissionCode.Read)) { WebGrid webGrid = this; IHtmlString webGridHtml = webGrid.GetHtml(tableStyle, headerStyle, footerStyle, rowStyle, alternatingRowStyle, selectedRowStyle, caption, displayHeader, fillEmptyRows, emptyRowCellValue, columns, exclusions, mode, firstText, previousText, nextText, lastText, numericLinksCount, htmlAttributes); string webGridHtmlString = webGridHtml.ToString(); HtmlDocument htmlDocument = new HtmlDocument(); //TH Attributes htmlDocument.LoadHtml(webGridHtmlString); HtmlNodeCollection htmlNodeCollection = htmlDocument.DocumentNode.SelectSingleNode("//thead/tr").SelectNodes("th"); int i = 0; foreach (WebGridColumnHelper c in columns) { if (c.ThAttributes.IsNotNull()) { HtmlNode htmlNodeTh = HtmlNode.CreateNode(htmlNodeCollection[i].OuterHtml.Insert(3, " " + c.ThAttributes + " ")); htmlNodeCollection[i].ParentNode.ReplaceChild(htmlNodeTh, htmlNodeCollection[i]); } if (c.DataHide.IsNotNull()) { HtmlNode htmlNodeTh = HtmlNode.CreateNode(htmlNodeCollection[i].OuterHtml.Insert(3, " data-hide=\"" + c.DataHide.ToString().ToLower().Split('_').ToCSV(',') + "\" ")); htmlNodeCollection[i].ParentNode.ReplaceChild(htmlNodeTh, htmlNodeCollection[i]); } i++; } webGridHtmlString = htmlDocument.DocumentNode.OuterHtml; //Sort icon if (webGrid.SortColumn.IsNotEmptyOrWhiteSpace()) { htmlDocument.LoadHtml(webGridHtmlString); HtmlNode htmlNodeAnchor = htmlDocument.DocumentNode.SelectSingleNode("//a[contains(@href,'sort=" + webGrid.SortColumn + "')]"); if (htmlNodeAnchor != null) { string imgSortDirection; if (webGrid.SortDirection == SortDirection.Ascending) { imgSortDirection = "imgSortDirectionASC"; } else { imgSortDirection = "imgSortDirectionDESC"; } HtmlNode htmlNodeIcon = HtmlNode.CreateNode("<div class=\"" + imgSortDirection + "\"></div>"); htmlNodeAnchor.ParentNode.AppendChild(htmlNodeIcon); // Fix a bug http://stackoverflow.com/questions/759355/image-tag-not-closing-with-htmlagilitypack if (HtmlNode.ElementsFlags.ContainsKey("img")) { HtmlNode.ElementsFlags["img"] = HtmlElementFlag.Closed; } else { HtmlNode.ElementsFlags.Add("img", HtmlElementFlag.Closed); } webGridHtmlString = htmlDocument.DocumentNode.OuterHtml; } } //Total Row Count htmlDocument.LoadHtml(webGridHtmlString); HtmlNode htmlNodeTFoot = htmlDocument.DocumentNode.SelectSingleNode("//tfoot/tr/td"); if (htmlNodeTFoot != null) { string pager = webGrid.Pager(numericLinksCount: 10, mode: WebGridPagerModes.All).ToString(); if (displayTotalItems) { pager = "<span class=\"pager-total-items-text\">" + totalItemsText + ":</span> <span class=\"pager-total-items-value\">" + webGrid.TotalRowCount.ToString() + "</span><span class=\"pager-pagination\">" + pager + "</span>"; } htmlNodeTFoot.InnerHtml = pager; // Fix a bug http://stackoverflow.com/questions/759355/image-tag-not-closing-with-htmlagilitypack if (HtmlNode.ElementsFlags.ContainsKey("img")) { HtmlNode.ElementsFlags["img"] = HtmlElementFlag.Closed; } else { HtmlNode.ElementsFlags.Add("img", HtmlElementFlag.Closed); } webGridHtmlString = htmlDocument.DocumentNode.OuterHtml; } result = new HtmlString(webGridHtmlString); } else { result = new HtmlString("<span class=\"label label-danger\">" + Resources.Strings.InsufficientPermissions + "</span>"); } return(new HelperResult(writer => { writer.Write(result); })); }