I want to create a dynamic identity for roles that admin can add access to roles. I created it and it works fine but in the view it shows the actual name for each areas, controllers and actions. I want to change these names to another language for displaying but I want to insert the actual names in table. How should I do that? I searched a lot but I couldn't find any solution.
This is the class and method that returns the names of all areas and controllers and actions:
public class MvcUtilities : IMvcUtilities
{
/// <summary>
/// Will add all area and controller and action names into a List of tuple.
/// </summary>
public MvcUtilities(IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
{
var actionDescriptors = actionDescriptorCollectionProvider.ActionDescriptors.Items;
foreach (var actionDescriptor in actionDescriptors)
{
var descriptor = actionDescriptor as ControllerActionDescriptor;
if (descriptor == null) continue;
var controllerTypeInfo = descriptor.ControllerTypeInfo;
//var actionMethodInfo = descriptor.MethodInfo;
ValueTuples.Add((controllerTypeInfo.GetCustomAttribute<AreaAttribute>()?.RouteValue,
descriptor.ControllerName,
descriptor.ActionName));
}
}
public IList<(string areaName, string controllerName, string actionName)> ValueTuples { get; }
= new List<(string areaName, string controllerName, string actionName)>();
public IList<ActionAndControllerName> AreaAndActionAndControllerNamesList()
{
var list = ValueTuples.Distinct().Select(t => new ActionAndControllerName()
{
AreaName = t.areaName,
ControllerName = t.controllerName+"Controller",
ActionName = t.actionName
});
return list.Where(l=>(l.ControllerName!="AccountController")&&(l.ActionName!="Management"))
.OrderByDescending(ar=>ar.AreaName).ThenBy(c=>c.ControllerName).ThenBy(a=>a.ActionName).ToList();
}