public Resp_Query <AlarmDTO> Query(Alarm_Query request) { var records = _repository.GetAll(); var response = new Resp_Query <AlarmDTO>(); records.ToMaybe() .Do(d => request.Verify()) .DoWhen(t => !string.IsNullOrEmpty(request.CarNumber), d => records = records.Where(s => s.CarNumber.Contains(request.CarNumber))) .DoWhen(t => !string.IsNullOrEmpty(request.Channel), d => records = records.Where(s => s.Channel.Equals(request.Channel))); if (!string.IsNullOrEmpty(request.IsDeal) && int.TryParse(request.IsDeal, out int result)) { records = records.Where(s => s.IsDeal == result); } if (!string.IsNullOrEmpty(request.AlarmBeginTime) && DateTime.TryParse(request.AlarmBeginTime, out DateTime a_start)) { records = records.Where(s => s.AlarmTime >= a_start); } if (!string.IsNullOrEmpty(request.AlarmEndTime) && DateTime.TryParse(request.AlarmEndTime, out DateTime a_end)) { records = records.Where(s => s.AlarmTime <= a_end); } if (!string.IsNullOrEmpty(request.HandlerBeginTime) && DateTime.TryParse(request.HandlerBeginTime, out DateTime h_start)) { records = records.Where(s => s.HandlerTime >= h_start); } if (!string.IsNullOrEmpty(request.HandlerEndTime) && DateTime.TryParse(request.HandlerEndTime, out DateTime h_end)) { records = records.Where(s => s.HandlerTime <= h_end); } response.totalCounts = records.Count(); response.totalRows = (int)Math.Ceiling((double)response.totalCounts / request.PgSize); if (!string.IsNullOrEmpty(request.Order)) { records = records.DataSorting(request.Order, request.Esc); } else { records = records.OrderByDescending(o => o.ID); } response.entities = records.Skip(request.PgSize * (request.PgIndex - 1)).Take(request.PgSize).ToList().ConvertoDto <Alarm, AlarmDTO>().ToList(); return(response); }