public GetAuthoritiesListResponse GetAuthoritiesList(GetAuthoritiesListRequest request) { GetAuthoritiesListResponse response = new GetAuthoritiesListResponse(); try { using (IUnitOfWork unitOfWork = RepositoryFactory.GetUnitOfWork()) { if (request != null) { IAuthorityRepository authorityRepository = RepositoryFactory.Get(typeof(IAuthorityRepository), unitOfWork) as IAuthorityRepository; List <Authority> authorities = authorityRepository.GetAll().ToList(); unitOfWork.Commit(); if (authorities != null) { foreach (var item in authorities) { ViewModels.AuthorityView node = new ViewModels.AuthorityView() { Id = item.Id, Name = item.Name }; if (response.Authorities == null) { response.Authorities = new List <ViewModels.AuthorityView>(); } response.Authorities.Add(node); } response.IsSucess = true; } else { response.IsSucess = false; response.Message = "No Authority!"; } } else { response.IsSucess = false; response.Message = "No Input!"; } } } catch (Exception ex) { Log.Write(ex.Message); response.IsSucess = false; response.Message = ex.Message; } return(response); }
public GetRolesListResponse GetRolesList(GetRolesListRequest request) { GetRolesListResponse response = new GetRolesListResponse(); try { using (IUnitOfWork unitOfWork = RepositoryFactory.GetUnitOfWork()) { if (request != null) { IRoleRepository roleRepository = RepositoryFactory.Get(typeof(IRoleRepository), unitOfWork) as IRoleRepository; IAuthorizeRepository authorizeRepository = RepositoryFactory.Get(typeof(IAuthorizeRepository), unitOfWork) as IAuthorizeRepository; IAuthorityRepository authorityRepositroy = RepositoryFactory.Get(typeof(IAuthorityRepository), unitOfWork) as IAuthorityRepository; List <Authorize> authorizes = authorizeRepository.GetAll().ToList(); List <Authority> authorities = authorityRepositroy.GetAll().ToList(); List <Role> roles = roleRepository.GetAll().ToList(); unitOfWork.Commit(); if (authorities != null && authorizes != null && roles != null) { response.Roles = new List <ViewModels.RoleView>(); foreach (var item in roles) { ViewModels.RoleView node = new ViewModels.RoleView(); node.Id = item.Id; node.Name = item.Name; List <Authorize> selectedAuthorizes = authorizes.Where(it => it.RoleName.Contains(item.Id)).ToList(); if (selectedAuthorizes != null) { foreach (var seletecd in selectedAuthorizes) { var selectedAuthority = authorities.Where(it => it.Id == seletecd.AuthorityName).FirstOrDefault(); if (selectedAuthority != null) { if (node.Authorities == null) { node.Authorities = new List <ViewModels.AuthorityView>(); } node.Authorities.Add(new ViewModels.AuthorityView() { Id = selectedAuthority.Id, Name = selectedAuthority.Name }); } } } response.Roles.Add(node); } response.IsSucess = true; } else { response.IsSucess = false; response.Message = "no Authority.Authorize.Role in GetRoleList of UserService!"; } } else { response.IsSucess = false; response.Message = "No Input!"; } } } catch (Exception ex) { Log.Write(ex.Message); response.IsSucess = false; response.Message = ex.Message; } return(response); }