public List <T> GetItemListByConditions <T>(string tableName, List <T> list, List <FilterCondition> filter) { List <T> result = new List <T>(); List <T> subList = null; if (filter == null || list == null || list.Count == 0) { return(result); } for (int i = 0; i < filter.Count; i++) { FilterCondition cond = filter[i]; if (cond.Value != null) { cond.CompareType = !cond.Value.ToString().Contains("*") ? TableCompareType.EQ : TableCompareType.TEXT; if (cond.CompareType == TableCompareType.EQ) { result = result.Concat(list.FindAll(d => { object val = ReflectionCommon.GetValue(d, cond.Key); if (val == null) { return(false); } return(cond.Value.ToString() == val.ToString()); })).ToList(); } else { subList = GetItemListBySearchStr(list, cond); if (subList.Count == 0) { result.Clear(); break; } result = result.Concat(subList).ToList(); } } else { result = list; } } return(result); }
public List <T> OrderItemList <T>(List <T> list, List <FilterCondition> conds) { IOrderedEnumerable <T> olist = null; if (conds == null || conds.Count == 0) { return(list); } olist = list.OrderBy(d => ReflectionCommon.GetValue(d, conds[0].Key)); foreach (FilterCondition c in conds) { olist = OrderItemList <T>(olist, c); } return(olist.ToList()); }
public List <T> GetItemListBySearchStr <T>(List <T> list, FilterCondition condition) { if (list == null) { return(new List <T>()); } return(list.FindAll(d => { object val = ReflectionCommon.GetValue(d, condition.Key); if (val == null) { return false; } return condition.GetRegexValue().IsMatch(val.ToString()); })); }
public bool UpdateItem <T>(string tableName, FilterCondition cond, T data, string[] columns) { IMongoCollection <T> collection = db.GetCollection <T>(tableName); FilterDefinition <T> filter = Builders <T> .Filter.Eq(cond.Key, cond.Value); UpdateDefinition <T> update = null; if (columns == null) { return(false); } foreach (string col in columns) { update = Builders <T> .Update.AddToSet(col, ReflectionCommon.GetValue <T>(data, col)); } return(1 == (int)collection.UpdateOne(transaction, filter, update).ModifiedCount); }
public IOrderedEnumerable <T> OrderItemList <T>(IOrderedEnumerable <T> list, FilterCondition cond) { return(list.ThenBy(u => ReflectionCommon.GetValue(u, cond.Key))); }