public ActionResult Contacts(int currentPage = 1, string orderBy = "id", string order = "asc", string searchBy = "name", string searchByValue = "") { DbConnection conn = new DbConnection(); conn.SqlCommand.Connection.Open(); ContactLogic contactlogic = new ContactLogic(); int numberOfContacts = contactlogic.GetTotalNumberOfContacts(conn, searchBy, searchByValue); conn.SqlCommand.Parameters.Clear(); searchByValue = searchByValue == "undefined" ? "" : searchByValue; searchBy = searchBy == "undefined" ? "name" : searchBy; conn.Reader = contactlogic.GetListOfContactsWithPagination(conn, currentPage, orderBy, order, searchBy, searchByValue); ContactsViewModel listOfContacts = new ContactsViewModel { Contacts = contactlogic.GenerateListOfContactsFromSqlDataReader(conn.Reader), NumberOfPaginationPages = contactlogic.GenerateNumberOfPaginationPagesFromTotalNumberOfContacts(currentPage, numberOfContacts), CurrentPage = currentPage, CurrentOrder = order, OrderBy = orderBy, TotalNumberOfContacts = numberOfContacts, SearchBy = searchBy, SearchByValue = searchByValue }; conn.SqlCommand.Connection.Close(); return(View(listOfContacts)); }