public SearchResult <PumpSearchModel> SearchPump(PumpCriteria criteria)
        {
            var userInfo = SessionData.Get <UserInfo>("UserInfo");

            if (userInfo == null)
            {
                throw new UnauthorizedException();
            }
            var userId       = userInfo.Id;
            var canAccessAll = authorizationService.CheckPermission(OperationCodes.ControlPump_Access);

            var principals = userGroupRepository.GetAllMember().Where(t => t.UserId == userId && t.UserGroup.IsActive == true)
                             .Select(t => t.UserGroupId).ToList();

            principals.Add(userId);
            var query = pumpRepository.GetAllAccessRight().Include(t => t.Pump).Where(t => (principals.Contains(t.Principal) && t.Access == true) || canAccessAll == true)
                        .Select(t => t.Pump);
            var result = new SearchResult <PumpSearchModel>();

            result.ItemCount  = query.Count();
            query             = query.Sort(criteria.Sorting, new Sorting("Name", SortDirection.Ascending));
            query             = query.Page(criteria.Paging);
            result.ResultData = query.Select(pumpToSearchModel).ToList();
            return(result);
        }
예제 #2
0
        public SearchResult <PumpSearchModel> SearchPump(PumpCriteria criteria)
        {
            var result = new SearchResult <PumpSearchModel>();
            var query  = pumpRepository.GetAll().Include(t => t.Location).Include(t => t.Location.Province).Where(FilterPump(criteria));

            result.ItemCount  = query.Count();
            query             = query.Sort(criteria.Sorting, new Sorting("Name", SortDirection.Ascending));
            query             = query.Page(criteria.Paging);
            result.ResultData = query.Select(pumpToSearchModel).ToList();
            return(result);
        }
예제 #3
0
        private Expression <Func <Pump, bool> > FilterPump(PumpCriteria criteria)
        {
            Expression <Func <Pump, 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);
            }
            if (criteria.IsLock.HasValue)
            {
                result = result.And(t => t.IsLock == criteria.IsLock);
            }
            if (criteria.ProvinceId.HasValue)
            {
                result = result.And(t => t.Location.ProvinceId == criteria.ProvinceId);
            }

            return(result);
        }
        public IActionResult SearchPump(PumpCriteria criteria)
        {
            var result = controlPumpService.SearchPump(criteria);

            return(Ok(new SuccessResult(result)));
        }
        public IActionResult SearchPump([FromQuery] PumpCriteria criteria)
        {
            var result = pumpService.SearchPump(criteria);

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