コード例 #1
0
        public PagedResult <BillViewModel> GetAllPaging(string startDate, string endDate, string keyword
                                                        , int pageIndex, int pageSize)
        {
            var query = _orderRepository.FindAll();

            if (!string.IsNullOrEmpty(startDate))
            {
                DateTime start = DateTime.ParseExact(startDate, "dd/MM/yyyy", CultureInfo.GetCultureInfo("vi-VN"));
                query = query.Where(x => x.DateCreated >= start);
            }
            if (!string.IsNullOrEmpty(endDate))
            {
                DateTime end = DateTime.ParseExact(endDate, "dd/MM/yyyy", CultureInfo.GetCultureInfo("vi-VN"));
                query = query.Where(x => x.DateCreated <= end);
            }
            if (!string.IsNullOrEmpty(keyword))
            {
                query = query.Where(x => x.CustomerName.Contains(keyword) || x.CustomerMobile.Contains(keyword));
            }
            var totalRow = query.Count();
            var data     = query.OrderByDescending(x => x.DateCreated)
                           .Skip((pageIndex - 1) * pageSize)
                           .Take(pageSize)
                           .ProjectTo <BillViewModel>()
                           .ToList();

            return(new PagedResult <BillViewModel>()
            {
                CurrentPage = pageIndex,
                PageSize = pageSize,
                Results = data,
                RowCount = totalRow
            });
        }
コード例 #2
0
ファイル: BillService.cs プロジェクト: bvnty1998/ASP.Net-Core
        public BillViewModel FindBillById(int id)
        {
            var bill = _billRepository.FindAll(x => x.Id == id).ProjectTo <BillViewModel>().SingleOrDefault();

            return(bill);
        }
コード例 #3
0
        public async Task <IEnumerable <BillViewModel> > GetOrdersByCustomer(Guid customerId)
        {
            var data = await _orderRepository.FindAll(x => x.CustomerId == customerId, c => c.BillDetails);

            return(new BillViewModel().Map(data));
        }
コード例 #4
0
        public PageResult <BillViewModel> GetAllBillPaging(int?option, DateTime fromDate, DateTime toDate, string keyword, int page, int pageSize)
        {
            var billModels = _billRepository.FindAll();

            if (fromDate != DateTime.MinValue & toDate != default(DateTime)) // sort by date time picker
            {
                billModels = billModels.Where(x => fromDate < x.CreatedDate && x.CreatedDate < toDate);
            }

            if (!string.IsNullOrEmpty(keyword)) // sort by keyword
            {
                billModels = billModels.Where(x => x.CustomerName.Contains(keyword) ||
                                              x.Id.ToString().Contains(keyword));
            }

            if (option.HasValue && keyword == null) // sort by Bill status
            {
                billModels = billModels.Where(x => x.BillStatus == (BillStatus)option);
            }

            if (option == null && fromDate == DateTime.MinValue) // this sort for all conditions == null
            {
                billModels = billModels.OrderByDescending(x => x.CreatedDate);
            }

            var total = billModels.Count();

            billModels = billModels.Skip((page - 1) * pageSize).Take(pageSize);

            var pageResult = new PageResult <BillViewModel>()
            {
                CurentPage = page,
                Results    = Mapper.Map <List <Bill>, List <BillViewModel> >(billModels.ToList()),
                PageSize   = pageSize,
                RowCount   = total,
            };

            return(pageResult);
        }
コード例 #5
0
ファイル: BillService.cs プロジェクト: war-man/KLTN
 public async Task<IEnumerable<BillViewModel>> GetOrdersByCustomer(Guid customerId)
 {
     var data = (await _orderRepository.FindAll(x => x.CustomerId == customerId, c => c.BillDetails)).AsParallel().WithExecutionMode(ParallelExecutionMode.ForceParallelism);
     return new BillViewModel().Map(data);
 }