public async Task <ActionResult <RecordsPageDto> > GetRecordsList(
            [FromQuery] DateTime?from,
            [FromQuery] DateTime?to,
            [FromQuery] string?name,
            [FromQuery] bool?combinedThemes,
            [FromQuery] Guid[]?themeId,
            [FromQuery] int?pageSize,
            [FromQuery] int?pageNo)
        {
            try
            {
                pageSize ??= 20;
                pageSize = pageSize > 100 ? 100 : pageSize;
                pageNo ??= 0;

                var filters = new RecordsFilter
                {
                    CombineThemes = combinedThemes ?? false,
                    PageSize      = pageSize.Value,
                    PageNo        = pageNo.Value,
                    FromDate      = from.HasValue ? DateOnly.FromDateTime(from.Value) : null,
                    ToDate        = to.HasValue ? DateOnly.FromDateTime(to.Value) : null,
                    FilterName    = name
                };

                if (themeId != null && themeId.Length > 0)
                {
                    filters.AddThemeId(themeId);
                }

                var records = await _recordsSearchService.GetRecordsList(filters);

                int allCount = await _recordsSearchService.GetRecordsCount(filters);

                var pagesInfo = PagesInfo.GetPagesInfo(allCount, pageNo.Value, pageSize.Value);

                var dto = new RecordsPageDto
                {
                    PagesInfo = pagesInfo,
                    Records   = records.Select(r => new RecordListItemDto
                    {
                        Date          = r.Date,
                        CreatedDate   = r.CreateDate,
                        ModifiedDate  = r.ModifyDate,
                        DisplayedName = r.GetRecordNameDisplay(),
                        DisplayedText = r.GetRecordTextShort(),
                        RecordId      = r.Id
                    }).ToList()
                };

                return(Ok(dto));
            }
            catch (ArgumentException exc)
            {
                return(BadRequest(exc.Message));
            }
        }
示例#2
0
        public async Task <ActionResult <RecordsPageDto> > GetRecordsList(
            [FromQuery] string?searchText,
            [FromQuery] int?pageSize,
            [FromQuery] int?pageNo)
        {
            try
            {
                pageSize ??= 20;
                pageSize = pageSize > 100 ? 100 : pageSize;
                pageNo ??= 0;

                var filters = new RecordsTextFilter
                {
                    SearchText = searchText,
                    PageNo     = pageNo.Value,
                    PageSize   = pageSize.Value
                };

                var records = await _recordsSearchService.GetRecordsList(filters);

                int allCount = await _recordsSearchService.GetRecordsCount(filters.SearchText);

                var pagesInfo = PagesInfo.GetPagesInfo(allCount, pageNo.Value, pageSize.Value);

                var dto = new RecordsPageDto
                {
                    PagesInfo = pagesInfo,
                    Records   = records.Select(r => new RecordListItemDto
                    {
                        Date          = r.Date,
                        CreatedDate   = r.CreateDate,
                        ModifiedDate  = r.ModifyDate,
                        DisplayedName = r.GetRecordNameDisplay(),
                        DisplayedText = r.GetRecordTextShort(),
                        RecordId      = r.Id
                    }).ToList()
                };

                return(Ok(dto));
            }
            catch (ArgumentException exc)
            {
                return(BadRequest(exc.Message));
            }
        }