Beispiel #1
0
        public async Task <int> CountAllAsync(
            PaginationFilter pagination,
            GetAllAddressesFilter filter = null
            )
        {
            var queryable = _context.Addresses.AsQueryable();

            queryable = queryable.Where(x => x.IsDeleted == false);
            queryable = AddFilterOnQuery(filter, queryable);
            return(await queryable.CountAsync());
        }
Beispiel #2
0
        private IQueryable <Address> AddFilterOnQuery(
            GetAllAddressesFilter filter,
            IQueryable <Address> queryable
            )
        {
            queryable = queryable.Where(x => x.IsDeleted == false);

            if (!string.IsNullOrEmpty(filter?.City))
            {
                queryable = queryable.Where(x => x.City.Contains(filter.City));
            }

            if (!string.IsNullOrEmpty(filter?.District))
            {
                queryable = queryable.Where(x => x.District.Contains(filter.District));
            }

            if (!string.IsNullOrEmpty(filter?.Ward))
            {
                queryable = queryable.Where(x => x.Ward.Contains(filter.Ward));
            }

            if (!string.IsNullOrEmpty(filter?.StreetLocation))
            {
                queryable = queryable.Where(x => x.StreetLocation.Contains(filter.StreetLocation));
            }

            if (!string.IsNullOrEmpty(filter?.Name))
            {
                queryable = queryable.Where(x => x.Name.Contains(filter.Name));
            }

            if (!string.IsNullOrEmpty(filter?.Phone))
            {
                queryable = queryable.Where(x => x.Phone.Contains(filter.Phone));
            }

            if (filter?.CustomerId > 0)
            {
                queryable = queryable.Where(x => x.CustomerId == filter.CustomerId);
            }

            return(queryable);
        }
Beispiel #3
0
        public async Task <IEnumerable <Address> > GetAllAsync(
            int userId,
            PaginationFilter pagination,
            GetAllAddressesFilter filter = null
            )
        {
            var customer = await _context.Customers.SingleOrDefaultAsync(c => c.UserId == userId);

            var queryable = _context.Addresses.AsQueryable();

            queryable = AddFilterOnQuery(filter, queryable);

            var skip = (pagination.PageNumber - 1) * pagination.PageSize;

            return(await queryable
                   .Where(c => c.CustomerId == customer.Id)
                   .Skip(skip)
                   .Take(pagination.PageSize)
                   .ToListAsync());
        }