Ejemplo n.º 1
0
        public virtual async Task <IActionResult> GetEntitiesAsync(
            [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(entitiesRepository
                                                     .AsQueryable()
                                                     .OData()
                                                     .ApplyQueryOptionsWithoutSelectExpand(oDataQueryOptions)
                                                     .ToList());

                return(Ok(new EntityListResponse
                {
                    SchemaVersion = Assembly.GetAssembly(typeof(DataHub.Entities.Asset)).GetName().Version.ToString(),
                    Data = await PagedListData <Entity> .CreateAsync(
                        entities,
                        top,
                        skip,
                        async() => await Task.FromResult(entitiesRepository.AsQueryable().LongCount()))
                }));
            }
            catch (Exception e)
            {
                return(this.InternalServerError(e.FlattenMessages()));
            }
        }