public async Task <PagedQueryResult <PointQueryResult> > GetAsync(GetPagedResourceQuery resource) { try { async Task <PagedQueryResult <PointQueryResult> > SearchInDataBaseAsync() { var result = await _mongoContext.GetCollection <Point>(MongoCollections.Point) .AsQueryable() .Where(p => p.Active) .Search(p => p.Name.ToLower().Contains(resource.Search.ToLower()), resource.Search) .OrderByDescending(p => p.CreatedAt) .Select(p => new PointQueryResult { Id = p.Id, Name = p.Name }) .GetPagedAsync(resource); return(result); } return(await GetFromCacheIfExist(resource.ToCacheKey(CacheKeys.Routes), SearchInDataBaseAsync)); } catch (Exception ex) { throw new UserFriendlyException("Error to get connections", ex); } }
public async Task <PagedQueryResult <ConnectionQueryResult> > GetAsync(GetPagedResourceQuery resource) { try { async Task <PagedQueryResult <ConnectionQueryResult> > SearchInDataBaseAsync() { var search = resource.Search.ToLower(); return(await _mongoContext.GetCollection <Connection>(MongoCollections.Connection) .AsQueryable() .Where(x => x.Active) .Search(x => x.Origin.Name.ToLower().Contains(search) || x.Destination.Name.ToLower().Contains(search), search) .OrderByDescending(p => p.CreatedAt) .Select(x => new ConnectionQueryResult { Id = x.Id, Cost = x.Cost, Time = x.Time, Origin = new PointQueryResult { Id = x.Origin.Id, Name = x.Origin.Name }, Destination = new PointQueryResult { Id = x.Destination.Id, Name = x.Destination.Name } }).GetPagedAsync(resource)); } return(await GetFromCacheIfExist(resource.ToCacheKey(CacheKeys.Connections), SearchInDataBaseAsync)); } catch (Exception ex) { throw new UserFriendlyException("Error to get connection paged", ex); } }