示例#1
0
        public SearchResult <ConnectionModel> SearchConnection(ConnectionCriteria criteria)
        {
            var result = new SearchResult <ConnectionModel>();
            var query  = connectionRepository.GetAll().Where(FilterConnection(criteria));

            result.ItemCount  = query.Count();
            query             = query.Sort(criteria.Sorting, new Sorting("Name", SortDirection.Ascending));
            query             = query.Page(criteria.Paging);
            result.ResultData = query.Select(connectionToModel).ToList();
            return(result);
        }
示例#2
0
        private Expression <Func <Connection, bool> > FilterConnection(ConnectionCriteria criteria)
        {
            Expression <Func <Connection, bool> > result = t => true;

            if (!string.IsNullOrWhiteSpace(criteria.Keyword))
            {
                result = result.And(t => EF.Functions.Like(t.Name, $"%{criteria.Keyword}%") || EF.Functions.Like(t.Description, $"%{criteria.Keyword}%"));
            }
            if (criteria.IsActive.HasValue)
            {
                result = result.And(t => t.IsActive == criteria.IsActive);
            }
            return(result);
        }
        public IActionResult SearchConnection([FromQuery] ConnectionCriteria criteria)
        {
            var result = connectionService.SearchConnection(criteria);

            return(Ok(new SuccessResult(result)));
        }