示例#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
        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
 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);
 }