public CombinationChargeData SearchChargesByMengzhu(PayType[] payTypes, ChargeMode[] chargeModes, DateTime startTime, DateTime endTime , bool isTimeRangeRequired, long lastId) { var result = new CombinationChargeData(); using (var db = DbContextFactory.CreateDbContext()) { IQueryable<Charge> charges = db.Charges.Include(a => a.TargetXiake).Include(a=>a.Handler).OrderByDescending(a => a.Id); if (lastId != 0) { charges = charges.Where(a => a.Id < lastId); } charges = charges.Where(a => payTypes.Contains(a.PayType)); charges = charges.Where(a => chargeModes.Contains(a.ChargeMode)); if (isTimeRangeRequired) { charges = charges.Where(a => a.CreateTime >= startTime && a.CreateTime <= endTime); } if (lastId == 0) { result.TotalCount = charges.Count(); } charges = charges.Take(DomainDefinition.PAGE_SIZE); foreach (Charge dp in charges) { var x = new ChargeData() { ID = dp.Id, ChargeTime = dp.CreateTime, ChargeMode = dp.ChargeMode, Comments = dp.Comments, Handler = dp.Handler.XiakeName, PayType = dp.PayType, Value = dp.Value, }; result.Items .Add(x); } if (result.Items .Count < DomainDefinition.PAGE_SIZE) { result.IsLoadedAllData = true; } } return result; }
public CombinationChargeData GetXiakeCharges (long lastId) { var result = new CombinationChargeData(); using (var db = DbContextFactory.CreateDbContext()) { var xiake = db.Xiakes.FirstOrDefault(a => a.XiakeName == Thread.CurrentPrincipal.Identity.Name); IQueryable<Charge> charges = db.Charges.Where(a=>a.TargetXiake.Id == xiake.Id).OrderByDescending(a => a.Id); if (lastId != 0) { charges = charges.Where(a => a.Id < lastId); } if (lastId == 0) { result.TotelNum = 0; if(db.Charges.Where(a => a.TargetXiake.Id == xiake.Id && a.PayType == PayType.ByInviteAward).Any()) result.TotelNum = db.Charges.Where(a => a.TargetXiake.Id == xiake.Id && a.PayType == PayType.ByInviteAward) .Sum(a => a.Value); } charges = charges.Take(DomainDefinition.PAGE_SIZE); foreach (Charge dp in charges) { var x = new ChargeData() { ID = dp.Id, ChargeTime = dp.CreateTime, ChargeMode = dp.ChargeMode, Comments = dp.Comments, PayType = dp.PayType, Value = dp.Value, }; result.Items.Add(x); } if (result.Items.Count < DomainDefinition.PAGE_SIZE) { result.IsLoadedAllData = true; } } return result; }