public IEnumerable <User> GetUsersBySeacrhCriterias(UserSearchCriterias searchCriterias) { if (searchCriterias == null) { throw new ArgumentNullException(nameof(searchCriterias)); } if (!searchCriterias.RoleId.HasValue && string.IsNullOrWhiteSpace(searchCriterias.UserName)) { return(GetUsers()); } _context.Roles.Load(); var searchedUsers = _context.Users.Include(r => r.RoleNavigation) as IQueryable <User>; if (searchCriterias.RoleId.HasValue) { searchedUsers = searchedUsers.Where(u => u.Role == searchCriterias.RoleId); } if (!String.IsNullOrEmpty(searchCriterias.UserName)) { searchedUsers = searchedUsers.Where(u => u.UserName == searchCriterias.UserName.Trim()); } return(searchedUsers.ToList <User>()); }
public IEnumerable <UserDTO> GetUsersBySeacrhCriterias(UserSearchCriterias criterias) { var usersFromRepo = _userRepository.GetUsersBySeacrhCriterias(criterias); var lstUser = _mapper.Map <IEnumerable <UserDTO> >(usersFromRepo); return(lstUser); }