Beispiel #1
0
        public async Task <PaginatedListResult <InfoChannelMessage> > Search(InfoChannelMessagesRequestViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException(nameof(viewModel));
            }

            var query = BaseQuery();

            query = SearchFilter(query, viewModel);
            query = SearchSort(query, viewModel);

            return(await query.ToPaginatedListResultAsync(viewModel));
        }
        public async Task <ServiceResult <PaginatedListResult <InfoChannelMessagesResponseViewModel> > > Search(InfoChannelMessagesRequestViewModel viewModel)
        {
            var paginatedListWithModel = await _repository.Search(viewModel);

            // Mapping
            List <InfoChannelMessagesResponseViewModel> Mapping(List <InfoChannelMessage> list)
            {
                return(list?
                       .Select(model => new InfoChannelMessagesResponseViewModel
                {
                    Id = model.Id,
                    Subject = model.Title,
                    Message = model.Message,
                    Date = model.VisibleUntil,
                    IsVisible = model.Visible
                })
                       .ToList());
            }

            var paginatedListWithViewModel = paginatedListWithModel.Copy(Mapping);

            return(ServiceResultFactory.Success(paginatedListWithViewModel));
        }
Beispiel #3
0
        protected IQueryable <InfoChannelMessage> SearchSort(IQueryable <InfoChannelMessage> query, InfoChannelMessagesRequestViewModel viewModel)
        {
            string sortName = viewModel.SortName?.ToUpper();

            if (sortName == InfoChannelMessagesRequestViewModel.OrderFields.Subject)
            {
                query = query.OrderUsingSearchOptions(viewModel, x => x.Title);
            }
            else if (sortName == InfoChannelMessagesRequestViewModel.OrderFields.Message)
            {
                query = query.OrderUsingSearchOptions(viewModel, x => x.Message);
            }
            else if (sortName == InfoChannelMessagesRequestViewModel.OrderFields.Date)
            {
                query = query.OrderUsingSearchOptions(viewModel, x => x.UpdatedOn);
            }
            else if (sortName == InfoChannelMessagesRequestViewModel.OrderFields.IsVisible)
            {
                query = query.OrderUsingSearchOptions(viewModel, x => x.Visible);
            }
            else
            {
                query = query.OrderBy(x => x.Id);
            }
            return(query);
        }
Beispiel #4
0
 protected IQueryable <InfoChannelMessage> SearchFilter(IQueryable <InfoChannelMessage> query, InfoChannelMessagesRequestViewModel viewModel)
 {
     return(query);
 }
Beispiel #5
0
 public async Task <IActionResult> Search([FromQuery] InfoChannelMessagesRequestViewModel viewModel)
 => await HandleResultAsync(() => _service.Search(viewModel));