diff options
author | marcinzelent <zelent.marcin@gmail.com> | 2017-11-23 10:55:32 +0100 |
---|---|---|
committer | marcinzelent <zelent.marcin@gmail.com> | 2017-11-23 10:55:32 +0100 |
commit | efc3555b0cc3ddeb0404abcbc7030627617c9719 (patch) | |
tree | c2b5c4c8cc74b37a46215e985669a2c1e1282f91 /AirPollutionWebApi/Singletons | |
parent | d5b8f7f8762cd8270a44227f23ce6f7a88ae3eac (diff) |
Changed the way data is being get from database.
Diffstat (limited to 'AirPollutionWebApi/Singletons')
-rw-r--r-- | AirPollutionWebApi/Singletons/Singleton.cs | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/AirPollutionWebApi/Singletons/Singleton.cs b/AirPollutionWebApi/Singletons/Singleton.cs index 5da91ad..00269ad 100644 --- a/AirPollutionWebApi/Singletons/Singleton.cs +++ b/AirPollutionWebApi/Singletons/Singleton.cs @@ -8,14 +8,19 @@ namespace AirPollutionWebApi.Singletons public class Singleton { static Singleton instance; - const string ConnectionString = "Server=tcp:forschool.database.windows.net,1433;Initial Catalog=schooldb;Persist Security Info=False;User ID=***REMOVED***;Password=***REMOVED***;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"; + const string ConnectionString = "Server=tcp:forschool.database.windows.net,1433;" + + "Initial Catalog=schooldb;" + + "Persist Security Info=False;" + + "User ID=***REMOVED***;" + + "Password=***REMOVED***;" + + "MultipleActiveResultSets=False;" + + "Encrypt=True;" + + "TrustServerCertificate=False;" + + "Connection Timeout=30;"; public List<Reading> Readings = new List<Reading>(); - Singleton() - { - GetData(); - } + Singleton() {} public static Singleton Instance { @@ -29,7 +34,7 @@ namespace AirPollutionWebApi.Singletons } } - void GetData() + public void GetData() { Readings = new List<Reading>(); using (SqlConnection databaseConnection = new SqlConnection(ConnectionString)) @@ -42,10 +47,11 @@ namespace AirPollutionWebApi.Singletons { Readings.Add(new Reading { - TimeStamp = reader.GetDateTime(0), - Co = reader.GetInt32(1), - No = reader.GetInt32(2), - So = reader.GetInt32(3) + Id = reader.GetInt32(0), + TimeStamp = reader.GetInt32(1), + Co = reader.GetInt32(2), + No = reader.GetInt32(3), + So = reader.GetInt32(4) }); } } |