From efc3555b0cc3ddeb0404abcbc7030627617c9719 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Thu, 23 Nov 2017 10:55:32 +0100 Subject: Changed the way data is being get from database. --- AirPollutionWebApi.userprefs | 4 ++-- .../Controllers/ReadingsController.cs | 3 ++- AirPollutionWebApi/Models/Reading.cs | 3 ++- AirPollutionWebApi/Singletons/Singleton.cs | 26 +++++++++++++-------- AirPollutionWebApi/bin/AirPollutionWebApi.dll | Bin 11776 -> 11776 bytes AirPollutionWebApi/bin/AirPollutionWebApi.pdb | Bin 2512 -> 2568 bytes .../obj/Debug/AirPollutionWebApi.dll | Bin 11776 -> 11776 bytes .../obj/Debug/AirPollutionWebApi.pdb | Bin 2512 -> 2568 bytes 8 files changed, 22 insertions(+), 14 deletions(-) diff --git a/AirPollutionWebApi.userprefs b/AirPollutionWebApi.userprefs index 22153ef..6cd10e6 100644 --- a/AirPollutionWebApi.userprefs +++ b/AirPollutionWebApi.userprefs @@ -11,8 +11,8 @@ - - + + diff --git a/AirPollutionWebApi/Controllers/ReadingsController.cs b/AirPollutionWebApi/Controllers/ReadingsController.cs index 3ffe624..c8c8087 100644 --- a/AirPollutionWebApi/Controllers/ReadingsController.cs +++ b/AirPollutionWebApi/Controllers/ReadingsController.cs @@ -14,7 +14,8 @@ namespace AirPollutionWebApi.Controllers public ReadingsController() { } public IEnumerable GetAllReadings() - { + { + Singleton.Instance.GetData(); return Singleton.Instance.Readings; } diff --git a/AirPollutionWebApi/Models/Reading.cs b/AirPollutionWebApi/Models/Reading.cs index b829711..4880659 100644 --- a/AirPollutionWebApi/Models/Reading.cs +++ b/AirPollutionWebApi/Models/Reading.cs @@ -4,7 +4,8 @@ namespace AirPollutionWebApi.Models { public class Reading { - public DateTime TimeStamp { get; set; } + public int Id { get; set; } + public int TimeStamp { get; set; } public int Co { get; set; } public int No { get; set; } public int So { get; set; } 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 Readings = new List(); - Singleton() - { - GetData(); - } + Singleton() {} public static Singleton Instance { @@ -29,7 +34,7 @@ namespace AirPollutionWebApi.Singletons } } - void GetData() + public void GetData() { Readings = new List(); 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) }); } } diff --git a/AirPollutionWebApi/bin/AirPollutionWebApi.dll b/AirPollutionWebApi/bin/AirPollutionWebApi.dll index 1a26a51..ef89550 100644 Binary files a/AirPollutionWebApi/bin/AirPollutionWebApi.dll and b/AirPollutionWebApi/bin/AirPollutionWebApi.dll differ diff --git a/AirPollutionWebApi/bin/AirPollutionWebApi.pdb b/AirPollutionWebApi/bin/AirPollutionWebApi.pdb index 1afaefb..05ea137 100644 Binary files a/AirPollutionWebApi/bin/AirPollutionWebApi.pdb and b/AirPollutionWebApi/bin/AirPollutionWebApi.pdb differ diff --git a/AirPollutionWebApi/obj/Debug/AirPollutionWebApi.dll b/AirPollutionWebApi/obj/Debug/AirPollutionWebApi.dll index 1a26a51..ef89550 100644 Binary files a/AirPollutionWebApi/obj/Debug/AirPollutionWebApi.dll and b/AirPollutionWebApi/obj/Debug/AirPollutionWebApi.dll differ diff --git a/AirPollutionWebApi/obj/Debug/AirPollutionWebApi.pdb b/AirPollutionWebApi/obj/Debug/AirPollutionWebApi.pdb index 1afaefb..05ea137 100644 Binary files a/AirPollutionWebApi/obj/Debug/AirPollutionWebApi.pdb and b/AirPollutionWebApi/obj/Debug/AirPollutionWebApi.pdb differ -- cgit v1.2.3