public async Task <IActionResult> QuickSearch(UserSearchOption searchOption)
        {
            var query = _userRepository.Query().Where(x => !x.IsDeleted);

            if (!string.IsNullOrWhiteSpace(searchOption.Name))
            {
                query = query.Where(x => x.FullName.Contains(searchOption.Name));
            }

            if (!string.IsNullOrWhiteSpace(searchOption.Email))
            {
                query = query.Where(x => x.Email.Contains(searchOption.Email));
            }

            var users = await query.Take(5).Select(x => new
            {
                x.Id,
                x.FullName,
                x.Email,
                x.IdNumber,
                x.PhoneNumber
            }).ToListAsync();

            return(Ok(users));
        }
示例#2
0
        public async Task <IEnumerable <UserInfo> > SearchWithFriends(UserSearchOption option, PageOptions page)
        {
            var users = await Search(null, page);             // get user info from cache or db

            var fromService = _conf["FriendService:From"];
            var virtualPath = _conf["FriendService:VirtualPath"];

            using (var client = new HttpClient())
            {
                var friends = await client.PostAsync <List <FriendViewModel>, ConsulService>(fromService, virtualPath, null, new { SubscriberId = option.UserId, ServiceId = option.ServiceId }, _serviceFinder, _loadBalancer);                // get friend info from cache or db

                foreach (var friend in friends)
                {
                    // aggregate friend and user data
                    var user = users.FirstOrDefault(x => x.UserId == friend.TargetId.ToGuid());
                    if (!user.IsNull())
                    {
                        user.IsFriend = true;
                    }
                }
            }

            return(users);
        }
示例#3
0
        /// <summary>
        /// Searching and matching other matchs/clanwars
        /// </summary>
        /// <param name="userSearchInfo">insert UserSearchInfo object</param>
        /// <param name="option">are you starting searching OR just update search results?</param>
        /// <param name="maxResults">max results you want</param>
        /// <param name="pageIndex">page index (fx. what page you are on)</param>
        /// <param name="langId">insert langid for langauge</param>
        /// <param name="minNoUserActivityTimeSeconds">If there is no activity for the user (fx. internet connection lost)</param>
        /// <param name="noticemessage">notice if user still can search OR errors</param>
        /// <param name="fromLastSeconds">Write the number of seconds you want to get all "Searchs" from</param>
        /// <param name="context">current httpcontext</param>
        /// <param name="maxIdleTimeSeconds">How long the user can max search in time</param>
        /// <returns>anynmous object</returns>
        public List <SearchObject> UserSearchMatch(UserSearchInfo userSearchInfo,
                                                   UserSearchOption option,
                                                   int maxResults,
                                                   int pageIndex,
                                                   int langId,
                                                   int maxIdleTimeSeconds,
                                                   int minNoUserActivityTimeSeconds,
                                                   out SearchNoticeMessage noticemessage,
                                                   int fromLastSeconds,
                                                   HttpContext context)
        {
            _context = context;

            noticemessage = SearchNoticeMessage.Searching; // default status value

            // Create search
            if (option == UserSearchOption.CreateUserSearch)
            {
                InsertusiResult result = CreateUserSearch(userSearchInfo);
                if (result == InsertusiResult.Error)
                {
                    noticemessage = SearchNoticeMessage.UnknownError;
                }
            }



            // Check max idle/searching time
            if (option == UserSearchOption.UpdateUserSearch)
            {
                // Update user activity
                noticemessage = UpdateUserActivity(userSearchInfo,
                                                   minNoUserActivityTimeSeconds,
                                                   context,
                                                   noticemessage);

                noticemessage = CheckUserIdleActivity(userSearchInfo,
                                                      maxIdleTimeSeconds,
                                                      context,
                                                      noticemessage);
            }

            if (option == UserSearchOption.UpdateActivity)
            {
                // Update user activity
                noticemessage = UpdateUserActivity(userSearchInfo,
                                                   minNoUserActivityTimeSeconds,
                                                   context,
                                                   noticemessage);

                noticemessage = CheckUserIdleActivity(userSearchInfo,
                                                      maxIdleTimeSeconds,
                                                      context,
                                                      noticemessage);

                return(null);
            }

            // SEARCH NOW!!!!
            var itemResult = noticemessage == SearchNoticeMessage.Searching
                             ? SearchMatchs(userSearchInfo,
                                            maxResults,
                                            pageIndex,
                                            langId,
                                            fromLastSeconds)
                             : null;


            // no result change noticemsg
            if (itemResult == null)
            {
                noticemessage = SearchNoticeMessage.NoResults;
            }


            // return search/match results
            return(itemResult);
        }