using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace InterviewTest { public class Data { SqlConnection _dbConn = new SqlConnection(); SqlCommand _dbCommand = new SqlCommand(); SqlDataReader _dbReader; SqlDataAdapter _dbAdapter; string _connectionString = "Server=localhost;Database=test;Trusted_Connection=True;"; public DataSet GetDataset(string CommandText, bool IsStoredProcedure) { DataSet ds = new DataSet(); try { _dbConn.ConnectionString = _connectionString; _dbConn.Open(); _dbCommand.Connection = _dbConn; _dbCommand.CommandText = CommandText; _dbCommand.Parameters.Clear(); if (!IsStoredProcedure) { _dbCommand.CommandType = System.Data.CommandType.Text; } else { _dbCommand.CommandType = System.Data.CommandType.StoredProcedure; } _dbAdapter = new System.Data.SqlClient.SqlDataAdapter(_dbCommand); _dbAdapter.Fill(ds); return ds; } catch (Exception ex) { throw ex; } finally { _dbConn.Close(); } } public bool ContainsUppercase(string Value) { return Value.Any(x => char.IsUpper(x)); } } public static class Extension { /// /// Determines if the current dataset contains at least one table with at least one record /// /// DataSet to process /// public static bool HasData(this DataSet ds) { if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) return true; return false; } } }