public async Task <ApplicationRoleSearchModel> GetApplicationRoles(ApplicationRoleSearchModel model) { var url = ODataApiUri + "/ApplicationRole?" + GetFilterString(model); var result = await GetOdataResultFromApi(url); var searchResultCount = 0; if (result.Count != null) { int.TryParse(result.Count.ToString(), out searchResultCount); } model.TotalRows = searchResultCount; model.ApplicationRoleSearchResult.Clear(); try { model.ApplicationRoleSearchResult.AddRange(result.Items.Select(item => JsonConvert.DeserializeObject <ApplicationRoleDto>(item.ToString()))); } catch (Exception e) { Console.WriteLine(e); throw; } return(model); }
private RoleDto PopulatePermission(int applicationId, int roleId, List <int> fullaccessIds = null, List <int> readonlyaccessIds = null) { var searchApplicationRole = new ApplicationRoleSearchModel { ApplicationId = applicationId, RoleId = roleId, PageSize = int.MaxValue, SortColumn = "Id" }; searchApplicationRole = _employeeFacadeApiClient.GetApplicationRoles(searchApplicationRole).Result; var menuItemSearch = new MenuItemSearchModel { PageSize = int.MaxValue, SortColumn = "DisplayName", ApplicationId = applicationId }; menuItemSearch = _employeeFacadeApiClient.GetMenuItems(menuItemSearch).Result; var fullaccessPermissions = searchApplicationRole.ApplicationRoleSearchResult.SelectMany(a => a.RolePermissions.Where(x => x.AccessLevel == AccessLevel.Full).Select(r => r.MenuItemId)).ToList(); var readonlyPermissions = searchApplicationRole.ApplicationRoleSearchResult.SelectMany(a => a.RolePermissions.Where(x => x.AccessLevel == AccessLevel.Readonly).Select(r => r.MenuItemId)).ToList(); var menuItemsForAvailableForReadonly = menuItemSearch.MenuItemSearchResult.Where(x => !fullaccessPermissions.Contains(x.Id)).ToList(); if (fullaccessIds != null) { menuItemsForAvailableForReadonly = menuItemsForAvailableForReadonly.Where(x => !fullaccessIds.Contains(x.Id)).ToList(); fullaccessPermissions.AddRange(fullaccessIds); } var menuItemsForAvailableForFullaccess = menuItemSearch.MenuItemSearchResult.Where(x => !readonlyPermissions.Contains(x.Id)).ToList(); if (readonlyaccessIds != null) { menuItemsForAvailableForFullaccess = menuItemsForAvailableForFullaccess.Where(x => !readonlyaccessIds.Contains(x.Id)).ToList(); readonlyPermissions.AddRange(readonlyaccessIds); } var role = _employeeFacadeApiClient.GetRole(roleId).Result; role.ApplicationId = applicationId; role.Id = roleId; role.ReadonlyPermisssionSelectList = SelectedListHelper.GetPermissionSelectList(menuItemsForAvailableForReadonly, readonlyPermissions); role.FullAccessPermisssionSelectList = SelectedListHelper.GetPermissionSelectList(menuItemsForAvailableForFullaccess, fullaccessPermissions); role.LinkedReadonlyRolePermissionsIds = readonlyaccessIds?.Select(x => x.ToString()).ToList(); role.LinkedFullAccessRolePermissionsIds = fullaccessIds?.Select(x => x.ToString()).ToList(); return(role); }
private string GetFilterString(ApplicationRoleSearchModel searchModel) { var filterString = string.Empty; if (searchModel != null) { if (searchModel.ApplicationId > 0) { filterString = ODataFilterConstant.Filter + $"ApplicationId eq {searchModel.ApplicationId}"; } if (searchModel.RoleId > 0) { if (string.IsNullOrWhiteSpace(filterString)) { filterString = ODataFilterConstant.Filter + $"RoleId eq {searchModel.RoleId}"; } else { filterString += $"and RoleId eq {searchModel.RoleId}"; } } if (!string.IsNullOrWhiteSpace(searchModel.FilterText)) { if (string.IsNullOrWhiteSpace(filterString)) { filterString = ODataFilterConstant.Filter + $"contains(Role/RoleName,'{searchModel.FilterText}') eq true"; } else { filterString += $" or contains(Role/RoleName,'{searchModel.FilterText}') eq true"; } filterString += $" or contains(Role/RoleDescription,'{searchModel.FilterText}') eq true"; } filterString += GetFilterStringForAssociatedEntities(new List <string> { "RolePermissions" }); AddPageSizeNumberAndSortingInFilterString(searchModel, ref filterString); } return(filterString); }
public async Task <ApplicationRoleSearchModel> GetApplicationRoles(ApplicationRoleSearchModel model) { return(await _applicationRoleApiClient.GetApplicationRoles(model)); }