Example #1
0
        public async Task <PagedResultDto <TextDto> > GetTextsAsync(SearchTextDto parameters)
        {
            IQueryable <Text> query = _dbContext.Texts
                                      .OrderBy(x => x.Key)
                                      .ThenBy(x => x.Id);

            PagedResultDto <TextDto> result = await PagedResultUtil.ToPagedResult(query, parameters.Page, ToDto);

            return(result);
        }
Example #2
0
        public async void TestPaging()
        {
            TestingContext testingContext = new TestingContext();

            testingContext.AddAdminPrincipalMock();
            testingContext.AddInMemoryDb();
            testingContext.AddLogServiceMock();
            testingContext.AddEnglishCultureServiceMock();

            ApplicationDbContext dbContext = testingContext.GetSimple <ApplicationDbContext>();

            for (int i = 0; i < 13; i++)
            {
                dbContext.Texts.Add(new Text()
                {
                    Key       = $"TestKey{i}",
                    ContentDe = $"ContentDe",
                    ContentEn = $"ContentEn",
                });
            }

            await dbContext.SaveChangesAsync();

            ITextService textService = testingContext.GetService <TextService>();

            //Act
            SearchTextDto dto = new SearchTextDto();

            dto.Page = 0;
            PagedResultDto <TextDto> res = await textService.GetTextsAsync(dto);

            //Assert
            Assert.Equal(13, res.Count);
            Assert.Equal(5, res.Pagesize);
            Assert.Equal(5, res.Data.Count);
            Assert.Equal(3, res.Numpages);

            //Act
            dto      = new SearchTextDto();
            dto.Page = 2;
            res      = await textService.GetTextsAsync(dto);

            //Assert
            Assert.Equal(13, res.Count);
            Assert.Equal(5, res.Pagesize);
            Assert.Equal(3, res.Data.Count);
            Assert.Equal(3, res.Numpages);
        }
Example #3
0
        public IActionResult SearchByText(string text)
        {
            if (!string.IsNullOrEmpty(text))
            {
                var dataResult = _searchService.SearchByText(text);
                if (dataResult.IsSuccessful)
                {
                    var searchTextDto = new SearchTextDto
                    {
                        Channels = _mapper.Map <List <ChannelForListDto> >(dataResult.Data.Item2),
                        Users    = _mapper.Map <List <UserForListDto> >(dataResult.Data.Item1),
                        Text     = text
                    };
                    return(Ok(searchTextDto));
                }

                return(NotFound());
            }

            return(BadRequest());
        }
Example #4
0
 public async Task <PagedResultDto <TextDto> > GetTexts([FromBody] SearchTextDto search)
 {
     return(await _textService.GetTextsAsync(search));
 }