private Expression <Func <TEntity, bool> > BuildRequestExpression(GetAllQuery <TEntity, TRequestModel> request)
        {
            var expressionList = new List <Expression <Func <TEntity, bool> > >();

            var queryExpressionBySearchQuery = !string.IsNullOrEmpty(request.SearchQuery) ? ExpressionBuilders.BuildQueryExpressionBySearchQuery <TEntity>(request.SearchQuery) : null;

            if (queryExpressionBySearchQuery != null)
            {
                expressionList.Add(queryExpressionBySearchQuery);
            }

            if (request.ParentExpression != null)
            {
                expressionList.Add(request.ParentExpression);
            }

            Expression <Func <TEntity, bool> > requestExpression = x => true;

            if (expressionList.Count > 0)
            {
                foreach (var expression in expressionList)
                {
                    requestExpression = ExpressionFunctions.AndAlso(requestExpression, expression);
                }
            }

            return(requestExpression);
        }
        /// <inheritdoc/>
        public async Task <PaginatedList <TRequestModel> > Handle(GetAllQuery <TEntity, TRequestModel> request, CancellationToken cancellationToken)
        {
            PaginatedList <TRequestModel> result = new PaginatedList <TRequestModel>();

            try
            {
                var requestExpression = this.BuildRequestExpression(request);

                result.AllItemsCount = this.context
                                       .Set <TEntity>()
                                       .Where(requestExpression)
                                       .Count();

                result.CurrentPage = request.Page;
                result.PageSize    = request.PageSize;

                var orderType = this.GetOrderTypeByString(request.OrderType);
                IEnumerable <TRequestModel> entities = this.context
                                                       .Set <TEntity>()
                                                       .Where(requestExpression)
                                                       .OrderByProperty(request.OrderBy, orderType)
                                                       .Skip(result.StartRow)
                                                       .Take(request.PageSize)
                                                       .ProjectTo <TRequestModel>(this.mapper.ConfigurationProvider)
                                                       .ToList();

                result.Items = entities;
            }
            catch (Exception ex)
            {
                await this.logger.LogErrorAsync(ex, nameof(GetAllQueryHandler <TEntity, TRequestModel>));
            }

            return(result);
        }