public IPagedList <EthereumContractViewModel> Pagination(IList <EthereumContractViewModel> list, int?page, string sortOrder, EthereumContractSearchModel search, EthereumContractSearchModel 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)); }
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()); }
// GET: EthereumContractViewModel public ActionResult Index(int?page, string sortOrder, bool?asc, int?institutionType, int?emergencyType, EthereumContractSearchModel search, EthereumContractSearchModel currentSearchFilter) { if (search != null && !string.IsNullOrEmpty(search.Name)) { ViewBag.currentFilter = search; ViewBag.Name = search.Name; } IList <EthereumContractViewModel> EthereumContractViewModels = _EthereumContractRepository.GetAll().Select(x => new EthereumContractViewModel() { ContractID = x.ContractID }).ToList(); EthereumContractViewModels = SearchBy(EthereumContractViewModels, search); EthereumContractViewModels = OrderBy(sortOrder, asc, EthereumContractViewModels); var pageList = Pagination(EthereumContractViewModels, page, sortOrder, search, currentSearchFilter); return(View(pageList)); }