Пример #1
0
        public IList <EthereumContractViewModel> SearchBy(IList <EthereumContractViewModel> list, EthereumContractSearchModel search)
        {
            IList <EthereumContractViewModel> resultList = new List <EthereumContractViewModel>();

            if (search.IsAnyNotNullOrEmpty())
            {
                foreach (PropertyInfo pi in search.GetType().GetProperties())
                {
                    if (pi.PropertyType == typeof(string))
                    {
                        string value = (string)pi.GetValue(search);

                        if (!string.IsNullOrEmpty(value))
                        {
                            var property = typeof(EthereumContractViewModel).GetProperty(pi.Name);
                            resultList = resultList.Concat(list.Where(x => property.GetValue(x, null).ToString().Contains(value)).ToList()).ToList();
                        }
                    }
                    else if (pi.PropertyType == typeof(int))
                    {
                        int value = (int)pi.GetValue(search);

                        if (value != 0)
                        {
                            var property = typeof(EthereumContractViewModel).GetProperty(pi.Name);
                            resultList = resultList.Concat(list.Where(x => property.GetValue(x, null).ToString() == value.ToString()).ToList()).ToList();
                        }
                    }
                    else if (pi.PropertyType.IsEnum)
                    {
                        var property = typeof(EthereumContractViewModel).GetProperty(pi.Name);
                        var status   = Enum.Parse(pi.PropertyType, pi.GetValue(search).ToString()) as Enum;

                        int enumValue = Convert.ToInt32(status);

                        if (enumValue > 0 && !string.IsNullOrEmpty(status.ToString()))
                        {
                            ;
                        }
                        resultList = resultList.Concat(list.Where(x => property.GetValue(x, null).ToString().Contains(status.ToDescriptionString().ToUpper())).ToList()).ToList();
                    }
                }

                return(resultList.Distinct().ToList());
            }

            return(list.ToList());
        }