public async Task <List <IUserDTO> > GetUsersAsync(string userId) { var users = new List <IUserDTO>(); await context.Users .Where(u => u.Id != userId) .Where(u => u.IsPublic == true) .Where(u => u.UserName != "admin") .ForEachAsync(u => users.Add(mapper.Map <UserResponse>(u))); await context.Users .Where(u => u.Id != userId) .Where(u => u.IsPublic == false) .Where(u => u.UserName != "admin") .ForEachAsync(u => users.Add(mapper.Map <UserShortResponse>(u))); foreach (IUserDTO userDto in users) { var relationship = relationshipService.GetRelationshipByNames(userDto.UserName, userId); if (relationship != null) { if (relationship.RelationshipState == RelationshipStates.CONFIRMED) { userDto.IsFriend = true; userDto.IsBlocked = false; userDto.RelationShipId = relationship.RelationshipId; } else if (relationship.RelationshipState == RelationshipStates.BLOCKED) { userDto.IsFriend = false; userDto.IsBlocked = true; userDto.RelationShipId = relationship.RelationshipId; } else if (relationship.RelationshipState == RelationshipStates.PENDING) { userDto.IsFriend = false; userDto.IsBlocked = false; userDto.IsPending = true; userDto.RelationShipId = relationship.RelationshipId; } else { userDto.IsFriend = false; userDto.IsBlocked = false; userDto.IsPending = false; userDto.RelationShipId = null; } } } return(users); }