Advertisement
Guest User

Untitled

a guest
Mar 31st, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. @{
  2.     var menus = new[]
  3.     {
  4.         new {LinkText = "Home", ActionName = "Index", ControllerName = "Home", Roles = "All" },
  5.         new {LinkText = "About", ActionName = "Index", ControllerName = "Home", Roles = "All" },
  6.         new {LinkText = "Contact", ActionName = "Index", ControllerName = "Home", Roles = "All" },
  7.         new {LinkText = "Manage Workers", ActionName = "Index", ControllerName = "Workers", Roles = "Admin" },
  8.         new {LinkText = "Visits Manager", ActionName = "Index", ControllerName = "Visit", Roles = "Admin,Registrator,Doctor" },
  9.         new {LinkText = "Manage examinations and its prices", ActionName = "Index", ControllerName = "ExaminationDictionary", Roles = "Admin" },
  10.         new {LinkText = "Medical Examinations", ActionName = "Index", ControllerName = "MedicalExaminations", Roles = "Admin,ChiefTechnician,Technician" },
  11.         new {LinkText = "Manage visits", ActionName = "Index", ControllerName = "Visit", Roles = "Admin,Registrant,Doctor" }
  12.  
  13.     };
  14. }
  15.  
  16. @if (HttpContext.Current.User.Identity.IsAuthenticated)
  17. {
  18.     String[] roles = System.Web.Security.Roles.GetRolesForUser();
  19.     var links = from item in menus
  20.                 where item.Roles.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries)
  21.                 .Any(x => roles.Contains(x) || x == "All")
  22.                 select item;
  23.     foreach (var link in links)
  24.     {
  25.         @:
  26.         <li> @Html.ActionLink(link.LinkText, link.ActionName, link.ControllerName)</li>
  27.     }
  28. }
  29. else
  30. {
  31.     var links = from item in menus
  32.                 where item.Roles.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries)
  33.                 .Any(x => new String[] { "All", "Anonymous" }.Contains(x))
  34.                 select item;
  35.     foreach (var link in links)
  36.     {
  37.         @:
  38.         <li> @Html.ActionLink(link.LinkText, link.ActionName, link.ControllerName)</li>
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement