Example #1
0
        public IPagedResponse <MediaModel> Get([FromUri] PagingFilter filter)
        {
            if (filter == null)
            {
                filter = new PagingFilter(1, 25);
            }

            var userId = this.getUserId();

            IPagedResponse <IMedia> results = Business.Media.Media.GetMedia(userId, filter.Page, filter.Size);

            ICollection <MediaModel> models = new List <MediaModel>();

            if (results.Data != null)
            {
                foreach (IMedia a in results.Data)
                {
                    var model = MediaModel.Load(a);
                    models.Add(model);
                }
            }

            return(new PagedResponse <MediaModel>()
            {
                TotalCount = results.TotalCount,
                Data = models
            });
        }
Example #2
0
        public IPagedResponse <AssetModel> GetAssets([FromUri] PagingFilter filter)
        {
            if (filter == null)
            {
                filter = new PagingFilter(1, 25);
            }

            IPagedResponse <IAsset> results = Asset.GetAssets(filter.Page, filter.Size);

            ICollection <AssetModel> assets = new List <AssetModel>();

            if (results.Data != null)
            {
                foreach (IAsset a in results.Data)
                {
                    var asset = AssetModel.Load(a);
                    assets.Add(asset);
                }
            }

            return(new PagedResponse <AssetModel>()
            {
                TotalCount = results.TotalCount,
                Data = assets
            });
        }
Example #3
0
        public async Task <IPagedResponse <NewsReadModel> > SearchAsync([FromQuery] NewsSearchQuery searchQuery, CancellationToken cancellationToken)
        {
            IPagedResponse <NewsReadModel> response = null;
            await _elasticClient.Indices.FlushAsync(indexName, d => d.RequestConfiguration(c => c.AllowedStatusCodes((int)HttpStatusCode.NotFound)), cancellationToken);

            await _elasticClient.Indices.RefreshAsync(indexName, d => d.RequestConfiguration(c => c.AllowedStatusCodes((int)HttpStatusCode.NotFound)), cancellationToken);

            SearchRequest searchRequest = new SearchRequest <NewsReadModel>(indexName)
            {
                Query = new BoolQuery()
                {
                    Should = new QueryContainer[]
                    {
                        new MatchQuery()
                        {
                            Field = Infer.Field <NewsReadModel>(f => f.Title),
                            Query = searchQuery.Title,
                            Boost = 1.1
                        },
                        new MatchQuery()
                        {
                            Field = Infer.Field <NewsReadModel>(f => f.SubTitle),
                            Query = searchQuery.SubTitle,
                        }
                    },
                    Filter = new QueryContainer[]
                    {
                        new TermQuery()
                        {
                            Field = Infer.Field <NewsReadModel>(f => f.NCategory),
                            Value = searchQuery.Category,
                        },
                        new TermQuery()
                        {
                            Field = Infer.Field <NewsReadModel>(f => f.Country),
                            Value = searchQuery.Country,
                        },
                        new MatchQuery()
                        {
                            Field = Infer.Field <NewsReadModel>(f => f.PortalName),
                            Query = searchQuery.Portal,
                        }
                    }
                }
            };

            var record = await _elasticClient.SearchAsync <NewsReadModel>(searchRequest, cancellationToken);

            if (record?.Documents?.Count > 0)
            {
                response = new PagedResponse <NewsReadModel>()
                {
                    Records    = record.Documents.ToList(),
                    TotalCount = record.Total
                };
            }

            return(response);
        }
Example #4
0
        public IAsyncOperation <LoadMoreItemsResult> LoadMoreItemsAsync(uint count)
        {
            CoreDispatcher dispatcher = Window.Current != null ? Window.Current.Dispatcher : Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher;

            if (count > 50 || count <= 0)
            {
                // default load count to be set to 50
                count = 50;
            }


            return(Task.Run <LoadMoreItemsResult>(
                       async() =>
            {
                IPagedResponse <K> result = await this.Source.GetPage(string.Format(this.Query, count), ++this.CurrentPage, (int)count);

                this.VirtualCount = result.VirtualCount;
                if (rpp == 0)
                {
                    rpp = result.rpp;
                }

                await dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal,
                    () =>
                {
                    foreach (K item in result.Items)
                    {
                        this.Add(item);
                    }
                });

                return new LoadMoreItemsResult()
                {
                    Count = (uint)result.Items.Count()
                };
            }).AsAsyncOperation <LoadMoreItemsResult>());
        }
        public ActionResult <IPagedResponse <FavoriteDTO> > GetListFavorites(int page = 1, SortState sortOrder = SortState.NameAsc)
        {
            IPagedResponse <FavoriteDTO> objectList = favoriteService.GetFavorites(page, sortOrder);

            return(Ok(objectList));
        }
 public ResponseEventArgs(string pageToken, IPagedResponse <TResponse> response)
 {
     PageToken = pageToken;
     Response  = response;
 }
Example #7
0
        public ActionResult <IPagedResponse <FavoriteDTO> > GetListFavorites(int userId, int page = 1, SortState sortOrder = SortState.NameAsc, bool isPageRequestNeeded = true)
        {
            IPagedResponse <FavoriteDTO> objectList = favoriteService.GetFavorites(userId, page, sortOrder, isPageRequestNeeded);

            return(Ok(objectList));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PagedResponseModel{T}"/> class.
 /// </summary>
 /// <param name="statusCode">The status code.</param>
 /// <param name="title">The title.</param>
 /// <param name="pagedResults">The paged results.</param>
 public PagedResponseModel(int statusCode, string title, IPagedResponse <T> pagedResults)
     : this(statusCode,
            title,
            (pagedResults ?? throw new ArgumentNullException(nameof(pagedResults))).Data,
Example #9
0
 public Pagination Next <T>(IPagedResponse <T> page)
 {
     var next = new Pagination
     {
         After  = default,