public Task <IQueryable <News> > Handle(GetNewsQuery request, CancellationToken cancellationToken) { var News = _newsRepository .FindBy(n => n is News, n => n.Category, n => n.Subcategory, n => n.NewsStructure) .Where(n => string.IsNullOrEmpty(request.CategoryName) ? (string.IsNullOrEmpty(request.SubcategoryName) || n.Subcategory != null && n.Subcategory.Name.Contains(request.SubcategoryName)) : n.Category.Name.Contains(request.CategoryName)) .Where(n => request.Rate == null || n.Reputation.Equals(request.Rate)); return(Task.FromResult(News)); }
public async Task <Page <NewsView> > Handle(GetNewsQuery query, CancellationToken cancellationToken) { var result = await _db.QueryMultipleAsync( new CommandDefinition( commandText : Entity.NewsDto.Sql, parameters : new { OrganisationId = query.OrganisationId, PetId = query.PetId, Tag = String.IsNullOrEmpty(query.Tag) ? null : $"%{query.Tag}%", Limit = query.Limit, Offset = query.Offset, NewsId = query.NewsId, }, commandType : CommandType.Text, cancellationToken : cancellationToken )); if (result is null) { return new Page <NewsView> { Limit = query.Limit, Offset = query.Offset, Total = 0, } } ; return(new Page <NewsView> { Limit = query.Limit, Offset = query.Offset, Total = await result.ReadSingleAsync <Int64>(), Items = (await result.ReadAsync <Entity.NewsDto>()).Select(_ => new NewsView( id: _.Id, title: _.Title, imgLink: _.ImgLink, mdShortBody: _.MdShortBody, mdBody: _.MdBody, createDate: _.CreateDate, linkedPets: _.LinkedPets?.TryParseJson <List <LinkedPetsDto> >() .Select(lp => new LinkedPetsView(lp.Id, lp.Name)).ToList() ?? new List <LinkedPetsView>(), tags: _.Tags?.TryParseJson <List <String> >() ?? new List <String>() )) }); }