diff options
author | marcinzelent <zelent.marcin@gmail.com> | 2017-11-23 11:19:37 +0100 |
---|---|---|
committer | marcinzelent <zelent.marcin@gmail.com> | 2017-11-23 11:19:37 +0100 |
commit | 8f083ddb74fb74d6c2b5d347472aa26f18a4b15c (patch) | |
tree | 0ed80d0f36034ffa5481e219e564548c17fb4909 /AirPollutionWebApi/Controllers/ReadingsController.cs | |
parent | 4d81014947864b39aab3c32000c0b2a9ae0d4461 (diff) |
Rewrote almost everything, got rid of singleton.
Diffstat (limited to 'AirPollutionWebApi/Controllers/ReadingsController.cs')
-rw-r--r-- | AirPollutionWebApi/Controllers/ReadingsController.cs | 74 |
1 files changed, 35 insertions, 39 deletions
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<Reading> 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 |