Exemplo n.º 1
0
        public async virtual Task <IActionResult> GetMetadataAsync(
            [FromQuery(Name = "$top")] string top,
            [FromQuery(Name = "$skip")] string skip,
            [FromQuery(Name = "$orderby")] string orderby,
            [FromQuery(Name = "$filter")] string filter)
        {
            try
            {
                ODataQueryOptions oDataQueryOptions = new ODataQueryOptions
                {
                    Top     = top,
                    Skip    = skip,
                    OrderBy = orderby,
                    Filters = string.IsNullOrEmpty(filter) ? null : new List <string> {
                        filter
                    }
                };

                var entities = await Task.FromResult(timeseriesMetadataRepository
                                                     .AsQueryable()
                                                     .OData()
                                                     .ApplyQueryOptionsWithoutSelectExpand(oDataQueryOptions)
                                                     .ToList());

                return(Ok(new TimeseriesMetadataListResponse
                {
                    Data = await PagedListData <TimeseriesMetadata> .CreateAsync(
                        entities,
                        top,
                        skip,
                        async() => await timeseriesMetadataRepository.AsQueryable().LongCountAsync())
                }));
            }
            catch (Exception e)
            {
                return(this.InternalServerError(e.FlattenMessages()));
            }
        }