public static ExpressionStarter <Purchase> GetPredicate(this QPurchase query) { var predicate = PredicateBuilder.New <Purchase>(true); if (query.FormateId > 0) { predicate = predicate.And(o => o.FormateId == query.FormateId); } else { if (query.DeviceId > 0) { predicate = predicate.And(o => o.DeviceId == query.DeviceId); } if (query.VandorId > 0) { predicate = predicate.And(o => o.VandorId == query.VandorId); } } if (!string.IsNullOrEmpty(query.ApplyNumber)) { predicate = predicate.And(o => o.ApplyNumber.Contains(query.ApplyNumber)); } if (!string.IsNullOrEmpty(query.Remark)) { predicate = predicate.And(o => o.Remark.Contains(query.Remark)); } if (query.ApplyDateRange != null && query.ApplyDateRange.Count == 2) { predicate = predicate.And(o => o.ApplyDate >= query.ApplyDateRange.Min().Date&& o.ApplyDate < query.ApplyDateRange.Max().Date.AddDays(1)); } if (query.PurchaseDateRange != null && query.PurchaseDateRange.Count == 2) { predicate = predicate.And(o => o.PurchaseDate >= query.PurchaseDateRange.Min().Date&& o.PurchaseDate < query.PurchaseDateRange.Max().Date.AddDays(1)); } if (query.TotalMax != 1000) { predicate = predicate.And(o => o.PurchasePrice * o.Quantity <= query.TotalMax); } if (query.TotalMin > 0) { predicate = predicate.And(o => o.PurchasePrice * o.Quantity >= query.TotalMin); } if (query.Quantity > 0) { predicate = predicate.And(o => o.Quantity == query.Quantity); } return(predicate); }
public async Task <PagedResult <PTCStore.RanderModels.RPurchase> > Purchases(PTCStore.QueryModels.QPurchase query, int page, int pageSize = 10) { var rs = _context.Purchases //.Include(o => o.Barcodes) //.Include(o => o.Formate).ThenInclude(o => o.VandorDevice).ThenInclude(o => o.Device) //.Include(o => o.Formate).ThenInclude(o => o.VandorDevice).ThenInclude(o => o.Vandor) .Where(query.GetPredicate()).Select(o => new RPurchase { ApplyDate = o.ApplyDate, ApplyNumber = o.ApplyNumber, Remark = o.Remark, Barcodes = o.Barcodes, DeviceId = o.DeviceId, VandorId = o.VandorId, FormateId = o.FormateId, Formate = o.Formate, FormateName = o.Formate.Name, VandorName = o.Formate.VandorDevice.Vandor.Name, DeviceName = o.Formate.VandorDevice.Device.Name, PurchaseDate = o.PurchaseDate, PurchaseId = o.PurchaseId, CreateDate = o.CreateDate, CreateId = o.CreateId, PurchasePrice = o.PurchasePrice, Quantity = o.Quantity, SalePrice = o.SalePrice, UpDateId = o.UpDateId, UpDateDate = o.UpDateDate, TotalPrice = o.Quantity * o.PurchasePrice, });; //var gg = rs.ToList<PTCStore.RanderModels.RPurchase>(); return(await rs.GetPagedAsync(pageSize, page, query.Sort)); }