示例#1
0
        public async Task <IEnumerable <WordsDTO> > GetFilteredEntitiesAsync(
            string searchingUrlQuery = null,
            PaginationUrlQuery paginationUrlQuery = null)
        {
            Expression <Func <Words, bool> > filter = e => true;

            if (!string.IsNullOrEmpty(searchingUrlQuery))
            {
                filter = filter.And(e => e.Word.Contains(searchingUrlQuery));

                int i;
                if (!Int32.TryParse(searchingUrlQuery, out i))
                {
                    i = -1;
                }
                if (i != -1 && i != 0)
                {
                    filter = filter.Or(e => e.Id == i);
                }
            }

            var entities = await _uow.WordsRepository.GetRangeAsync(
                include : r => r.Include(o => o.Rels),
                filter : filter,
                paginationUrlQuery : paginationUrlQuery);

            var dtos = _mapper.Map <List <Words>, List <WordsDTO> >(entities);

            return(dtos);
        }
示例#2
0
        public async Task <IEnumerable <WordsDTO> > GetAllEntitiesAsync(PaginationUrlQuery paginationUrlQuery = null)
        {
            var entities = await _uow.WordsRepository.GetRangeAsync(
                include : r => r.Include(o => o.Rels),
                paginationUrlQuery : paginationUrlQuery);

            var dtos = _mapper.Map <List <Words>, List <WordsDTO> >(entities);

            return(dtos);
        }
示例#3
0
        public async Task <IEnumerable <WordsToListDTO> > GetMainEntitiesAsync(PaginationUrlQuery paginationUrlQuery = null)
        {
            var entities = await _uow.WordsRepository.GetRangeAsync(
                filter : f => f.Type == 1, // 1 it's type of main words
                paginationUrlQuery : paginationUrlQuery
                );

            var dtos = _mapper.Map <List <Words>, List <WordsToListDTO> >(entities);

            return(dtos);
        }
        public virtual async Task <ActionResult <IEnumerable <WordsDTO> > > Get([FromQuery] PaginationUrlQuery paginationUrlQuery = null)
        {
            var dtos = await _wordsService.GetAllEntitiesAsync(paginationUrlQuery);

            if (!dtos.Any())
            {
                return(NoContent());
            }
            var pageInfo = new PageInfo()
            {
                PageNumber   = paginationUrlQuery.PageNumber,
                PageSize     = paginationUrlQuery.PageSize,
                TotalRecords = _wordsService.TotalRecords
            };

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(pageInfo));

            return(Ok(dtos));
        }
示例#5
0
        public async Task <List <TEntity> > GetRangeAsync(Expression <Func <TEntity, bool> > filter = null,
                                                          Func <IQueryable <TEntity>, IIncludableQueryable <TEntity, object> > include = null,
                                                          Expression <Func <TEntity, string> > sorting = null,
                                                          bool?sortOrder = null,
                                                          PaginationUrlQuery paginationUrlQuery = null)
        {
            IQueryable <TEntity> query = _dbSet;

            if (filter != null)
            {
                query = query.Where(filter);
            }

            if (include != null)
            {
                query = include(query);
            }

            TotalRecords = await query.CountAsync();

            if (sorting != null)
            {
                if (sortOrder.Value)
                {
                    query = query.OrderBy(sorting);
                }
                else
                {
                    query = query.OrderByDescending(sorting);
                }
            }

            if (paginationUrlQuery != null)
            {
                query = query.Skip(paginationUrlQuery.PageSize * (paginationUrlQuery.PageNumber - 1))
                        .Take(paginationUrlQuery.PageSize);
            }

            return(await query.ToListAsync());
        }
        public virtual async Task <ActionResult <IEnumerable <WordsDTO> > > Get(
            [FromQuery] string searchString = null,
            [FromQuery] PaginationUrlQuery paginationUrlQuery = null)
        {
            var dtos = await _wordsService.GetFilteredEntitiesAsync(searchString, paginationUrlQuery);

            if (dtos == null)
            {
                return(NotFound());
            }

            var pageInfo = new PageInfo()
            {
                PageNumber   = paginationUrlQuery.PageNumber,
                PageSize     = paginationUrlQuery.PageSize,
                TotalRecords = _wordsService.TotalRecords
            };

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(pageInfo));

            return(Ok(dtos));
        }
示例#7
0
        public async Task <IEnumerable <WordRelsToListDTO> > GetFilteredEntitiesAsync(
            int id,
            string searchingUrlQuery = null,
            PaginationUrlQuery paginationUrlQuery = null)
        {
            Expression <Func <WordRels, bool> > filter = e => true;

            filter = filter.And(e => e.WordId == id);

            if (!string.IsNullOrEmpty(searchingUrlQuery))
            {
                filter = filter.And(e => e.RelWord.Word.Contains(searchingUrlQuery));
            }

            var entities = await _uow.WordRelsRepository.GetRangeAsync(
                include : r => r.Include(e => e.RelWord),
                filter : filter,
                paginationUrlQuery : paginationUrlQuery);

            var dtos = _mapper.Map <List <WordRels>, List <WordRelsToListDTO> >(entities);

            return(dtos);
        }
示例#8
0
 public Task <IEnumerable <WordsDTO> > GetRangeOfEntitiesAsync(PaginationUrlQuery urlQuery = null)
 {
     throw new NotImplementedException();
 }
示例#9
0
 Task <WordRelsDTO> IWordRelsService.GetRangeOfEntitiesAsync(PaginationUrlQuery urlQuery)
 {
     throw new NotImplementedException();
 }
示例#10
0
        public async Task <List <WordRelsToListDTO> > GetEntityByMainWordIdAsync(int id, [FromQuery] PaginationUrlQuery paginationUrlQuery = null)
        {
            var entity = await _uow.WordRelsRepository.GetRangeAsync(
                include : r => r.Include(e => e.RelWord),
                filter : r => r.WordId == id,
                paginationUrlQuery : paginationUrlQuery);

            if (entity == null)
            {
                return(null);
            }

            var dto = _mapper.Map <List <WordRels>, List <WordRelsToListDTO> >(entity);

            return(dto);
        }
示例#11
0
        public virtual async Task <ActionResult <WordRelsToListDTO> > GetByMainWordId(int id, [FromQuery] PaginationUrlQuery paginationUrlQuery = null)
        {
            var dto = await _wordRelsService.GetEntityByMainWordIdAsync(id, paginationUrlQuery);

            if (dto == null)
            {
                return(NotFound());
            }
            var pageInfo = new PageInfo()
            {
                PageNumber   = paginationUrlQuery.PageNumber,
                PageSize     = paginationUrlQuery.PageSize,
                TotalRecords = _wordRelsService.TotalRecords
            };

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(pageInfo));

            return(Ok(dto));
        }