Пример #1
0
        public async Task <int> Count(Customer_CustomerGroupingFilter filter)
        {
            IQueryable <Customer_CustomerGroupingDAO> Customer_CustomerGroupingDAOs = DataContext.Customer_CustomerGrouping;

            Customer_CustomerGroupingDAOs = DynamicFilter(Customer_CustomerGroupingDAOs, filter);
            return(await Customer_CustomerGroupingDAOs.CountAsync());
        }
Пример #2
0
        public async Task <List <Customer_CustomerGrouping> > List(Customer_CustomerGroupingFilter filter)
        {
            if (filter == null)
            {
                return(new List <Customer_CustomerGrouping>());
            }
            IQueryable <Customer_CustomerGroupingDAO> Customer_CustomerGroupingDAOs = DataContext.Customer_CustomerGrouping;

            Customer_CustomerGroupingDAOs = DynamicFilter(Customer_CustomerGroupingDAOs, filter);
            Customer_CustomerGroupingDAOs = DynamicOrder(Customer_CustomerGroupingDAOs, filter);
            var Customer_CustomerGroupings = await DynamicSelect(Customer_CustomerGroupingDAOs, filter);

            return(Customer_CustomerGroupings);
        }
Пример #3
0
        private async Task <List <Customer_CustomerGrouping> > DynamicSelect(IQueryable <Customer_CustomerGroupingDAO> query, Customer_CustomerGroupingFilter filter)
        {
            List <Customer_CustomerGrouping> Customer_CustomerGroupings = await query.Select(q => new Customer_CustomerGrouping()
            {
                CustomerId         = filter.Selects.Contains(Customer_CustomerGroupingSelect.Customer) ? q.CustomerId : default(long),
                CustomerGroupingId = filter.Selects.Contains(Customer_CustomerGroupingSelect.CustomerGrouping) ? q.CustomerGroupingId : default(long),
                Customer           = filter.Selects.Contains(Customer_CustomerGroupingSelect.Customer) && q.Customer != null ? new Customer
                {
                    Id          = q.Customer.Id,
                    Username    = q.Customer.Username,
                    DisplayName = q.Customer.DisplayName,
                    PhoneNumber = q.Customer.PhoneNumber,
                    Email       = q.Customer.Email,
                } : null,
                CustomerGrouping = filter.Selects.Contains(Customer_CustomerGroupingSelect.CustomerGrouping) && q.CustomerGrouping != null ? new CustomerGrouping
                {
                    Id   = q.CustomerGrouping.Id,
                    Name = q.CustomerGrouping.Name,
                } : null,
            }).ToListAsync();

            return(Customer_CustomerGroupings);
        }
Пример #4
0
        private IQueryable <Customer_CustomerGroupingDAO> DynamicOrder(IQueryable <Customer_CustomerGroupingDAO> query, Customer_CustomerGroupingFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case Customer_CustomerGroupingOrder.Customer:
                    query = query.OrderBy(q => q.Customer.Id);
                    break;

                case Customer_CustomerGroupingOrder.CustomerGrouping:
                    query = query.OrderBy(q => q.CustomerGrouping.Id);
                    break;
                }
                break;

            case OrderType.DESC:
                switch (filter.OrderBy)
                {
                case Customer_CustomerGroupingOrder.Customer:
                    query = query.OrderByDescending(q => q.Customer.Id);
                    break;

                case Customer_CustomerGroupingOrder.CustomerGrouping:
                    query = query.OrderByDescending(q => q.CustomerGrouping.Id);
                    break;
                }
                break;
            }
            query = query.Skip(filter.Skip).Take(filter.Take);
            return(query);
        }
Пример #5
0
        private IQueryable <Customer_CustomerGroupingDAO> DynamicFilter(IQueryable <Customer_CustomerGroupingDAO> query, Customer_CustomerGroupingFilter filter)
        {
            if (filter == null)
            {
                return(query.Where(q => false));
            }

            if (filter.CustomerId != null)
            {
                query = query.Where(q => q.CustomerId, filter.CustomerId);
            }
            if (filter.CustomerGroupingId != null)
            {
                query = query.Where(q => q.CustomerGroupingId, filter.CustomerGroupingId);
            }
            return(query);
        }