public UsersPage GetPage(string GroupName, int PageNo, int PageSize = 10, string filterQ = "0") { using (SqlCommand cmd = new SqlCommand("[dbo].[GetUsersList]", Conn)) { cmd.CommandTimeout = ComTimeout; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@PageNo", PageNo); cmd.Parameters.AddWithValue("@PageSize", PageSize); cmd.Parameters.AddWithValue("@GroupName", string.IsNullOrEmpty(GroupName) == true ? "All" : GroupName); cmd.Parameters.AddWithValue("@filterQ", string.IsNullOrEmpty(filterQ) == true ? "0" : filterQ); List <UsersListItem> objList = new List <UsersListItem>(); UsersListItem obj = null; try { OpenConnection(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { obj = new UsersListItem { UserId = (string)dr["UserId"], FirstName = (string)dr["FirstName"], LastName = (string)dr["LastName"], IsLogedIn = (bool)dr["IsLogedIn"], CurrentStatus = (string)dr["AccountStatus"], OnlineStatus = (string)dr["OnlineStatus"] }; objList.Add(obj); } dr.NextResult(); while (dr.Read()) { TotalPages = (int)dr["PageCount"]; } } return(new UsersPage(objList, PageNo, PageSize, TotalPages, filterQ)); } finally { CloseConnection(); } } }
public UsersListItem GetAllUsers() { UsersListItem response = new UsersListItem(); List <Users> listusers = ur.GetAllUsers(); response.TotalCount = ur.GetAllUsers().Count; List <UserItem> useritem = new List <UserItem>(); for (int i = 0; i < listusers.Count; i++) { UserItem ui = new UserItem(); ui.UserId = listusers[i].UserId; ui.UserName = listusers[i].UserName; ui.UserPassword = listusers[i].UserPassword; ui.Sex = listusers[i].Sex; ui.PhoneNum = listusers[i].PhoneNum; ui.Address = listusers[i].Address; ui.PostalCode = listusers[i].PostalCode; useritem.Add(ui); } response.UserItem = useritem; return(response); }