コード例 #1
0
        /// <summary>
        /// Get LnD team events as per user search text.
        /// </summary>
        /// <param name="searchParametersDto">Search parameters entered by user.</param>
        /// <returns>List of events.</returns>
        public async Task <IEnumerable <EventEntity> > GetEventsAsync(Models.SearchParametersDto searchParametersDto)
        {
            searchParametersDto = searchParametersDto ?? throw new ArgumentNullException(nameof(searchParametersDto), "Search parameters are null");

            searchParametersDto.SkipRecords        = searchParametersDto.PageCount * this.botOptions.Value.EventsPageSize;
            searchParametersDto.SearchResultsCount = this.botOptions.Value.EventsPageSize;

            var searchParameters = this.InitializeSearchParameters(searchParametersDto);

            var events = await this.eventSearchService.GetEventsAsync(searchParametersDto.SearchString.EscapeSpecialCharacters(), searchParameters);

            return(events);
        }
        /// <summary>
        /// Initialization of search service parameters which will help in searching the documents.
        /// </summary>
        /// <param name="searchParametersDto">Search parameters.</param>
        /// <returns>Represents an search parameter object.</returns>
        private Azure.Search.Models.SearchParameters InitializeSearchParameters(Models.SearchParametersDto searchParametersDto)
        {
            Azure.Search.Models.SearchParameters searchParameters = new Azure.Search.Models.SearchParameters()
            {
                Top    = searchParametersDto.SearchResultsCount.HasValue && searchParametersDto.SortByFilter != (int)SortBy.PopularityByRecentCollaborators ? searchParametersDto.SearchResultsCount : ApiSearchResultCount,
                Skip   = searchParametersDto.SkipRecords.HasValue && searchParametersDto.SortByFilter != (int)SortBy.PopularityByRecentCollaborators ? searchParametersDto.SkipRecords : 0,
                Select = searchParametersDto.SearchScope == EventSearchType.SearchByName ?
                         new[]
                {
                    nameof(EventEntity.Name),
                    nameof(EventEntity.EventId),
                }
                :
                new[]
                {
                    nameof(EventEntity.Audience),
                    nameof(EventEntity.CategoryId),
                    nameof(EventEntity.Description),
                    nameof(EventEntity.EndTime),
                    nameof(EventEntity.EventId),
                    nameof(EventEntity.MaximumNumberOfParticipants),
                    nameof(EventEntity.Name),
                    nameof(EventEntity.Photo),
                    nameof(EventEntity.SelectedColor),
                    nameof(EventEntity.StartDate),
                    nameof(EventEntity.StartTime),
                    nameof(EventEntity.TeamId),
                    nameof(EventEntity.Type),
                    nameof(EventEntity.MandatoryAttendees),
                    nameof(EventEntity.AutoRegisteredAttendees),
                    nameof(EventEntity.RegisteredAttendeesCount),
                    nameof(EventEntity.Venue),
                    nameof(EventEntity.RegisteredAttendees),
                },
                SearchFields = new[] { nameof(EventEntity.Name), nameof(EventEntity.Description) }, // default search event by name and description
                Filter       = this.filterQueryGenerator.GetStrategy(searchParametersDto.SearchScope)?.GenerateFilterQuery(searchParametersDto),
            };

            searchParameters.OrderBy = searchParametersDto.SortByFilter == (int)SortBy.Recent ?
                                       new[] { $"{nameof(EventEntity.CreatedOn)} desc" } :
            new[] { $"{nameof(EventEntity.RegisteredAttendeesCount)} desc" };

            var filterConditions = this.GetFilterCondition(searchParametersDto.CreatedByFilter, searchParametersDto.CategoryFilter);

            if (!string.IsNullOrEmpty(filterConditions))
            {
                searchParameters.Filter += $" and {filterConditions}";
            }

            return(searchParameters);
        }
コード例 #3
0
        /// <summary>
        /// Initialization of search service parameters which will help in searching the documents.
        /// </summary>
        /// /// <param name="searchParametersDto">Search parameters entered by user.</param>
        /// <returns>Represents an search parameter object.</returns>
        private Azure.Search.Models.SearchParameters InitializeSearchParameters(Models.SearchParametersDto searchParametersDto)
        {
            Azure.Search.Models.SearchParameters searchParameters = new Azure.Search.Models.SearchParameters()
            {
                Top    = searchParametersDto.SearchResultsCount ?? ApiSearchResultCount,
                Skip   = searchParametersDto.SkipRecords ?? 0,
                Select = new[]
                {
                    nameof(EventEntity.Audience),
                    nameof(EventEntity.CategoryId),
                    nameof(EventEntity.CreatedBy),
                    nameof(EventEntity.CreatedOn),
                    nameof(EventEntity.Description),
                    nameof(EventEntity.EndTime),
                    nameof(EventEntity.EventId),
                    nameof(EventEntity.IsAutoRegister),
                    nameof(EventEntity.MaximumNumberOfParticipants),
                    nameof(EventEntity.MeetingLink),
                    nameof(EventEntity.Name),
                    nameof(EventEntity.Photo),
                    nameof(EventEntity.StartDate),
                    nameof(EventEntity.StartTime),
                    nameof(EventEntity.Status),
                    nameof(EventEntity.TeamId),
                    nameof(EventEntity.Type),
                    nameof(EventEntity.UpdatedBy),
                    nameof(EventEntity.UpdatedOn),
                    nameof(EventEntity.Venue),
                    nameof(EventEntity.EndDate),
                    nameof(EventEntity.IsRegistrationClosed),
                    nameof(EventEntity.RegisteredAttendeesCount),
                },
                SearchFields = new[] { nameof(EventEntity.Name), nameof(EventEntity.Description) }, // default search event by name
                Filter       = this.filterQueryGenerator.GetStrategy(searchParametersDto.SearchScope).GenerateFilterQuery(searchParametersDto),
            };

            if (searchParametersDto.SearchScope == EventSearchType.GetCategoryEvent)
            {
                searchParameters.Top    = 1;
                searchParameters.Select = new[]
                {
                    nameof(EventEntity.CategoryId),
                    nameof(EventEntity.EventId),
                };
            }

            searchParameters.OrderBy = new[] { $"{nameof(EventEntity.CreatedOn)} desc" };

            return(searchParameters);
        }
        /// <summary>
        /// Get events as per user search text.
        /// </summary>
        /// <param name="searchParametersDto">Search parameters entered by user.</param>
        /// <returns>List of events.</returns>
        public async Task <IEnumerable <EventEntity> > GetEventsAsync(Models.SearchParametersDto searchParametersDto)
        {
            searchParametersDto = searchParametersDto ?? throw new ArgumentNullException(nameof(searchParametersDto), "Search parameter is null");

            if (searchParametersDto.SearchScope != EventSearchType.DayBeforeReminder && searchParametersDto.SearchScope != EventSearchType.WeekBeforeReminder &&
                string.IsNullOrEmpty(searchParametersDto.UserObjectId))
            {
                return(Enumerable.Empty <EventEntity>());
            }

            searchParametersDto.SkipRecords = searchParametersDto.SortByFilter != (int)SortBy.PopularityByRecentCollaborators && searchParametersDto.SearchResultsCount != null ? searchParametersDto.PageCount * searchParametersDto.SearchResultsCount : null;

            var searchParameters = this.InitializeSearchParameters(searchParametersDto);
            var events           = await this.eventSearchService.GetEventsAsync(searchParametersDto.SearchString.EscapeSpecialCharacters(), searchParameters);

            if (events.IsNullOrEmpty() || searchParametersDto.SearchScope == EventSearchType.DayBeforeReminder || searchParametersDto.SearchScope == EventSearchType.WeekBeforeReminder)
            {
                return(events);
            }

            foreach (var eventDetails in events)
            {
                eventDetails.IsMandatoryForLoggedInUser = this.CheckIfMandatoryForLoggedInUser(eventDetails, searchParametersDto.UserObjectId);
                eventDetails.IsLoggedInUserRegistered   = this.CheckIfLoggedInUserRegistered(eventDetails, searchParametersDto.UserObjectId);

                if (searchParametersDto.SortByFilter == (int)SortBy.PopularityByRecentCollaborators && !searchParametersDto.RecentCollaboratorIds.IsNullOrEmpty())
                {
                    if (!string.IsNullOrEmpty(eventDetails.RegisteredAttendees))
                    {
                        var registeredAttendees = eventDetails.RegisteredAttendees.Split(";");
                        var recentCollaborators = searchParametersDto.RecentCollaboratorIds.Intersect <string>(registeredAttendees);
                        eventDetails.LoggedInUserCollaboratorsCount = recentCollaborators?.Count() ?? 0;
                    }

                    if (!string.IsNullOrEmpty(eventDetails.AutoRegisteredAttendees))
                    {
                        var autoRegisteredAttendees = eventDetails.AutoRegisteredAttendees.Split(";");
                        var recentCollaborators     = searchParametersDto.RecentCollaboratorIds.Intersect <string>(autoRegisteredAttendees);
                        eventDetails.LoggedInUserCollaboratorsCount += recentCollaborators?.Count() ?? 0;
                    }
                }
            }

            return(searchParametersDto.SortByFilter == (int)SortBy.PopularityByRecentCollaborators ? events.OrderByDescending(userEvent => userEvent.LoggedInUserCollaboratorsCount).Skip(searchParametersDto.SkipRecords ?? 0).Take((int)searchParametersDto.SearchResultsCount) : events);
        }