public IEnumerable <CheckListFilter> InitNomenclatureDetailMenu(long key) { //main predicate Expression <Func <krt_Naftan_orc_sapod, bool> > predicate = x => x.keykrt == key; return(new[] { new CheckListFilter(this._engage.GetGroup <krt_Naftan_orc_sapod, object>(x => new { x.id_kart, x.nkrt }, predicate) .ToDictionary(x => x.First().id_kart?.ToString(), x => x.First().nkrt)) { FieldName = PredicateExtensions.GetPropName <krt_Naftan_orc_sapod>(x => x.id_kart), NameDescription = "Карточки:" }, new CheckListFilter(this._engage.GetGroup(x => x.tdoc.ToString(), predicate) .ToDictionary(x => x.First().tdoc.ToString(), x => x.First().tdoc.ToString())) { FieldName = PredicateExtensions.GetPropName <krt_Naftan_orc_sapod>(x => x.tdoc), NameDescription = "Тип документа:" }, new CheckListFilter(this._engage.GetGroup(x => x.vidsbr.ToString(), predicate) .ToDictionary(x => x.First().vidsbr.ToString(), x => x.First().vidsbr.ToString())) { FieldName = PredicateExtensions.GetPropName <krt_Naftan_orc_sapod>(x => x.vidsbr), NameDescription = "Вид сбора:" }, new CheckListFilter(this._engage.GetGroup(x => x.nomot.ToString(), predicate) .ToDictionary(x => x.First().nomot.ToString(), x => x.First().nomot.ToString())) { FieldName = PredicateExtensions.GetPropName <krt_Naftan_orc_sapod>(x => x.nomot), NameDescription = "Документ:" }, //new CheckListFilter(_engage.GetGroup(x=>x.dt.ToString(CultureInfo.InvariantCulture), predicate).Select(x=>x.ToString())){ // FieldName = PredicateExtensions.GetPropName<krt_Naftan_orc_sapod>(x=>x.dt), // NameDescription = "Период:" //}, }); }
public IEnumerable <CheckListFilter> InitGlobalSearchFilters() { CheckListFilter[] result; try { result = new[] { new CheckListFilter( this._engage.GetGroup <krt_Naftan_orc_sapod, object>(x => new { x.id_kart, x.nkrt }, x => x.tdoc == 4 && x.id_kart != null, x => new { x.nkrt }, caсhe: true) .ToDictionary(x => x.First().id_kart?.ToString(), x => x.First().nkrt)) { FieldName = PredicateExtensions.GetPropName <krt_Naftan_orc_sapod> (x => x.id_kart), NameDescription = @"Накоп. Карточки" }, new CheckListFilter( this._engage.GetGroup <krt_Naftan, object>(x => new { x.KEYKRT, x.NKRT }, x => true, x => new { x.NKRT }, caсhe: true) .ToDictionary(x => x.First().KEYKRT.ToString(), x => x.First().NKRT.ToString())) { FieldName = PredicateExtensions.GetPropName <krt_Naftan_orc_sapod> (x => x.keykrt), NameDescription = @"Перечни" }, // new CheckListFilter( // /* _engage.GetGroup<krt_Naftan_orc_sapod, string>( x => x.num_doc, x => x.num_doc != null && x.num_doc.Length > 0, x => x.num_doc) // .ToDictionary(x => x.First().num_doc, x => x.First().num_doc)*/) { // FieldName = PredicateExtensions.GetPropName<krt_Naftan_orc_sapod> (x => x.num_doc), // NameDescription = @"Первичный док. (накладные, ведомости, акты, карточки)" //}, }; } catch (Exception ex) { this._engage.Log.Debug($"Method initGlobalSearchFilters throws exception: {ex.Message}."); throw; } return(result); }
public void FiltersDtoTest() { // Arrange var seq = new[] { "First", "Second", "Third" }; var cards = new List <krt_Naftan_orc_sapod> { new krt_Naftan_orc_sapod() { id_kart = 11, nkrt = @"K_1" }, new krt_Naftan_orc_sapod() { id_kart = 12, nkrt = @"K_2" }, new krt_Naftan_orc_sapod() { id_kart = 13, nkrt = @"K_3" }, new krt_Naftan_orc_sapod() { id_kart = 14, nkrt = @"K_4" }, new krt_Naftan_orc_sapod() { id_kart = 15, nkrt = @"K_5" }, new krt_Naftan_orc_sapod() { id_kart = 11, nkrt = @"K_1" }, // dublicate new krt_Naftan_orc_sapod() { id_kart = 12, nkrt = @"K_2" }, new krt_Naftan_orc_sapod() { id_kart = 13, nkrt = @"K_3" }, new krt_Naftan_orc_sapod() { id_kart = 14, nkrt = @"K_4" }, // wrong cases (filter predicate) new krt_Naftan_orc_sapod() { id_kart = null, nkrt = @"K_null" }, }.AsQueryable(); Expression <Func <krt_Naftan_orc_sapod, object> > groupPredicate = x => new { x.id_kart, x.nkrt }; Expression <Func <krt_Naftan_orc_sapod, bool> > filterPredicate = x => x.id_kart != null; // Act var result = cards.Where(filterPredicate) .OrderBy(x => x.nkrt) .GroupBy(groupPredicate) .ToDictionary(x => x.First().id_kart.Value.ToString(), x => x.First().nkrt); var availableValues = result.Values.Select(x => x); var availableKeys = result.Keys.Select(x => x); var filterDict = new CheckListFilter(result) { FieldName = PredicateExtensions.GetPropName <krt_Naftan_orc_sapod>(x => x.id_kart), NameDescription = @"Накоп. Карточки" }; // There're four unique values var inputSeq = new[] { "1", "2", "3", "1" }; // It moves them in dictinary with unique Key/Value var inputDicionary = inputSeq.GroupBy(x => x).ToDictionary(x => x.First(), x => x.First()); var dictValues = inputDicionary.Values.Select(x => x); // constructor with enum var filterEnum = new CheckListFilter(inputSeq); var expTree1 = filterDict.FilterByField <krt_Naftan_orc_sapod>(); Assert.AreEqual(5, result.Count()); Assert.AreEqual(5, availableValues.ToList().Count()); Assert.AreEqual(@"Накоп. Карточки", filterDict.NameDescription); Assert.AreEqual(@"id_kart", filterDict.FieldName); Assert.AreEqual(5, filterDict.AllAvailableValues.Count()); Assert.AreEqual(3, dictValues.Count()); Assert.AreEqual(3, filterEnum.AllAvailableValues.Count()); }