示例#1
0
        public IPagedList<OrderQueryModel> Query(IEnumerable<ExtendedQueryParameter> parameters, ICommerceDatabase db, int pageIndex, int pageSize)
        {
            if (pageIndex <= 1)
                pageIndex = 1;

            int num = 10;
            var numPara = parameters.FirstOrDefault(o => o.Name == "Num");
            if (numPara != null && numPara.Value != null && !string.IsNullOrEmpty(numPara.Value.ToString()))
                num = Convert.ToInt32(numPara.Value);
            decimal totalPrice = 100.0m;
            var totalPara = parameters.FirstOrDefault(o => o.Name == "TotalPrice");
            if (totalPara != null && totalPara.Value != null && !string.IsNullOrEmpty(totalPara.Value.ToString()))
                totalPrice = Convert.ToDecimal(totalPara.Value);

            var customerQuery = db.GetRepository<Customer>().Query();
            IQueryable<OrderQueryModel> query = db.GetRepository<Order>().Query()
                .Join(customerQuery,
                           order => order.CustomerId,
                           customer => customer.Id,
                           (order, customer) => new { Order = order, Customer = customer })
                .Select(o => new OrderQueryModel() { Customer = o.Customer, Order = o.Order })
                .Where(o => o.Order.Total > totalPrice)
                .OrderByDescending(o => o.Order.Total);
            var total = query.Count();
            var data = query.Skip(0).Take(num).ToArray();
            return new PagedList<OrderQueryModel>(data, pageIndex, pageSize, total);
        }
示例#2
0
        public IPagedList<CustomerQueryModel> Query(IEnumerable<ExtendedQueryParameter> parameters, ICommerceDatabase db, int pageIndex, int pageSize)
        {
            if (pageIndex <= 1)
                pageIndex = 1;
            int num = 10;
            var numPara = parameters.FirstOrDefault(o => o.Name == "Num");
            if (numPara != null && numPara.Value != null && !string.IsNullOrEmpty(numPara.Value.ToString()))
                num = Convert.ToInt32(numPara.Value);

            var orderQuery = db.GetRepository<Order>().Query();
            IQueryable<CustomerQueryModel> query = db.GetRepository<Customer>().Query()
                .GroupJoin(orderQuery,
                           customer => customer.Id,
                           order => order.CustomerId,
                           (customer, orders) => new { Customer = customer, Orders = orders.Count() })
                .Select(o => new CustomerQueryModel() { Customer = o.Customer, OrdersCount = o.Orders })
                .OrderByDescending(o => o.OrdersCount);
            var total = query.Count();
            var data = query.Skip(0).Take(num).ToArray();
            return new PagedList<CustomerQueryModel>(data, pageIndex, pageSize, total);
        }
        public IPagedList<CustomerQueryModel> Query(IEnumerable<ExtendedQueryParameter> parameters, ICommerceDatabase db, int pageIndex, int pageSize)
        {
            if (pageIndex <= 1)
                pageIndex = 1;

            int days = 7;
            var para = parameters.FirstOrDefault(o => o.Name == "Days");
            if (para != null && para.Value != null)
                days = Convert.ToInt32(para.Value);
            DateTime lastDate = DateTime.Today.AddDays(-1 * days);

            var orderQuery = db.GetRepository<Order>().Query()
                .Where(o => o.CreatedAtUtc > lastDate);
            IQueryable<CustomerQueryModel> query = db.GetRepository<Customer>().Query()
                .GroupJoin(orderQuery,
                           customer => customer.Id,
                           order => order.CustomerId,
                           (customer, orders) => new { Customer = customer, Orders = orders.Count() })
                .Select(o => new CustomerQueryModel() { Customer = o.Customer, OrdersCount = o.Orders })
                .OrderByDescending(o => o.Customer.Id);
            var total = query.Count();
            var data = query.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToArray();
            return new PagedList<CustomerQueryModel>(data, pageIndex, pageSize, total);
        }