Ejemplo n.º 1
0
        public async Task <ProductVideoSearchResult> SearchVideoLinksAsync(ProductVideoSearchCriteria criteria)
        {
            var cacheKey = CacheKey.With(GetType(), nameof(SearchVideoLinksAsync), criteria.GetCacheKey());

            return(await _platformMemoryCache.GetOrCreateExclusiveAsync(cacheKey, async (cacheEntry) =>
            {
                cacheEntry.AddExpirationToken(ProductVideoCacheRegion.CreateChangeToken());
                var result = AbstractTypeFactory <ProductVideoSearchResult> .TryCreateInstance();

                using (var repository = _repositoryFactory())
                {
                    var query = repository.VideoLinks.Where(x => criteria.ProductIds.Contains(x.ProductId));

                    result.TotalCount = await query.CountAsync();

                    if (criteria.Take > 0)
                    {
                        var videoLinksIds = await query.OrderByDescending(x => x.CreatedDate).Skip(criteria.Skip)
                                            .Take(criteria.Take)
                                            .Select(x => x.Id)
                                            .ToArrayAsync();

                        var priorResults = await _productVideoService.GetByIdsAsync(videoLinksIds);
                        //TODO warning EF1001: Microsoft.EntityFrameworkCore.Internal.EnumerableExtensions is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs.
                        result.Results = priorResults;
                    }

                    return result;
                }
            }));
        }
        //[CheckPermission(Permission = Core.ModuleConstants.Security.Permissions.Read)]
        public async Task <IActionResult> SearchProductVideos([FromBody] ProductVideoSearchCriteria criteria)
        {
            var validationResult = await _validator.ValidateAsync(criteria);

            if (!validationResult.IsValid)
            {
                return(BadRequest(string.Join(' ', validationResult.Errors.Select(x => x.ErrorMessage))));
            }

            var result = await _productVideoSearchService.SearchVideoLinksAsync(criteria);

            return(Ok(result));
        }