diff options
Diffstat (limited to 'AirPollutionWebApi/Controllers')
-rw-r--r-- | AirPollutionWebApi/Controllers/HomeController.cs | 23 | ||||
-rw-r--r-- | AirPollutionWebApi/Controllers/ReadingsController.cs | 88 |
2 files changed, 0 insertions, 111 deletions
diff --git a/AirPollutionWebApi/Controllers/HomeController.cs b/AirPollutionWebApi/Controllers/HomeController.cs deleted file mode 100644 index 6a83056..0000000 --- a/AirPollutionWebApi/Controllers/HomeController.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Web; -using System.Web.Mvc; -using System.Web.Mvc.Ajax; - -namespace AirPollutionWebApi.Controllers -{ - public class HomeController : Controller - { - public ActionResult Index() - { - var mvcName = typeof(Controller).Assembly.GetName(); - var isMono = Type.GetType("Mono.Runtime") != null; - - ViewData["Version"] = mvcName.Version.Major + "." + mvcName.Version.Minor; - ViewData["Runtime"] = isMono ? "Mono" : ".NET"; - - return View(); - } - } -} diff --git a/AirPollutionWebApi/Controllers/ReadingsController.cs b/AirPollutionWebApi/Controllers/ReadingsController.cs deleted file mode 100644 index 99965e6..0000000 --- a/AirPollutionWebApi/Controllers/ReadingsController.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System;
-using System.Web.Http;
-using AirPollutionWebApi.Models; -using AirPollutionWebApi.Singletons; - -namespace AirPollutionWebApi.Controllers
-{
- public class ReadingsController : ApiController
- { - public ReadingsController() { } - - public IHttpActionResult GetAllReadings() - {
- var command = "SELECT * FROM Readings";
- var readings = SqlOperator.GetReadings(command); - - if (readings.Count > 0) return Ok(readings);
- else return NotFound(); - } - - public IHttpActionResult GetReading(int id) - {
- var command = $"SELECT * FROM Readings WHERE Id={id}"; - var reading = SqlOperator.GetReadings(command)[0]; - - if (reading != null) return Ok(reading); - else return NotFound(); - }
-
- [Route("api/Readings/latest")]
- public IHttpActionResult GetLatestReading()
- { - var command = "SELECT * FROM Readings " +
- "WHERE TimeStamp IN(SELECT MAX(TimeStamp) FROM Readings)"; - var reading = SqlOperator.GetReadings(command)[0]; - - if (reading != null) return Ok(reading); - else return NotFound();
- } -
- [Route("api/Readings/lastweek")] - public IHttpActionResult GetReadingsFromLastWeek() - {
- var timeNow = DateTimeOffset.Now.ToUnixTimeSeconds(); - var command = "SELECT * FROM Readings " +
- $"WHERE TimeStamp BETWEEN {timeNow-7*24*3600} AND {timeNow}"; - var readings = SqlOperator.GetReadings(command); - - if (readings.Count > 0) return Ok(readings); - 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) - { - SqlOperator.PostReading(reading); - return Ok(); - } - else return BadRequest(); - } - - public IHttpActionResult DeleteReading(int id) - {
- var command = $"SELECT * FROM Readings WHERE Id={id}";
- - Reading reading = SqlOperator.GetReadings(command)[0]; - if (reading == null) - { - return NotFound(); - } - - SqlOperator.DeleteReading(id); - - return Ok(reading); - }
- }
-}
\ No newline at end of file |