public async Task <ActionResult> Search() { try { var firstName = Request.Query["firstName"]; var lastName = Request.Query["lastName"]; var email = Request.Query["email"]; var username = Request.Query["username"]; DateTime dateOfBirth; if (!DateTime.TryParse(Request.Query["dateOfBirth"], out dateOfBirth)) { return(BadRequest($"{Request.Query["dateOfBirth"]} is an invalid value for 'dateOfBirth'")); } var query = new UserSearchQuery { Query = new { FirstName = firstName, LastName = lastName, Email = email, Username = username, DateOfBirth = dateOfBirth, }, }; var users = await _queryHandler.HandleAsync(query); return(Ok(users)); } catch (Exception) { return(BadRequest()); } }
protected override HandlerResult GetResult(IHostServer server, WebContext context, string callbackEndPoint, CancellationToken cancel) { if ( !Roles.IsInRole(context.User.Identity, $"{SecurityConst.ROLE_SECURITY_ADMIN},{SecurityConst.ROLE_DOMAIN_ADMIN}")) { throw new SecurityException("only admins allowed to call this"); } var j = RequestParameters.Create(context).AsJson(); var uq = new UserSearchQuery(); uq.LoadFromJson(j); //check if not total admin if (!Roles.IsInRole(context.User.Identity, $"{SecurityConst.ROLE_SECURITY_ADMIN}")) { var domain = ((Identity)context.User.Identity).User.Domain; if (string.IsNullOrWhiteSpace(domain)) { throw new SecurityException("invalid domain for user " + domain); } if (!string.IsNullOrWhiteSpace(uq.Domain) && uq.Domain != domain) { throw new SecurityException("try access not self domain " + domain + " (" + uq.Domain + ")"); } uq.Domain = domain; } var users = Users.SearchUsers(uq).ToArray(); return(new HandlerResult { Result = new { items = users } }); }
public async Task <UserSearchResponse> UserSearch(UserSearchRequest request, SystemSession session) { var serviceRequest = new UserSearchQuery { Query = request.Query, Cursor = request.Cursor, Limit = request.Limit }; var response = await Task.Factory.StartNew(() => Client.SearchService.userSearch(serviceRequest, session.GetSession())).ConfigureAwait(false); var result = new UserSearchResponse { Cursor = response.Cursor, Limit = response.Limit, Count = response.Count, User = response.Users != null?response.Users.Select(x => new UserInformationBaseExtendedResponse { FirstName = x.UserInfoPerson.FirstName, LastName = x.UserInfoPerson.LastName, Image = x.UserInfo.Picture, Title = x.UserInfo.Title, UserId = Convert.ToInt32(x.UserInfoPerson.UserId), UserName = x.UserName, UserTypeId = (SystemUserType)x.UserInfo.UserTypeId }) : null }; return(result); }
public Task <List <UserListResponse> > SearchUsers(string name, CancellationToken cancellationToken) { var query = new UserSearchQuery { Name = name }; return(mediator.Send(query, cancellationToken)); }
public void UserController_Index_ShouldCallUserServiceGetUsersPaged() { var userSearchQuery = new UserSearchQuery(); _userController.Index(userSearchQuery); A.CallTo(() => _userSearchService.GetUsersPaged(userSearchQuery)).MustHaveHappened(); }
public void UserController_Index_ShouldReturnThePassedQueryAsTheModel() { var userSearchQuery = new UserSearchQuery(); ActionResult actionResult = _userController.Index(userSearchQuery); actionResult.As <ViewResult>().Model.Should().BeSameAs(userSearchQuery); }
public async Task <IEnumerable <UserDetail> > HandleAsync(UserSearchQuery query) { var users = await _repository.Search(query.Query) as List <User>; return(users.Select(user => { return _mapper.Map <UserDetail>(user); })); }
public async Task <UserSearchCollection> List([FromQuery] UserSearchQuery query) { var users = await userSearchService.List(query); var results = users.Results.Select(i => mapper.MapValue(i, new UserSearch())); return(new UserSearchCollection(query, users.Total, results)); }
public void UserController_Index_ShouldReturnTheResultOfServiceCallAsViewData() { var users = new StaticPagedList <User>(new List <User>(), 1, 1, 0); var userSearchQuery = new UserSearchQuery(); A.CallTo(() => _userSearchService.GetUsersPaged(userSearchQuery)).Returns(users); ActionResult actionResult = _userController.Index(userSearchQuery); _userController.ViewData["users"].Should().Be(users); }
public QueryResult <UserModel> Where(UserSearchQuery searchQuery) { var result = new QueryResult <UserModel>(); var roleRep = _uow.GetRepostirory <Role>(); var clientRoleId = roleRep.Get(x => x.Name == UserRoles.Buyer).Id; if (!searchQuery.RegisterDateTo.HasValue) { searchQuery.RegisterDateTo = DateTime.Now; } bool hasName = !string.IsNullOrWhiteSpace(searchQuery.Name), hasUserName = !string.IsNullOrWhiteSpace(searchQuery.UserName); var users = _userRep.All.Where(u => u.Roles.All(r => r.RoleId != clientRoleId)); result.Total = users.Count(); users = users.Where(u => (!hasName || (u.FirstName + " " + u.LastName + " " + u.Patronymic).ToLower().Contains(searchQuery.Name.ToLower()) || (u.LastName + " " + u.FirstName).ToLower().Contains(searchQuery.Name.ToLower())) && (!hasUserName || u.UserName.ToLower().Contains(searchQuery.UserName.ToLower())) && (!searchQuery.Role.HasValue || u.Roles.Any(r => r.RoleId == searchQuery.Role)) && (!searchQuery.RegisterDateFrom.HasValue && u.RegistredDate <= searchQuery.RegisterDateTo.Value || u.RegistredDate >= searchQuery.RegisterDateFrom.Value && u.RegistredDate <= searchQuery.RegisterDateTo.Value)); var query = from u in users from ur in u.Roles join r in roleRep.All on ur.RoleId equals r.Id select new UserModel { Id = u.Id, FirstName = u.FirstName, LastName = u.LastName, UserName = u.UserName, RegistredDate = u.RegistredDate, Role = r.Description }; result.TotalFiltered = query.Count(); query = query.OrderBy(searchQuery.OrderBy.ToString()). Skip(searchQuery.Paging.Skip). Take(searchQuery.Paging.Length); result.Paging = searchQuery.Paging; result.Data = query.ToList(); return(result); }
public IEnumerable <IUser> SearchUsers(UserSearchQuery query) { var q = string.IsNullOrWhiteSpace(query.Query)? "login:*" : query.Query; if (!string.IsNullOrWhiteSpace(query.Login)) { q += " AND login:"******" AND name:" + query.Name; } if (!query.Groups) { q += " AND NOT isgroup:true"; } if (!query.Users) { q += " AND isgroup:true"; } if (!string.IsNullOrWhiteSpace(query.Domain)) { q += " AND domain:" + query.Domain; } var esquery = new { query = new { query_string = new { query = q } } }; var json = EsClient.ExecuteCommand(GetBaseUrl() + "_search", esquery.stringify()); if (null == json) { yield break; } var j = json.jsonify(); var hits = j.arr("hits.hits"); foreach (var hit in hits) { var src = hit.map("*._source"); var version = hit.resolvenum("_version", "__version"); var user = UserSerializer.CreateFromJson(src); user.Id = hit.resolvestr("_id", "__id"); user.Version = version; _cache[user.Login] = user; yield return(user); } }
public async Task <List <UserRolesInfo> > FindUsers(UserSearchQuery query, int limit = 100) { var role = db.Roles.FirstOrDefault(r => r.Name == query.Role); var users = db.Users.Where(u => !u.IsDeleted); if (!string.IsNullOrEmpty(query.NamePrefix)) { var usersIds = GetUsersByNamePrefix(query.NamePrefix).Select(u => u.Id); users = users.Where(u => usersIds.Contains(u.Id)); } return(await users .FilterByRole(role, userManager) .FilterByUserIds( await courseRoleUsersFilter.GetListOfUsersWithCourseRoleAsync(query.CourseRoleType, query.CourseId, query.IncludeHighCourseRoles).ConfigureAwait(false), await courseRoleUsersFilter.GetListOfUsersByPrivilegeAsync(query.OnlyPrivileged, query.CourseId).ConfigureAwait(false) ) .GetUserRolesInfoAsync(limit, userManager).ConfigureAwait(false)); }
//Search public async Task <JsonResult> Search(UserSearchQuery model) { var result = new UserResults(); try { var response = await userService.GetAllAsync(model); result.Users = response.Users; result.Total = response.Total; } catch (Exception e) { Console.WriteLine(e); throw; } return(Json(result, JsonRequestBehavior.AllowGet)); }
public IPagedList <User> GetUsersPaged(UserSearchQuery searchQuery) { var query = _session.QueryOver <User>(); if (!string.IsNullOrWhiteSpace(searchQuery.Email)) { query = query.Where( user => user.Email.IsInsensitiveLike(searchQuery.Email, MatchMode.Anywhere)); } if (!string.IsNullOrWhiteSpace(searchQuery.FirstName)) { query = query.Where( user => user.FirstName.IsInsensitiveLike(searchQuery.FirstName, MatchMode.Anywhere)); } if (!string.IsNullOrWhiteSpace(searchQuery.LastName)) { query = query.Where( user => user.LastName.IsInsensitiveLike(searchQuery.LastName, MatchMode.Anywhere)); } if (searchQuery.UserRoleId != null) { UserRole role = null; query = query.JoinAlias(user => user.Roles, () => role).Where(() => role.Id == searchQuery.UserRoleId); } return(query.Paged(searchQuery.Page)); }
protected override HandlerResult GetResult(IHostServer server, WebContext context, string callbackEndPoint, CancellationToken cancel) { if ( !Roles.IsInRole(context.User.Identity, $"{SecurityConst.ROLE_SECURITY_ADMIN},{SecurityConst.ROLE_DOMAIN_ADMIN}")) { throw new SecurityException("only admins allowed to call this"); } var j = RequestParameters.Create(context).AsJson(); var uq = new UserSearchQuery(); uq.LoadFromJson(j); //check if not total admin if (!Roles.IsInRole(context.User.Identity, $"{SecurityConst.ROLE_SECURITY_ADMIN}")) { var domain = ((Identity) context.User.Identity).User.Domain; if (string.IsNullOrWhiteSpace(domain)) { throw new SecurityException("invalid domain for user "+domain); } if (!string.IsNullOrWhiteSpace(uq.Domain) && uq.Domain != domain) { throw new SecurityException("try access not self domain "+domain+" ("+uq.Domain+")"); } uq.Domain = domain; } var users = Users.SearchUsers(uq).ToArray(); return new HandlerResult { Result = new {items= users} }; }
public IEnumerable <IUser> SearchUsers(UserSearchQuery query) { yield break; }
public ActionResult Index(UserSearchQuery searchQuery) { ViewData["users"] = _userSearchService.GetUsersPaged(searchQuery); ViewData["roles"] = _userSearchService.GetAllRoleOptions(); return(View(searchQuery)); }
public Task <List <UserListResponse> > Handle(UserSearchQuery request, CancellationToken cancellationToken) { return(context.Users.Where(x => x.Name.ToLower().Contains(request.Name.ToLower())) .ProjectTo <UserListResponse>(configurationProvider) .ToListAsync(cancellationToken)); }
public IEnumerable<IUser> SearchUsers(UserSearchQuery query) { return _cache.Values.Where(query.IsMatch); }
public IEnumerable <IUser> SearchUsers(UserSearchQuery query) { return(Values.Where(query.IsMatch)); }