示例#1
0
        public async Task <ProjectBusinessPagedVM> GetProjectBusinessesAsync(int page, int pageSize, string keywords)
        {
            var vm = new ProjectBusinessPagedVM
            {
                PageIndex = page - 1,
                PageSize  = pageSize,
                Keywords  = keywords
            };

            var query = _context.ProjectBusinesses.Include(d => d.Project).Include(d => d.Paymentlogs).AsQueryable();

            if (!string.IsNullOrEmpty(keywords))
            {
                query = query.Where(d => d.Project.Name.Contains(keywords));
            }

            vm.RowCount = await query.CountAsync();

            vm.TotalAmount = await query.SumAsync(d => d.Amount);

            vm.TotalPaymented = await query.SumAsync(d => d.Paymentlogs.Where(p => p.Money > 0).Sum(p => p.Money));

            vm.ProjectBusinesses = await query.OrderByDescending(d => d.Project.CreatedDate)
                                   .Skip(vm.PageIndex * vm.PageSize)
                                   .Take(vm.PageSize)
                                   .ProjectTo <ProjectBusinessVM>(_mapper.ConfigurationProvider).ToListAsync();

            return(vm);
        }
示例#2
0
        public async Task <ProjectBusinessPagedVM> GetListAsync(int page, int pageSize, string keywords, string orderBy, string orderMode)
        {
            var vm = new ProjectBusinessPagedVM
            {
                PageIndex = page - 1,
                PageSize  = pageSize,
                Keywords  = keywords,
                OrderBy   = orderBy,
                OrderMode = orderMode,
            };

            var query   = _db.ProjectBusinesses.Include(d => d.Project).Include(d => d.Paymentlogs).AsQueryable();
            var queryPL = _db.Paymentlogs.Where(d => d.Money > 0).AsQueryable();

            if (!string.IsNullOrEmpty(keywords))
            {
                query   = query.Where(d => d.Project.Name.Contains(keywords));
                queryPL = queryPL.Where(d => d.Project.Name.Contains(keywords));
            }

            if (!string.IsNullOrEmpty(orderBy))
            {
                switch (orderBy)
                {
                case "amount":
                    if (orderMode == "desc")
                    {
                        query = query.OrderByDescending(d => d.Amount);
                    }
                    else
                    {
                        query = query.OrderBy(d => d.Amount);
                    }
                    break;

                case "createdDate":
                    if (orderMode == "desc")
                    {
                        query = query.OrderByDescending(d => d.Project.CreatedDate);
                    }
                    else
                    {
                        query = query.OrderBy(d => d.Project.CreatedDate);
                    }
                    break;

                default:
                    query = query.OrderByDescending(d => d.Project.CreatedDate);
                    break;
                }
            }
            else
            {
                query = query.OrderByDescending(d => d.Project.CreatedDate);
            }

            vm.RowCount = await query.CountAsync();

            vm.TotalAmount = await query.SumAsync(d => d.Amount);

            vm.TotalPaymented = await queryPL.SumAsync(d => d.Money);

            vm.ProjectBusinesses = await query.Skip(vm.PageIndex *vm.PageSize)
                                   .Take(vm.PageSize)
                                   .ProjectTo <ProjectBusinessVM>(_mapper.ConfigurationProvider).ToListAsync();

            return(vm);
        }