コード例 #1
0
        public async Task <PagedListData <Artist> > GetArtistsAsync(int pageIndex, int pageSize = 10, string search = "", string orderBy = "")
        {
            var query = Enumerable.Empty <Artist>().AsQueryable();

            if (!search.IsNullOrEmpty())
            {
                query = _context.Artist.Where(a => a.ArtistName.Contains(search));
            }
            else
            {
                query = _context.Artist;
            }

            if (orderBy.IsNullOrEmpty())
            {
                query.OrderByDescending(a => a.ArtistName);
            }
            else
            {
                query.OrderByDescending(a => a.ArtistId);
            }

            // var a = _context.Artist.ToList();

            var pagedList = await PagedListData <Artist> .CreateAsync(query, pageIndex, pageSize);

            return(pagedList);
        }
コード例 #2
0
        public async virtual Task <IActionResult> GetDataAsync(
            [FromRoute] string name,
            [FromQuery(Name = "$top")] string top,
            [FromQuery(Name = "$skip")] string skip,
            [FromQuery(Name = "$orderby")] string orderby,
            [FromQuery(Name = "$expand")] string expand,
            [FromQuery(Name = "$filter")] string filter)
        {
            try
            {
                ODataQueryOptions oDataQueryOptions = new ODataQueryOptions
                {
                    Top  = top,
                    Skip = skip,
                    //Select = select,
                    OrderBy = orderby,
                    Expand  = expand,
                    Filters = string.IsNullOrEmpty(filter) ? null : new List <string> {
                        filter
                    }
                };

                var entity = entitiesRepository.GetById(name);
                if (entity == null)
                {
                    return(NotFound($"No data found for entity {name}"));
                }

                var items = await(Task <IEnumerable <object> >) GetType()
                            .GetMethod("ApplyQueryOptionsAsync")
                            .MakeGenericMethod(entity.ToType())
                            .Invoke(this, new object[] { oDataQueryOptions });

                return(Ok(new DataListResponse
                {
                    Data = await PagedListData <object> .CreateAsync(
                        items,
                        top,
                        skip,
                        async() => await(Task <long?>) GetType()
                        .GetMethod("CountAsync")
                        .MakeGenericMethod(entity.ToType())
                        .Invoke(this, null))
                }));
            }
            catch (Exception e)
            {
                return(this.InternalServerError(e.FlattenMessages()));
            }
        }
コード例 #3
0
ファイル: UserData.cs プロジェクト: zcurry-Dev/SS
        public async Task <PagedListData <Ssuser> > GetUsersAsync(int pageIndex, int pageSize = 10, string search = "", string orderBy = "")
        {
            if (!search.IsNullOrEmpty())
            {
                _userManager.Users.Where(s => s.UserName.Contains(search));  //todo more searching fields
            }

            if (orderBy.IsNullOrEmpty())
            {
                _userManager.Users.OrderByDescending(u => u.LastName); //todo
            }
            else
            {
                _userManager.Users.OrderByDescending(u => u.Id); //todo
            }

            var pagedList = await PagedListData <Ssuser> .CreateAsync(_userManager.Users, pageIndex, pageSize);

            return(pagedList);
        }
コード例 #4
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()));
            }
        }
コード例 #5
0
        public async virtual Task <IActionResult> GetFilesAsync(
            [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 files = await Task.FromResult(filesRepository
                                                  .AsQueryable()
                                                  .OData()
                                                  .ApplyQueryOptionsWithoutSelectExpand(oDataQueryOptions)
                                                  .ToList());

                foreach (var file in files)
                {
                    file.DownloadUri = this.BuildLink($"files/{file.Id}");
                }

                return(Ok(new FileListResponse
                {
                    Data = await PagedListData <FileInfo> .CreateAsync(files)
                }));
            }
            catch (Exception e)
            {
                return(this.InternalServerError(e.FlattenMessages()));
            }
        }
コード例 #6
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()));
            }
        }