From 8f083ddb74fb74d6c2b5d347472aa26f18a4b15c Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Thu, 23 Nov 2017 11:19:37 +0100 Subject: Rewrote almost everything, got rid of singleton. --- .../Controllers/ReadingsController.cs | 74 ++++++++++------------ 1 file changed, 35 insertions(+), 39 deletions(-) (limited to 'AirPollutionWebApi/Controllers') diff --git a/AirPollutionWebApi/Controllers/ReadingsController.cs b/AirPollutionWebApi/Controllers/ReadingsController.cs index c8c8087..e8eb0fa 100644 --- a/AirPollutionWebApi/Controllers/ReadingsController.cs +++ b/AirPollutionWebApi/Controllers/ReadingsController.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Http; -using System.Web.Mvc; +using System.Collections.Generic; +using System.Web.Http; using AirPollutionWebApi.Models; using AirPollutionWebApi.Singletons; @@ -15,49 +11,49 @@ namespace AirPollutionWebApi.Controllers public IEnumerable GetAllReadings() { - Singleton.Instance.GetData(); - return Singleton.Instance.Readings; + var readings = SqlOperator.GetAllReadings(); + return readings; } - //public IHttpActionResult GetReading(int id) - //{ - // var customer = Singleton.Instance.Readings.FirstOrDefault((p) => p.TimeStamp == id); - - // if (customer != null) return Ok(customer); - // else return NotFound(); - //} - - //public IHttpActionResult PutReading(int id, Reading customer) - //{ - // if (customer != null) - // { - // Singleton.Instance.PutData(id, customer); - // return Ok(); - // } - // else return BadRequest(); - //} - - public IHttpActionResult PostReading(Reading customer) + public IHttpActionResult GetReading(int id) { - if (customer != null) + var reading = SqlOperator.GetReadingById(id); + + if (reading != null) return Ok(reading); + else return NotFound(); + } + + public IHttpActionResult PutReading(int id, Reading reading) + { + if (reading != null) + { + SqlOperator.PutReading(id, reading); + return Ok(); + } + else return BadRequest(); + } + + public IHttpActionResult PostReading(Reading reading) + { + if (reading != null) { - Singleton.Instance.PostData(customer); + SqlOperator.PostReading(reading); return Ok(); } else return BadRequest(); } - //public IHttpActionResult DeleteReading(int id) - //{ - // Reading customer = Singleton.Instance.Readings.Find((p) => p.Id == id); - // if (customer == null) - // { - // return NotFound(); - // } + public IHttpActionResult DeleteReading(int id) + { + Reading reading = SqlOperator.GetReadingById(id); + if (reading == null) + { + return NotFound(); + } - // Singleton.Instance.DeleteData(id); + SqlOperator.DeleteReading(id); - // return Ok(customer); - //} + return Ok(reading); + } } } \ No newline at end of file -- cgit v1.2.3