public Resp_Query <RecordManagerDTO> Query(RecordManager_Query request) { var response = new Resp_Query <RecordManagerDTO>(); var records = _repository.GetAll(); records.ToMaybe() .Do(d => request.Verify()) .DoWhen(t => !string.IsNullOrEmpty(request.CarNumber.NullToString().Trim()), d => records = records.Where(s => s.CarNumber.Contains(request.CarNumber))) .DoWhen(t => !string.IsNullOrEmpty(request.DLicense.NullToString().Trim()), d => records = records.Where(s => s.DLicense.Contains(request.DLicense))) .DoWhen(t => !string.IsNullOrEmpty(request.TLicense.NullToString().Trim()), d => records = records.Where(s => s.TLicense.Contains(request.TLicense))) .DoWhen(t => !string.IsNullOrEmpty(request.Driver.NullToString().Trim()), d => records = records.Where(s => s.Driver.Contains(request.Driver))) .DoWhen(t => !string.IsNullOrEmpty(request.Contact.NullToString().Trim()), d => records = records.Where(s => s.Contact.Contains(request.Contact))) .DoWhen(t => !string.IsNullOrEmpty(request.RecordMGrade.NullToString().Trim()), d => records = records.Where(s => s.RecordMGrade.Equals(request.RecordMGrade))) .DoWhen(t => !string.IsNullOrEmpty(request.CarColor.NullToString().Trim()), d => records = records.Where(s => s.CarColor.Equals(request.CarColor))) .DoWhen(t => !string.IsNullOrEmpty(request.CarType.NullToString().Trim()), d => records = records.Where(s => s.CarType.Equals(request.CarType))) .DoWhen(t => !string.IsNullOrEmpty(request.Channel.NullToString().Trim()), d => records = records.Where(s => s.Channel.Contains(request.Channel))); //.DoWhen(t => !string.IsNullOrEmpty(request.Type.NullToString().Trim()), d => records = records.Where(s => s.Type == request.Type.ToInt())); if (!string.IsNullOrEmpty(request.Type) && int.TryParse(request.Type, out int typeresult)) { records = records.Where(s => s.Type == typeresult); } if (!string.IsNullOrEmpty(request.IsValid) && int.TryParse(request.IsValid, out int result)) { if (result == 0) { records = records.Where(s => s.IsValid == 0); } else if (result == 1) { records = records.Where(s => s.IsValid == 1); } } if (!string.IsNullOrEmpty(request.BeginTime) && DateTime.TryParse(request.BeginTime, out DateTime start)) //Linq to entity 不支持datatime.parse函数 { records = records.Where(s => s.CreateTime >= start); } if (!string.IsNullOrEmpty(request.EndTime) && DateTime.TryParse(request.EndTime, out DateTime end)) { records = records.Where(s => s.CreateTime <= 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(t => t.ID); } response.entities = records.Skip(request.PgSize * (request.PgIndex - 1)).Take(request.PgSize).ToList().ConvertoDto <RecordManager, RecordManagerDTO>().ToList(); return(response); }
public Resp_Index <RecordManagerDTO> Index(Req_Index request) { var response = new Resp_Index <RecordManagerDTO>(); var limits = _sysRightRepository.GetRightByUserWithModule(request.userId, request.moduleId).ConvertoDto <SysUserRightView, SysModuleOperateIndexDTO>().ToList(); if (limits.IsNotNull() && limits.Count > 0 && limits.Find(s => s.IsValid == 1).IsNotNull()) { response.allowVisit = true; response.moduleOperaties = limits.OrderByDescending(t => t.IsValid).GroupBy(t => new { t.KeyCode, t.KeyName }).Select(s => new SysModuleOperateIndexDTO { KeyCode = s.Key.KeyCode, KeyName = s.Key.KeyName, IsValid = s.Sum(x => x.IsValid), }).ToList(); var query_parameter = new RecordManager_Query { PgIndex = 1, PgSize = request.PgSize }; response.query = Query(query_parameter); } else { _sysRightRepository.UnitOfWork.Commite(); response.allowVisit = false; response.message = "无访问权限,请联系管理员"; } return(response); }