Beispiel #1
0
        public CollectionResult <UserDto> GetCustomers(UsersFilterParams filterParams)
        {
            var items = _unitOfWork.UserRepository.GetCustomers(filterParams);

            var result = new CollectionResult <UserDto>
            {
                TotalCount = items.TotalCount,
                Collection = AutoMapper.Mapper.Map <IEnumerable <User>, List <UserDto> >(items.Collection)
            };

            return(result);
        }
Beispiel #2
0
        public async Task <PaginatedList <GetUserDTO> > GetAllAsync(UsersFilterParams arg)
        {
            try
            {
                IQueryable <User> query = db.Users;

                if (arg.GeneralName != null)
                {
                    query = query.Where(w => w.UserName.StartsWith(arg.GeneralName) ||
                                        w.Email.StartsWith(arg.GeneralName) ||
                                        w.PhoneNumber.StartsWith(arg.GeneralName) ||
                                        w.FullName.Contains(arg.GeneralName));
                }

                if (arg.GroupId != 0)
                {
                    query = query.Where(w => w.Groups.Any(a => a.GroupId == arg.GroupId));
                }

                if (arg.IssueUrlId != 0)
                {
                    query = query.Where(w => w.IssueUrls.Any(a => a.IssueUrlId == arg.IssueUrlId));
                }

                if (arg.CustomerOrganizationId != 0)
                {
                    query = query.Where(w => w.CustomerOrganizationId == arg.CustomerOrganizationId);
                }

                if (arg.PostId != 0)
                {
                    query = query.Where(w => w.PostId == arg.PostId);
                }

                if (arg.IsCompanyMember != null)
                {
                    query = query.Where(w => w.IsCompanyMember == arg.IsCompanyMember);
                }

                var list = await new PaginatedListBuilder <User, GetUserDTO>(mapper)
                           .CreateAsync(query, arg.PageNumber, arg.PageSize);

                return(list);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Beispiel #3
0
        public async Task <ApiResponse> Get([FromQuery] UsersFilterParams arg)
        {
            try
            {
                var users = await userService.GetAllAsync(arg);

                return(new ApiResponse(users, HttpStatusCode.OK.ToInt()));
            }
            catch (CustomException ex)
            {
                throw new ApiException(ex, ex.StatusCode);
            }
            catch (Exception ex)
            {
                throw new ApiException(ex);
            }
        }
Beispiel #4
0
        private void FillUsersQueryParams(UsersFilterParams filterParams)
        {
            var predicate = PredicateBuilder.New <User>(true);

            if (!string.IsNullOrEmpty(filterParams.Term))
            {
                predicate = predicate.And(t => t.LastName.Contains(filterParams.Term) || t.FirstName.Contains(filterParams.Term));
            }

            if (filterParams.FacilityId.HasValue)
            {
                predicate = predicate.And(t => t.FacilityId == filterParams.FacilityId.Value);
            }

            if (filterParams.OnlyWithFacility)
            {
                predicate = predicate.And(t => t.FacilityId.HasValue);
            }

            filterParams.Expression = predicate;
        }
Beispiel #5
0
        public CollectionResult <User> GetCustomers(UsersFilterParams filterParams)
        {
            var users = GetAllUsers();

            FillUsersQueryParams(filterParams);

            users = users.Where(filterParams.Expression);

            var totalCount = users.Count();

            var result = users
                         .Skip(filterParams.Skip)
                         .Take(filterParams.Take)
                         .AsNoTracking()
                         .ToList();

            var userResult = new CollectionResult <User>
            {
                Collection = result,
                TotalCount = totalCount
            };

            return(userResult);
        }
Beispiel #6
0
        public IActionResult GetUsers([FromBody] UsersFilterParams filterParams)
        {
            var users = _customerService.GetCustomers(filterParams);

            return(Json(JsonResultData.Success(users)));
        }