/// <summary> /// Get UserInfo /// </summary> /// <returns></returns> public UserInfo GetUser(UserInfo userInfo) { var result = new UserInfo(); try { var dataTable = _dbConnection.ExecuteSelectQuery(ConstantInfo.SP_GETUSER, new SqlParameter("@UserName", userInfo.UserName), new SqlParameter("@Password", userInfo.Password)); if (dataTable.Rows.Count > 0) { result.CreateFrom(dataTable.Rows[0]); } else { return null; } } catch (Exception) { //Log here throw; } return result; }
/// <summary> /// Select user by ID /// </summary> /// <param name="userID">UserID</param> /// <returns>UserInfo object</returns> public UserInfo SelectByID(int userID) { var userInfo = new UserInfo(); try { var parameters = new SqlParameter[1]; parameters[0] = new SqlParameter("@UserID", userID); var dataTable = _dbConnection.ExecuteSelectQuery(ConstantInfo.SP_SELECTUSERBYID, parameters); if (dataTable.Rows.Count == 1) { userInfo.CreateFrom(dataTable.Rows[0]); } return userInfo; } catch (Exception) { throw; } }
/// <summary> /// Select all user /// </summary> /// <returns></returns> public List<UserInfo> SelectAll() { var result = new List<UserInfo>(); UserInfo userInfo; try { var dataTable = _dbConnection.ExecuteSelectQuery(ConstantInfo.SP_SELECTALLUSER); foreach (DataRow dr in dataTable.Rows) { userInfo = new UserInfo(); userInfo.CreateFrom(dr); userInfo.UserName = userInfo.UserName; result.Add(userInfo); } return result; } catch (Exception ex) { throw ex; } }