Exemplo n.º 1
0
        public async Task <IReadOnlyCollection <ISearchResult> > SearchAsync(int?currentUserId, string searchString)
        {
            bool matchByIdIsPerfect;
            int? characterIdToFind = SearchKeywordsResolver.TryGetId(
                searchString,
                keysForPerfectMath,
                out matchByIdIsPerfect);

            var results =
                await
                UnitOfWork.GetDbSet <Character>()
                .Where(c =>
                       (c.CharacterId == characterIdToFind ||
                        c.CharacterName.Contains(searchString) ||
                        (c.Description.Contents != null && c.Description.Contents.Contains(searchString))) &&
                       c.IsActive
                       )
                .OrderByDescending(cg => cg.CharacterName.Contains(searchString))
                .ToListAsync();

            //search by ID is only for masters of the character's project
            var characters = results.Where(c =>
                                           CheckMasterAccessIfMatchById(c, currentUserId, characterIdToFind));

            return(GetWorldObjectsResult(
                       currentUserId,
                       characters,
                       LinkType.ResultCharacter,
                       wasFoundByIdPredicate: c => c.Id == characterIdToFind,
                       perfectMatchPredicte: c => c.Id == characterIdToFind && matchByIdIsPerfect));
        }
Exemplo n.º 2
0
        public async Task <IReadOnlyCollection <ISearchResult> > SearchAsync(int?currentUserId, string searchString)
        {
            int?idToFind = SearchKeywordsResolver.TryGetId(
                searchString,
                keysForPerfectMath,
                out var matchByIdIsPerfect);

            if (idToFind == null)
            {
                //Only search by Id is valid for claims
                return(new ReadOnlyCollection <ISearchResult>(new List <ISearchResult>()));
            }

            var results =
                await
                UnitOfWork.GetDbSet <Claim>()
                .Where(claim => claim.ClaimId == idToFind)
                .ToListAsync();

            return(results
                   .Where(claim => claim.HasMasterAccess(currentUserId))
                   .Select(claim => new SearchResultImpl
            {
                LinkType = LinkType.Claim,
                Name = claim.Name,
                Description = new MarkdownString(WorldObjectProviderBase.GetFoundByIdDescription(claim.ClaimId)),
                Identification = claim.ClaimId.ToString(),
                ProjectId = claim.ProjectId,
                IsPublic = false,
                IsActive = claim.ClaimStatus.IsActive(),
                IsPerfectMatch = claim.ClaimId == idToFind && matchByIdIsPerfect,
            })
                   .ToList());
        }
Exemplo n.º 3
0
        public async Task <IReadOnlyCollection <ISearchResult> > SearchAsync(int?currentUserId, string searchString)
        {
            bool matchByIdIsPerfect;
            int? idToFind = SearchKeywordsResolver.TryGetId(
                searchString,
                keysForPerfectMath,
                out matchByIdIsPerfect);

            var results =
                await
                UnitOfWork.GetDbSet <User>()
                .Where(user =>
                       //TODO There should be magic way to do this. Experiment with Expression.Voodoo
                       user.UserId == idToFind ||
                       user.Email.Contains(searchString) ||
                       user.FatherName.Contains(searchString) ||
                       user.BornName.Contains(searchString) ||
                       user.SurName.Contains(searchString) ||
                       user.PrefferedName.Contains(searchString) ||
                       (user.Extra != null && user.Extra.Nicknames != null && user.Extra.Nicknames.Contains(searchString))
                       )
                .ToListAsync();

            return(results.Select(user =>
            {
                bool wasfoundById = user.UserId == idToFind;
                var description = new MarkdownString(wasfoundById
          ? WorldObjectProviderBase.GetFoundByIdDescription(user.UserId)
          : "");

                return new SearchResultImpl
                {
                    LinkType = LinkType.ResultUser,
                    Name = user.GetDisplayName(),
                    Description = description,
                    Identification = user.UserId.ToString(),
                    ProjectId = null, //Users not associated with any project
                    IsPublic = true,
                    IsActive = true,
                    IsPerfectMatch = wasfoundById && matchByIdIsPerfect,
                };
            }).ToList());
        }