You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
3.3 KiB
104 lines
3.3 KiB
using Microsoft.AspNetCore.Mvc.Razor;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
|
|
namespace Infrastructure.Web.Mvc.Razor
|
|
{
|
|
public abstract class MyRazorPage<TModel> : RazorPage<TModel>
|
|
{
|
|
public string HtmlTitle
|
|
{
|
|
get { return this.ViewData["HtmlTitle"] as string; }
|
|
set { this.ViewData["HtmlTitle"] = value; }
|
|
}
|
|
|
|
public string HtmlAction
|
|
{
|
|
get { return this.ViewData["HtmlAction"] as string; }
|
|
set { this.ViewData["HtmlAction"] = value; }
|
|
}
|
|
|
|
public bool HideBread
|
|
{
|
|
get { return (bool)(this.ViewData["HideBread"] ?? false); }
|
|
set { this.ViewData["HideBread"] = value; }
|
|
}
|
|
|
|
public bool HidePaged
|
|
{
|
|
get { return (bool)(this.ViewData["HideBread"] ?? false); }
|
|
set { this.ViewData["HideBread"] = value; }
|
|
}
|
|
|
|
public bool DisableBackUrl
|
|
{
|
|
get { return (bool)(this.ViewData["DisableBackUrl"] ?? false); }
|
|
set { this.ViewData["DisableBackUrl"] = value; }
|
|
}
|
|
|
|
public string BackUrl
|
|
{
|
|
get { return this.ViewData["BackUrl"] as string; }
|
|
set { this.ViewData["BackUrl"] = value; }
|
|
}
|
|
|
|
public bool HasPermission(params string[] permissions)
|
|
{
|
|
var result = false;
|
|
foreach (var role in permissions)
|
|
{
|
|
result = result || User.IsInRole(role);
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public string GetLinkClass(string controller = null, string action = null, string area = null)
|
|
{
|
|
var currentArea = ViewContext.RouteData.Values["area"]?.ToString() ?? "";
|
|
var currentController = ViewContext.RouteData.Values["controller"]?.ToString();
|
|
var currentAction = ViewContext.RouteData.Values["action"]?.ToString();
|
|
var cls = "nav-link";
|
|
var match = true;
|
|
if (area != null)
|
|
{
|
|
match = match && area == currentArea;
|
|
}
|
|
if (controller != null)
|
|
{
|
|
match = match && controller == currentController;
|
|
}
|
|
if (action != null)
|
|
{
|
|
match = match && action == currentAction;
|
|
}
|
|
if (match)
|
|
{
|
|
cls += " active";
|
|
}
|
|
return cls;
|
|
}
|
|
|
|
public string GetGroupClass(params string[] controllers)
|
|
{
|
|
if (controllers.Select(o => o.ToLower(CultureInfo.InvariantCulture)).Contains(this.ViewContext.RouteData.Values["controller"].ToString().ToLower(CultureInfo.InvariantCulture)))
|
|
{
|
|
return "nav-item has-treeview menu-open";
|
|
}
|
|
return "nav-item has-treeview";
|
|
}
|
|
|
|
public string GetGroupLinkClass(params string[] controllers)
|
|
{
|
|
if (controllers.Select(o => o.ToLower(CultureInfo.InvariantCulture)).Contains(this.ViewContext.RouteData.Values["controller"].ToString().ToLower(CultureInfo.InvariantCulture)))
|
|
{
|
|
return "nav-link active";
|
|
}
|
|
return "nav-link";
|
|
}
|
|
}
|
|
|
|
public abstract class MyRazorPage : MyRazorPage<dynamic>
|
|
{
|
|
}
|
|
}
|