Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using Microsoft.AspNetCore.Mvc;
using Public_API.Server.DAL;
using Public_API.Shared.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace Public_API.Server.Controllers
{
[Route("[controller]")]
[ApiController]
public class APIController : ControllerBase
{
ApiContext db = new ApiContext();
// GET: api/<APIController>
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/sensor/logValue/...
[HttpGet("sensor/logValue/{sensorID}/{temperature}/{humidity}/{co2}/{ppm25}")]
public string Get(int sensorID, string temperature, string humidity, string co2, string ppm25)
{
// TODO Error Handling!
SensorValue sensorValue = new SensorValue(sensorID, decimal.Parse(temperature), decimal.Parse(humidity), decimal.Parse(co2), decimal.Parse(ppm25));
db.SensorValue.Add(sensorValue);
db.SaveChanges();
return "Got value from " + sensorID + ". Sorted with ID " + sensorValue.valueID;
}
// POST api/<APIController>
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/<APIController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<APIController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}