public INavigationBuilder Add(String name, Permission permission, Action<NavigationItemBuilder<NavigationItem>> itemBuilder, Int32 position = 0) { if (_menuCache.All(m => m.Name != name)) { var item = new NavigationItem { Name = name, Permission = permission, Position = position }; var childBuilder = new NavigationItemBuilder<NavigationItem>(item); itemBuilder(childBuilder); _menuCache.Add(item); } return this; }
public bool TryCheckAccess(Permission permission, IUser user) { if (user != null) { IEnumerable<string> permissions; if (!_accountPermissionContexts.TryGetValue(user.Id, out permissions)) { var roleIds = _userRoleRepository.All.Where(m => m.Account_Id == user.Id).Select(it => it.Role_Id).Distinct().ToArray(); permissions = _rolePermissionRepository.All.Where(m => roleIds.Contains(m.Role_Id)).Select(m => m.Permission).ToArray(); _accountPermissionContexts.TryAdd(user.Id, permissions); } return permissions.Any(m => m.Equals(permission.Name)); } return false; }
public bool Authorize(Permission permission) { var user = _authenticationService.GetAuthenticatedUser(); if (_authorizationService.TryCheckAccess(permission, user)) return true; return false; }
public INavigationBuilder Add(String name, Permission permission, Action<NavigationItemBuilder<NavigationItem>> itemBuilder, Int32 position = 0) { return this; }