public override Expression <Func <Merchant, bool> > GetExpress <QM>(QM model) { Expression <Func <Merchant, bool> > express = DynamicExpressions.True <Merchant>(); var m = model as MerchantQM; if (!string.IsNullOrWhiteSpace(m.Code)) { express = express.AndAlso(t => t.Code.Contains(m.Code.Trim())); } if (!string.IsNullOrWhiteSpace(m.Name)) { express = express.AndAlso(t => t.Name.Contains(m.Name.Trim())); } if (!string.IsNullOrWhiteSpace(m.Mobile)) { express = express.AndAlso(t => t.Mobile == m.Mobile.Trim()); } if (m.Status != null) { express = express.AndAlso(t => t.Status == m.Status); } return(express); }
public override Expression <Func <OrderHousePayment, bool> > GetExpress <QM>(QM model) { Expression <Func <OrderHousePayment, bool> > express = DynamicExpressions.True <OrderHousePayment>(); var m = model as OrderHousePaymentQM; if (!string.IsNullOrWhiteSpace(m.OrderNumber)) { express = express.AndAlso(t => t.OrderNumber == m.OrderNumber.Trim()); } if (!string.IsNullOrWhiteSpace(m.MemberName)) { express = express.AndAlso(t => t.Member.Name.Contains(m.MemberName.Trim())); } if (m.Status != null) { express = express.AndAlso(t => t.Status == m.Status); } if (currentUser.MerchantID != 0) { express = express.AndAlso(t => t.Merchant.ID == currentUser.MerchantID); } return(express); }
public override Expression <Func <PingAnOrderPaidRecharge, bool> > GetExpress <QM>(QM model) { Expression <Func <PingAnOrderPaidRecharge, bool> > express = DynamicExpressions.True <PingAnOrderPaidRecharge>(); var m = model as OntimePayQM; if (!string.IsNullOrWhiteSpace(m.OrderNumber)) { express = express.AndAlso(t => t.OrderPaid.OrderNumber == m.OrderNumber.Trim()); } if (!string.IsNullOrWhiteSpace(m.RechargeName)) { express = express.AndAlso(t => t.OrderPaid.Member.Name == m.RechargeName.Trim()); } if (!string.IsNullOrWhiteSpace(m.RechargeIDNumber)) { express = express.AndAlso(t => t.OrderPaid.Member.IDNumber == m.RechargeIDNumber.Trim()); } if (!string.IsNullOrWhiteSpace(m.BankCardNumber)) { express = express.AndAlso(t => t.BankCardNumber == m.BankCardNumber.Trim()); } if (m.Status != null) { express = express.AndAlso(t => t.Status == m.Status); } if (m.TransTime != null) { express = express.AndAlso(t => t.TransTime >= m.TransTime); } return(express); }
public override Expression <Func <HouseTypeShow, bool> > GetExpress <QM>(QM model) { Expression <Func <HouseTypeShow, bool> > express = DynamicExpressions.True <HouseTypeShow>(); var m = model as HouseTypeShowQM; if (m.ProjectID != null) { express = express.AndAlso(t => t.ProjectID == m.ProjectID); } if (m.MerchantID != null) { express = express.AndAlso(t => t.MerchantID == m.MerchantID); } if (!string.IsNullOrWhiteSpace(m.HouseTypeName)) { express = express.AndAlso(t => t.HouseTypeName == m.HouseTypeName.Trim()); } if (m.Status != null) { express = express.AndAlso(t => t.Status == m.Status); } if (!string.IsNullOrWhiteSpace(m.ProjetName)) { express = express.AndAlso(t => t.Project.ProjectName == m.ProjetName.Trim()); } if (currentUser.MerchantID != 0) { express = express.AndAlso(t => t.Merchant.ID == currentUser.MerchantID); } return(express); }
public override Expression <Func <PingAnOrderPaid, bool> > GetExpress <QM>(QM model) { Expression <Func <PingAnOrderPaid, bool> > express = DynamicExpressions.True <PingAnOrderPaid>(); var m = model as PingAnOrderPaidQM; //if (!string.IsNullOrWhiteSpace(m.OrderNumber)) //{ // express = express.AndAlso(t => t.OrderNumber == m.OrderNumber.Trim()); //} //if (!string.IsNullOrWhiteSpace(m.MemberMobile)) //{ // express = express.AndAlso(t => t.Member.Mobile == m.MemberMobile.Trim()); //} //if (!string.IsNullOrWhiteSpace(m.MemberName)) //{ // express = express.AndAlso(t => t.Member.Name.Contains(m.MemberName.Trim())); //} //if (m.ProjectID != null) //{ // express = express.AndAlso(t => t.ProjectID == m.ProjectID); //} if (m.Status != null) { express = express.AndAlso(t => t.Status == m.Status); } return(express); }
public void GetPredicate_ShouldHandleEnumerableStringOperators <T>(int id, T title, FilterOperator op, object value) { var entry = new Entry <T>(id, new SubEntry <T>(title)); var predicate = DynamicExpressions.GetPredicate <Entry <T> >("SubEntry.Title", op, value).Compile(); Assert.True(predicate(entry)); }
public void GetPredicate_ShouldHandleNullOrEmtpyStringOperatorsFalse(int id, string title, FilterOperator op, object value) { var entry = new Entry <string>(id, new SubEntry <string>(title)); var predicate = DynamicExpressions.GetPredicate <Entry <string> >("SubEntry.Title", op, value).Compile(); Assert.False(predicate(entry)); }
public override Expression <Func <Equipment, bool> > GetExpress <QM>(QM model) { Expression <Func <Equipment, bool> > express = DynamicExpressions.True <Equipment>(); var m = model as EquipmentQM; if (m.MerchantID != null) { express = express.AndAlso(t => t.MerchantID == m.MerchantID); } if (!string.IsNullOrWhiteSpace(m.EquipmentSNNo)) { express = express.AndAlso(t => t.EquipmentSNNo == m.EquipmentSNNo.Trim()); } if (!string.IsNullOrWhiteSpace(m.MerchantName)) { express = express.AndAlso(t => t.Merchant.Name.Contains(m.MerchantName.Trim())); } if (m.Status != null) { express = express.AndAlso(t => t.Status == m.Status); } return(express); }
public override Expression <Func <Member, bool> > GetExpress <QM>(QM model) { Expression <Func <Member, bool> > express = DynamicExpressions.True <Member>(); var m = model as MemberQM; if (!string.IsNullOrWhiteSpace(m.Name)) { express = express.AndAlso(t => t.Name.Contains(m.Name.Trim())); } if (!string.IsNullOrWhiteSpace(m.Mobile)) { express = express.AndAlso(t => t.Mobile == m.Mobile.Trim()); } if (!string.IsNullOrWhiteSpace(m.IDNumber)) { express = express.AndAlso(t => t.IDNumber == m.IDNumber.Trim()); } if (m.Status != null) { express = express.AndAlso(t => t.Status == m.Status); } if (currentUser.MerchantID != 0) { express = express.AndAlso(t => t.MerchantMemberList.Where(w => w.MerchantID == currentUser.MerchantID).Count() != 0); // express = express.AndAlso(t => t.OrderPaidList.Where(w => w.MerchantID == currentUser.MerchantID).Count() != 0); } return(express); }
public override Expression <Func <Project, bool> > GetExpress <QM>(QM model) { Expression <Func <Project, bool> > express = DynamicExpressions.True <Project>(); var m = model as ProjectQM; if (!string.IsNullOrWhiteSpace(m.ProjectName)) { express = express.AndAlso(t => t.ProjectName.Contains(m.ProjectName.Trim())); } if (m.MerchantID != null) { express = express.AndAlso(t => t.MerchantID == m.MerchantID); } if (m.Deadline != null) { express = express.AndAlso(t => t.Deadline >= m.Deadline); } if (m.Status != null) { express = express.AndAlso(t => t.Status == m.Status); } if (currentUser.MerchantID != 0) //商户客户端登录,会先获取到登录人员对应的商户ID,则此查询只查询该商户下项目(后台ADMIN则可查询所有) { express = express.AndAlso(t => t.Merchant.ID == currentUser.MerchantID); } return(express); }
public override Expression <Func <Employee, bool> > GetExpress <QM>(QM model) { Expression <Func <Employee, bool> > express = DynamicExpressions.True <Employee>(); var m = model as EmployeeQM; if (currentUser.IsAdmin) { if (!string.IsNullOrWhiteSpace(m.Code)) { express = express.AndAlso(t => t.Merchant.Code == m.Code.Trim()); } if (!string.IsNullOrWhiteSpace(m.MerchantName)) { express = express.AndAlso(t => t.Merchant.Name.Contains(m.MerchantName.Trim())); } if (!string.IsNullOrWhiteSpace(m.Name)) { express = express.AndAlso(t => t.Name.Contains(m.Name.Trim())); } if (!string.IsNullOrWhiteSpace(m.Mobile)) { express = express.AndAlso(t => t.Mobile == m.Mobile.Trim()); } if (currentUser.MerchantID != 0) { express = express.AndAlso(t => t.MerchantID == currentUser.MerchantID); } } else { if (m.MerchantID != null) //客户端用户查询时,默认根据当前用户的商户ID来查询(MerchantID) { express = express.AndAlso(t => t.MerchantID == m.MerchantID); } if (!string.IsNullOrWhiteSpace(m.Code)) { express = express.AndAlso(t => t.Code == m.Code.Trim() && t.MerchantID == m.MerchantID); } if (!string.IsNullOrWhiteSpace(m.MerchantName)) { express = express.AndAlso(t => t.Merchant.Name == m.MerchantName.Trim() && t.MerchantID == m.MerchantID); } if (!string.IsNullOrWhiteSpace(m.Name)) { express = express.AndAlso(t => t.Name.Contains(m.Name.Trim()) && t.MerchantID == m.MerchantID); } } if (m.Status != null) { express = express.AndAlso(t => t.Status == m.Status); } return(express); }
public void GetPredicate_ShouldHandleEqualsGenericOperators <T>(int id, T title, string property, FilterOperator op, object value) { var entry = new Entry <T>(id, new SubEntry <T>(title)); var predicate = DynamicExpressions.GetPredicate <Entry <T> >(property, op, value).Compile(); Assert.True(predicate(entry)); }
public void GetPredicate_ShouldWork_WhenValueIsNotStringAndOperatorIsStringBased(int id, string title, FilterOperator op, object value) { var entry = new Entry <string>(id, new SubEntry <string>(title)); var predicate = DynamicExpressions.GetPredicate <Entry <string> >("SubEntry.Title", op, value).Compile(); Assert.True(predicate(entry)); }
public void GetPropertyGetter_ShouldThrow_WhenPropertyDoesntExist() { var entry = new Entry(2); var ex = Assert.Throws <ArgumentException>(() => DynamicExpressions.GetPropertyGetter <Entry>("Test")); Assert.Equal("Instance property 'Test' is not defined for type 'DynamicExpressions.UnitTests.Entry' (Parameter 'propertyName')", ex.Message); }
public void GetPropertyGetter_ShouldThrow_WhenPropertyIsNull() { var ex = Assert.Throws <ArgumentNullException>(() => { DynamicExpressions.GetPropertyGetter <PropertyGetterTests>(null); }); Assert.Equal("Value cannot be null. (Parameter 'property')", ex.Message); }
public void GetPropertyGetter_ShouldReturnCorrectGetter() { var entry = new Entry(2); var getter = DynamicExpressions.GetPropertyGetter <Entry>("Id").Compile(); var id = getter(entry); Assert.Equal(entry.Id, id); }
public void GetPropertyGetter_ShouldHandleNestedProperty() { var entry = new Entry(1, new SubEntry("Title")); var getter = DynamicExpressions.GetPropertyGetter <Entry>("SubEntry.Title").Compile(); var value = getter(entry); Assert.Equal(entry.SubEntry.Title, value); }
public List <Employee> GetAuthList() { Expression <Func <Employee, bool> > express = DynamicExpressions.True <Employee>(); if (!currentUser.IsAdmin) { var users = this.GetDepartmentUsers(currentUser.ID); express = express.AndAlso(t => users.Contains(t.ID)); } return(this.Gets(express, 1, Int32.MaxValue, new OrderByExpression <Employee, string>(t => t.Name)).ToList()); }
public async IAsyncEnumerable <TView> GetFiltered( [FromQuery] UserFilterParams filterParams ) { var filter = DynamicExpressions.CreateFilter <TOtherEntity>(filterParams); var users = uw.Repository <TOtherEntity>().GetAllAsync(filterParams.FetchLength, filter); await foreach (var user in users) { yield return(mapper.Map <TView>(user)); } }
public List <List <Entry> > SearchTitleDynamicallyWithoutCache() { var result = new List <List <Entry> >(); for (int i = 0; i <= 500; i++) { var expr = DynamicExpressions.GetPropertyGetter <Entry>("Title"); var orderedEntries = _entries.AsQueryable().OrderByDescending(expr).ToList(); result.Add(orderedEntries); } return(result); }
public void GetPropertyGetter_ShouldBeUsableInQueryableOrderBy() { var entries = new List <Entry> { new Entry(1), new Entry(2), }; var getter = DynamicExpressions.GetPropertyGetter <Entry>("Id"); var sortedEntries = entries.AsQueryable().OrderByDescending(getter).ToList(); Assert.Equal(entries[0], sortedEntries[1]); Assert.Equal(entries[1], sortedEntries[0]); }
public override Expression <Func <EmployeeMenu, bool> > GetExpress <QM>(QM model) { Expression <Func <EmployeeMenu, bool> > express = DynamicExpressions.True <EmployeeMenu>(); if (model.Status == null) { express = express.AndAlso(t => t.Status == 1); } else { express = express.AndAlso(t => t.Status == model.Status); } return(express); }
public override Expression <Func <MerchantMember, bool> > GetExpress <QM>(QM model) { Expression <Func <MerchantMember, bool> > express = DynamicExpressions.True <MerchantMember>(); var m = model as MerchantMemberQM; if (m.Status != null) { express = express.AndAlso(t => t.Status == m.Status); } return(express); }
public override Expression <Func <EmployeeDepartment, bool> > GetExpress <QM>(QM model) { Expression <Func <EmployeeDepartment, bool> > express = DynamicExpressions.True <EmployeeDepartment>(); var m = model as EmployeeDepartmentQM; if (!string.IsNullOrWhiteSpace(m.Name)) { express = express.AndAlso(t => t.Name.Contains(m.Name.Trim())); } if (model.Status != null) { express = express.AndAlso(t => t.Status == model.Status); } return(express); }
public override Expression <Func <TLTPreferences, bool> > GetExpress <QM>(QM model) { Expression <Func <TLTPreferences, bool> > express = DynamicExpressions.True <TLTPreferences>(); var m = model as TLTPreferencesQM; if (m.Status != null) { express = express.AndAlso(t => t.Status == m.Status); } if (currentUser.MerchantID != 0) { express = express.AndAlso(t => t.Merchant.ID == currentUser.MerchantID); } if (!string.IsNullOrWhiteSpace(m.MerchantName)) { express = express.AndAlso(t => t.Merchant.Name.Contains(m.MerchantName)); } return(express); }
public override Expression <Func <OrderBooking, bool> > GetExpress <QM>(QM model) { Expression <Func <OrderBooking, bool> > express = DynamicExpressions.True <OrderBooking>(); var m = model as OrderBookingQM; if (!string.IsNullOrWhiteSpace(m.OrderNumber)) { express = express.AndAlso(t => t.OrderNumber == m.OrderNumber.Trim()); } if (!string.IsNullOrWhiteSpace(m.OrderMobile)) { express = express.AndAlso(t => t.OrderMobile == m.OrderMobile.Trim()); } if (!string.IsNullOrWhiteSpace(m.OrderName)) { express = express.AndAlso(t => t.OrderName.Contains(m.OrderName.Trim())); } if (m.Status != null) { express = express.AndAlso(t => t.Status == m.Status); } if (currentUser.MerchantID != 0) { express = express.AndAlso(t => t.Merchant.ID == currentUser.MerchantID); } if (m.ProjectID != null) { express = express.AndAlso(t => t.ProjectID == m.ProjectID); } if (m.QueryDate != null) { express = express.AndAlso(t => t.CreateDatetime >= m.QueryDate); } return(express); }
public override Expression <Func <ProceedsType, bool> > GetExpress <QM>(QM model) { Expression <Func <ProceedsType, bool> > express = DynamicExpressions.True <ProceedsType>(); var m = model as ProceedsTypeQM; //if (!string.IsNullOrWhiteSpace(m.EquipmentNo)) //{ // express = express.AndAlso(t => t.EquipmentNo == m.EquipmentNo.Trim()); //} //if (!string.IsNullOrWhiteSpace(m.EquipmentSNNo)) //{ // express = express.AndAlso(t => t.EquipmentSNNo == m.EquipmentSNNo.Trim()); //} if (m.Status != null) { express = express.AndAlso(t => t.Status == m.Status); } return(express); }
public override Expression <Func <BankCard, bool> > GetExpress <QM>(QM model) { Expression <Func <BankCard, bool> > express = DynamicExpressions.True <BankCard>(); var m = model as BankCardQM; if (m.MemberID != null) { express = express.AndAlso(t => t.MemberID == m.MemberID); } if (!string.IsNullOrWhiteSpace(m.BankCardNumber)) { express = express.AndAlso(t => t.BankCardNumber == m.BankCardNumber.Trim()); } if (m.Status != null) { express = express.AndAlso(t => t.Status == m.Status); } return(express); }
public void TreatFile() { try { Stopwatch watch; long elapsedMs = 0; watch = Stopwatch.StartNew(); _logger.LogInformation(string.Format(LogsProcess.InitProcess, Variables.TreatFile, DateTime.Now.ToString())); dynamic fileInClass = null; MemoryStream file = null; if (_parametersProcessum.Zip) { file = ExtractFile.Extract(expectedFilePath); } else { FileStream fs = new FileStream(expectedFilePath, FileMode.Open, FileAccess.Read); file = new MemoryStream(); fs.CopyTo(file); } fileInClass = DynamicExpressions.FileInClass(file, @class, _parametersProcessum); if (_parametersProcessum.IdGeracaoArquivoDeParaNavigation != null) { //Tem de Para switch ((ETipoArquivo)_parametersProcessum.IdGeracaoArquivoDeParaNavigation.IdTipoArquivo) { case ETipoArquivo.CSV: //implementar caso precise break; case ETipoArquivo.XLSX: _excel.TreatFile(fileInClass, @class, _parametersProcessum); break; case ETipoArquivo.XLS: //implementar caso precise break; case ETipoArquivo.TXT: //implementar caso precise break; default: break; } } if (File.Exists(expectedFilePath)) { File.Delete(expectedFilePath); } watch.Stop(); elapsedMs = watch.ElapsedMilliseconds; _logger.LogInformation(string.Format(LogsProcess.FinishProcess, Variables.TreatFile, DateTime.Now.ToString())); _logger.LogInformation(string.Format(LogsProcess.TimeExecution, Variables.TreatFile, elapsedMs.ToString())); } catch (Exception ex) { throw ex; } }
public virtual Expression <Func <E, bool> > GetExpress <QM>(QM model = null) where QM : BaseQueryModel, new() { return(DynamicExpressions.True <E>()); }