/// <summary> /// /// </summary> /// <typeparam name="TBusiness"></typeparam> /// <param name="propertyName"></param> /// <param name="propertyValue"></param> /// <param name="baseFilter"></param> /// <returns></returns> public static string DBCheck <TBusiness>(this BaseFilterAttribute baseFilter, string propertyName, string propertyValue) where TBusiness : Entity { string selectDBValue = string.Empty; var context = QHBXHttpContext.Current.RequestServices.GetService(typeof(DbContext)) as DbContext; Expression <Func <TBusiness, bool> > expression = t => t.IsDelete == DeleteStatus.Normal; var secondExp = ExpressionExtend.CreateExpressionEqual <TBusiness>(propertyName, propertyValue); expression = expression.And(secondExp); var result = context.Set <TBusiness>().FirstOrDefault(expression); var tableAttr = typeof(TBusiness).GetCustomAttribute <System.ComponentModel.DataAnnotations.Schema.TableAttribute>(); if (baseFilter.GetType() == typeof(ForeignCheckAttribute)) { if (result != null) { selectDBValue = result.Id; } else { baseFilter.ErrorMsg = string.Format(baseFilter.ErrorMsg, tableAttr.Name); } } else if (baseFilter.GetType() == typeof(DBFieldDumplicateAttribute)) { if (result != null) { selectDBValue = result.Id; baseFilter.ErrorMsg = string.Format(baseFilter.ErrorMsg, tableAttr.Name); } } return(selectDBValue); }
public static IFilter CreateInstance(BaseFilterAttribute baseFilterAttribute) { var filter = Assembly.GetAssembly(typeof(PfZhouEasyOfficeCollectionExtensions)).GetTypes() .Where(t => typeof(IFilter).IsAssignableFrom(t) && t.IsSubclassOf(typeof(BaseFilter))) .FirstOrDefault(t => t.GetCustomAttribute <FilterBindAttribute>().BindType == baseFilterAttribute.GetType()); if (filter == null) { return(default);