public ActionResult Index(string sortOrder, string searchString, string currentFilter, int?page) { ViewBag.IdSortParm = string.IsNullOrEmpty(sortOrder) ? "id_desc" : ""; ViewBag.NameSortParm = sortOrder == "Name" ? "name_desc" : "Name"; // ViewBag.IdSortParm = sortOrder == "Id" ? "id_desc" : "Id"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var glAccounts = _glAccountRepository.GetAll(); try { using (ISession session = NHibernateHelper.Session) { if (!string.IsNullOrEmpty(searchString)) { glAccounts = session.Query <GLAccount>().Where(u => u.GLAccountName.ToUpper().Contains(searchString.ToUpper())).ToList(); } switch (sortOrder) { case "name_desc": glAccounts = glAccounts.OrderByDescending(a => a.GLAccountName).ToList(); break; case "id_desc": glAccounts = glAccounts.OrderByDescending(a => a.GLCode).ToList(); break; default: glAccounts = glAccounts.OrderByDescending(u => u.Id).ToList(); break; } int pageSize = 3; int pageNumber = (page ?? 1); return(View(glAccounts.ToPagedList(pageNumber, pageSize))); } } catch (Exception exception) { ViewBag.Exception = exception.Message; } return(View(new GLAccount())); }
private void LoadComboBoxes() { try { IList <GLAccount> allAccounts = GLAccountRepository.GetAll(); IList <Terms> allTerms = TermsRepository.GetAll(); _allStates = StateRepository.GetAll(); VendorTermsComboBox.ItemsSource = allTerms; VendorAccountComboBox.ItemsSource = allAccounts; VendorStateComboBox.ItemsSource = _allStates; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }