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 OnGetAsync(
            DateTime?fromDate,
            DateTime?toDate,
            Guid[] themes,
            string?filterName,
            bool?combineThemes,
            int?pageNo)
        {
            CombineThemes = combineThemes ?? false;

            Filters = new RecordsFilter
            {
                PageSize      = _pageSize,
                FromDate      = fromDate == null ? null : DateOnly.FromDateTime(fromDate.Value),
                ToDate        = toDate == null ? null : DateOnly.FromDateTime(toDate.Value),
                FilterName    = filterName?.Trim(),
                PageNo        = (pageNo ?? 1) - 1,
                CombineThemes = CombineThemes
            };

            if (themes != null && themes.Length > 0)
            {
                Filters.AddThemeId(themes);
                SelectedThemes = themes;
            }

            var recordsCount = await _searchRecordsService.GetRecordsCount(Filters);

            Pages   = PagesInfo.GetPagesInfo(recordsCount, Filters.PageNo + 1, _pageSize, 10);
            Records = await _searchRecordsService.GetRecordsList(Filters);

            AllScopes = await _scopesSvc.GetScopes();
        }