Пример #1
0
        public async Task <TableData <UserCabinetDto> > GetUsers(TablePoliceParams tableParams)
        {
            TableData <UserCabinetDto> tableData = new TableData <UserCabinetDto>();
            IQueryable <User>          records   = _userManager.Users;

            if (!string.IsNullOrEmpty(tableParams.SortField) && tableParams.SortOrder != 0)
            {
                if (tableParams.SortField.Equals("firstName") && tableParams.SortOrder == 1)
                {
                    records = records.OrderBy(u => u.FirstName);
                }
                if (tableParams.SortField.Equals("firstName") && tableParams.SortOrder == -1)
                {
                    records = records.OrderByDescending(u => u.FirstName);
                }
            }

            if (tableParams.Filters.Any())
            {
                records = PrepareFilter(records, tableParams);
            }

            tableData.Count = await records.CountAsync();

            if (tableParams.Rows != 0)
            {
                records = records.Skip(tableParams.First).Take(tableParams.Rows);
            }

            tableData.Data = _mapper.Map <List <User>, List <UserCabinetDto> >(await records.ToListAsync());

            return(tableData);;
        }
Пример #2
0
        private IQueryable <User> PrepareFilter(IQueryable <User> records, TablePoliceParams tableParams)
        {
            foreach (TableFilterItem filter in tableParams.Filters)
            {
                if (string.Equals(filter.Field, "firstName", StringComparison.OrdinalIgnoreCase))
                {
                    records = records.Where(x => x.FirstName.Contains(filter.Value));
                }
                if (string.Equals(filter.Field, "lastName", StringComparison.OrdinalIgnoreCase))
                {
                    records = records.Where(x => x.LastName.Contains(filter.Value));
                }
                if (string.Equals(filter.Field, "email", StringComparison.OrdinalIgnoreCase))
                {
                    records = records.Where(x => x.Email.Contains(filter.Value));
                }
                if (string.Equals(filter.Field, "dateRange", StringComparison.OrdinalIgnoreCase))
                {
                    IEnumerable <DateTime> dates = filter.Value.Split('-', StringSplitOptions.RemoveEmptyEntries)
                                                   .Select(x => DateTime.Parse(x));

                    records = records.Where(x => x.BirthDate > dates.First() && x.BirthDate < dates.Last());
                }
                if (string.Equals(filter.Field, "phoneNumber", StringComparison.OrdinalIgnoreCase))
                {
                    records = records.Where(x => x.PhoneNumber.Contains(filter.Value));
                }
            }

            return(records);
        }
Пример #3
0
        public async Task <TableData <ViolationViewDto> > GetUserViolations(TablePoliceParams tableParams, string userId)
        {
            CountUserViolationSpecification      countSpec = new CountUserViolationSpecification(userId);
            UserViolationWithOrdersSpecification dataSpec  = new UserViolationWithOrdersSpecification(tableParams, userId);

            int countData = await _violationRepository.CountAsync(countSpec);

            IReadOnlyList <Violation> violations = await _violationRepository.ListAsync(dataSpec);

            IReadOnlyList <ViolationViewDto> data = _mapper.Map <IReadOnlyList <Violation>, IReadOnlyList <ViolationViewDto> >(violations);

            return(new TableData <ViolationViewDto> {
                Data = data, Count = countData
            });
        }
Пример #4
0
 public async Task <TableData <ViolationViewDto> > GetUserViolations(TablePoliceParams tableParams, string userId)
 {
     return(await _policePresentation.GetUserViolations(tableParams, userId));
 }
Пример #5
0
 public async Task <ActionResult <TableData <UserCabinetDto> > > GetUsers(TablePoliceParams tableParams)
 {
     return(await _policePresentation.GetUsers(tableParams));;
 }