예제 #1
0
        public async Task <JqDataTableResponse <InvoiceListItemDto> > GetPagedResultAsync(InvoiceJqDataTableRequestModel model)
        {
            if (model.Length == 0)
            {
                model.Length = Constants.DefaultPageSize;
            }

            var linqstmt = (from i in _dataContext.Invoices
                            join c in _dataContext.Customers
                            on i.CustomerId equals c.Id
                            where (model.CustomerId == null ||
                                   i.CustomerId == model.CustomerId.Value) &&
                            (model.FilterKey == null ||
                             EF.Functions.Like(c.FirstName, "%" + model.FilterKey + "%") ||
                             EF.Functions.Like(c.MiddleName, "%" + model.FilterKey + "%") ||
                             EF.Functions.Like(c.LastName, "%" + model.FilterKey + "%") ||
                             EF.Functions.Like(i.InvoiceNumber, "%" + model.FilterKey + "%")) &&
                            i.Status != Constants.InvoiceStatus.Deleted
                            select new InvoiceListItemDto
            {
                Id = i.Id,
                CustomerId = i.CustomerId,
                CustomerName = (c.FirstName ?? "") + " " + (c.MiddleName ?? "") + " " + (c.LastName ?? ""),
                Description = i.Remark,
                Amount = i.Services.Sum(x => x.Rate),
                Discount = i.Discount,
                Tax = i.Tax,
                TotalAmount = i.TotalAmount,
                CreatedOn = i.CreatedOn,
                Status = i.Status,
                InvoiceNumber = i.InvoiceNumber,
                SubTotal = i.SubTotal
            })
                           .AsNoTracking();

            var sortExpresstion = model.GetSortExpression();

            var pagedResult = new JqDataTableResponse <InvoiceListItemDto>
            {
                RecordsTotal    = await _dataContext.Invoices.CountAsync(x => x.Status != Constants.InvoiceStatus.Deleted),
                RecordsFiltered = await linqstmt.CountAsync(),
                Data            = await linqstmt.OrderBy(sortExpresstion).Skip(model.Start).Take(model.Length).ToListAsync()
            };

            foreach (var invoiceListItemDto in pagedResult.Data)
            {
                invoiceListItemDto.CreatedOn = Utility.GetDateTime(invoiceListItemDto.CreatedOn, null);
            }

            return(pagedResult);
        }
        public async Task <JqDataTableResponse <InvoicePaymentListItemDto> > GetPagedResultAsync(InvoiceJqDataTableRequestModel model)
        {
            if (model.Length == 0)
            {
                model.Length = Constants.DefaultPageSize;
            }

            var linqstmt = (from ip in _dataContext.InvoicePayments
                            join i in _dataContext.Invoices
                            on ip.InvoiceId equals i.Id
                            join c in _dataContext.Customers
                            on i.CustomerId equals c.Id
                            where (model.CustomerId == null ||
                                   i.CustomerId == model.CustomerId.Value) &&
                            (model.FilterKey == null ||
                             EF.Functions.Like(i.Id.ToString(), "%" + model.FilterKey + "%") ||
                             EF.Functions.Like(c.FirstName, "%" + model.FilterKey + "%") ||
                             EF.Functions.Like(c.LastName, "%" + model.FilterKey + "%")) &&
                            i.Status != Constants.InvoiceStatus.Deleted
                            select new InvoicePaymentListItemDto
            {
                Id = ip.Id,
                InvoiceNumber = ip.Invoice.Id.ToString(),
                FirstName = c.FirstName,
                MiddleName = c.MiddleName,
                LastName = c.LastName,
                DepositFrom = ip.DepositFrom,
                DepositTo = ip.BankAccount.AccountNumber,
                PaymentMode = ip.PaymentMode,
                Amount = ip.Amount,
                CreatedOn = ip.CreatedOn
            })
                           .AsNoTracking();

            var sortExpression = model.GetSortExpression();

            var pageResult = new JqDataTableResponse <InvoicePaymentListItemDto>
            {
                RecordsTotal    = await _dataContext.InvoicePayments.CountAsync(x => x.Status != Constants.RecordStatus.Deleted),
                RecordsFiltered = await linqstmt.CountAsync(),
                Data            = await linqstmt.OrderBy(sortExpression).ToListAsync()
            };

            return(pageResult);
        }