Exemple #1
0
        public IList <HealthUnit> SearchBy(IList <HealthUnit> list, HealthUnitSearchModel search)
        {
            IList <HealthUnit> resultList = new List <HealthUnit>();

            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(HealthUnit).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(HealthUnit).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(HealthUnit).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());
        }
Exemple #2
0
        public IPagedList <HealthUnit> Pagination(IList <HealthUnit> list, int?page, string sortOrder, HealthUnitSearchModel search, HealthUnitSearchModel currentFilter)
        {
            ViewBag.currentSort = sortOrder;

            if (search.IsAnyNotNullOrEmpty())
            {
                page = 1;
            }
            else
            {
                search = currentFilter;
            }

            ViewBag.page = page ?? 1;

            int pageSize = 10;

            return(list.ToPagedList(page ?? 1, pageSize));
        }