diff --git a/.vs/MyCore/v15/Server/sqlite3/storage.ide b/.vs/MyCore/v15/Server/sqlite3/storage.ide index cb961c9..f3798b7 100644 Binary files a/.vs/MyCore/v15/Server/sqlite3/storage.ide and b/.vs/MyCore/v15/Server/sqlite3/storage.ide differ diff --git a/.vs/MyCore/v15/Server/sqlite3/storage.ide-shm b/.vs/MyCore/v15/Server/sqlite3/storage.ide-shm index 9e8da61..7f814d3 100644 Binary files a/.vs/MyCore/v15/Server/sqlite3/storage.ide-shm and b/.vs/MyCore/v15/Server/sqlite3/storage.ide-shm differ diff --git a/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal b/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal index 9d5ea97..9348df4 100644 Binary files a/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal and b/.vs/MyCore/v15/Server/sqlite3/storage.ide-wal differ diff --git a/MyCore/Controllers/DeviceController.cs b/MyCore/Controllers/DeviceController.cs new file mode 100644 index 0000000..e05d5f6 --- /dev/null +++ b/MyCore/Controllers/DeviceController.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using MongoDB.Bson; +using MyCore.Models; +using MyCore.Services; + +namespace MyCore.Controllers +{ + [Authorize(Roles = "Admin")] + [Route("api/device")] + [ApiController] + public class DeviceController : ControllerBase + { + private readonly DeviceService _DeviceService; + + public DeviceController(DeviceService DeviceService) + { + _DeviceService = DeviceService; + } + + // GET: Devices + /// + /// + /// + /// Id of the device you want to get informatiun + [HttpGet] + public ActionResult> GetAllDevices() + { + return _DeviceService.GetAll(); + } + + // GET: Device + /// + /// + /// + /// Id of the device you want to get information + [HttpGet("{idDevice}")] + public ActionResult GetDeviceInfo(string idDevice) + { + return _DeviceService.GetDeviceInfo(idDevice); + } + + // POST: Device/Create + /// + /// + /// + [HttpPost("{idDevice}")] + public IActionResult CreateDevice(int idDevice, [FromBody] Device device) + { + if (idDevice == 0) + { + _DeviceService.CreateDevice(device); + + return StatusCode(201); + } + return StatusCode(500); + } + + // PUT: Device/Update + /// + /// + /// + [HttpPut("{idDevice}")] + public IActionResult UpdateDevice(int idDevice, [FromBody] Device device) + { + if (idDevice == 0) + { + _DeviceService.Update(device.Id, device); + + return StatusCode(201); + } + return StatusCode(500); + } + + // Delete: Device/Delete + /// + /// + /// + [HttpDelete("{idDevice}")] + public IActionResult DeleteDevice(int idDevice, [FromBody] string deviceId) + { + if (idDevice == 0) + { + _DeviceService.Remove(deviceId); + + return StatusCode(201); + } + return StatusCode(500); + } + } +} \ No newline at end of file diff --git a/MyCore/Controllers/ValuesController.cs b/MyCore/Controllers/ValuesController.cs index f4300a7..cbc5fd0 100644 --- a/MyCore/Controllers/ValuesController.cs +++ b/MyCore/Controllers/ValuesController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc; using MQTTnet; using MQTTnet.Client; using MQTTnet.Server; +using MyCore.Models; namespace MyCore.Controllers { @@ -24,6 +25,8 @@ namespace MyCore.Controllers [HttpGet] public ActionResult> Get() { + WidgetWeather widgetWeather = new WidgetWeather(); + return new string[] { "value1", "value2" }; } diff --git a/MyCore/Models/Device.cs b/MyCore/Models/Device.cs new file mode 100644 index 0000000..7700812 --- /dev/null +++ b/MyCore/Models/Device.cs @@ -0,0 +1,36 @@ +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyCore.Models +{ + public class Device + { + [BsonId] + [BsonRepresentation(BsonType.ObjectId)] + public string Id { get; set; } + + [BsonElement("Name")] + public string Name { get; set; } + + [BsonElement("Type")] + public string Type { get; set; } + + [BsonElement("Location")] + public string Location { get; set; } + + [BsonElement("LocationExplanation")] + public string LocationExplanation { get; set; } + + [BsonElement("Height")] + public int Height { get; set; } + + [BsonElement("Width")] + public int Width { get; set; } + } +} + + diff --git a/MyCore/Models/ScreenConfiguration.cs b/MyCore/Models/ScreenConfiguration.cs new file mode 100644 index 0000000..b70fc6b --- /dev/null +++ b/MyCore/Models/ScreenConfiguration.cs @@ -0,0 +1,31 @@ +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyCore.Models +{ + public class ScreenConfiguration + { + [BsonId] + [BsonRepresentation(BsonType.ObjectId)] + public string Id { get; set; } + + [BsonElement("Name")] + public string Name { get; set; } + + [BsonElement("Type")] + public string Type { get; set; } + + [BsonElement("Widgets")] + public Widget[] Widgets { get; set; } + + [BsonElement("Height")] + public int Height { get; set; } + + [BsonElement("Width")] + public int Width { get; set; } + } +} diff --git a/MyCore/Models/UserInfo.cs b/MyCore/Models/UserInfo.cs index eae1223..26b4974 100644 --- a/MyCore/Models/UserInfo.cs +++ b/MyCore/Models/UserInfo.cs @@ -17,8 +17,8 @@ namespace MyCore.Models [BsonElement("Role")] public string Role { get; set; } - [BsonElement("Username")] - public string Username { get; set; } + [BsonElement("Email")] + public string Email { get; set; } // UNIQUE !.. [BsonElement("Password")] public string Password { get; set; } @@ -34,6 +34,31 @@ namespace MyCore.Models [BsonElement("Birthday")] public string Birthday { get; set; } + + [BsonElement("Address")] + public string Address { get; set; } + + [BsonElement("City")] + public string City { get; set; } + + [BsonElement("State")] + public string State { get; set; } + + [BsonElement("Language")] + public string Language { get; set; } + + [BsonElement("TimeZone")] + public string TimeZone { get; set; } + + [BsonElement("PostalCode")] + public int PostalCode { get; set; } + + [BsonElement("ScreenConfigurationIds")] + public int[] ScreenConfigurationIds { get; set; } + + [BsonElement("DeviceIds")] + public int[] DeviceIds { get; set; } + } } diff --git a/MyCore/Models/Widget.cs b/MyCore/Models/Widget.cs new file mode 100644 index 0000000..5044ea4 --- /dev/null +++ b/MyCore/Models/Widget.cs @@ -0,0 +1,53 @@ +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + + +namespace MyCore.Models +{ + public class Widget + { + [BsonId] + [BsonRepresentation(BsonType.ObjectId)] + public string Id { get; set; } + + [BsonElement("Name")] + public string Name { get; set; } + + [BsonElement("DisplayName")] + public string DisplayName { get; set; } + + [BsonElement("Type")] + public string Type { get; set; } + + [BsonElement("Activated")] + public bool Activated { get; set; } + + [BsonElement("Form")] + public string Form { get; set; } + + [BsonElement("Font")] + public string Font { get; set; } + + [BsonElement("Color")] + public string Color { get; set; } + + [BsonElement("Size")] + public string Size { get; set; } + + [BsonElement("Width")] + public int Width { get; set; } + + [BsonElement("Height")] + public int Height { get; set; } + + [BsonElement("PositionX")] + public int PositionX { get; set; } + + [BsonElement("PositionY")] + public int PositionY { get; set; } + } +} diff --git a/MyCore/Models/WidgetAgenda.cs b/MyCore/Models/WidgetAgenda.cs new file mode 100644 index 0000000..4388938 --- /dev/null +++ b/MyCore/Models/WidgetAgenda.cs @@ -0,0 +1,20 @@ +using MongoDB.Bson.Serialization.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyCore.Models +{ + public class WidgetAgenda : Widget + { + [BsonElement("Provider")] + public string Provider { get; set; } + + [BsonElement("Link")] + public string Link { get; set; } // ? + + [BsonElement("ApiKey")] + public string ApiKey { get; set; } // ? + } +} diff --git a/MyCore/Models/WidgetHourAndDate.cs b/MyCore/Models/WidgetHourAndDate.cs new file mode 100644 index 0000000..746acef --- /dev/null +++ b/MyCore/Models/WidgetHourAndDate.cs @@ -0,0 +1,14 @@ +using MongoDB.Bson.Serialization.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyCore.Models +{ + public class WidgetHourAndDate : Widget + { + [BsonElement("Timezone")] + public string Timezone { get; set; } + } +} diff --git a/MyCore/Models/WidgetMessage.cs b/MyCore/Models/WidgetMessage.cs new file mode 100644 index 0000000..113b3db --- /dev/null +++ b/MyCore/Models/WidgetMessage.cs @@ -0,0 +1,23 @@ +using MongoDB.Bson.Serialization.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyCore.Models +{ + public class WidgetMessage : Widget + { + [BsonElement("Message")] + public string Message { get; set; } + + [BsonElement("Permanent")] + public bool Permanent { get; set; } + + [BsonElement("VisibleDuration")] + public int VisibleDuration { get; set; } + + [BsonElement("Link")] // LINK RSS FEED Motivational message .. ? / Citations etc + public string Link { get; set; } + } +} diff --git a/MyCore/Models/WidgetNews.cs b/MyCore/Models/WidgetNews.cs new file mode 100644 index 0000000..0350ff4 --- /dev/null +++ b/MyCore/Models/WidgetNews.cs @@ -0,0 +1,20 @@ +using MongoDB.Bson.Serialization.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyCore.Models +{ + public class WidgetNews : Widget + { + [BsonElement("Country")] + public string Country { get; set; } + + [BsonElement("Provider")] + public string Provider { get; set; } + + [BsonElement("Speed")] + public string Speed { get; set; } // Or int ? + } +} diff --git a/MyCore/Models/WidgetRadio.cs b/MyCore/Models/WidgetRadio.cs new file mode 100644 index 0000000..44570bf --- /dev/null +++ b/MyCore/Models/WidgetRadio.cs @@ -0,0 +1,17 @@ +using MongoDB.Bson.Serialization.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyCore.Models +{ + public class WidgetRadio : Widget + { + [BsonElement("Provider")] + public string Provider { get; set; } + + [BsonElement("Link")] + public string Link { get; set; } + } +} diff --git a/MyCore/Models/WidgetTraffic.cs b/MyCore/Models/WidgetTraffic.cs new file mode 100644 index 0000000..5be66c8 --- /dev/null +++ b/MyCore/Models/WidgetTraffic.cs @@ -0,0 +1,23 @@ +using MongoDB.Bson.Serialization.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyCore.Models +{ + public class WidgetTraffic : Widget + { + [BsonElement("WorkAddress")] + public string WorkAddress { get; set; } + + [BsonElement("WorkCity")] + public string WorkCity { get; set; } + + [BsonElement("WorkPostCode")] + public string WorkPostCode { get; set; } + + [BsonElement("WorkDays")] + public bool[] WorkDays { get; set; } // [1,1,1,1,1,0,0] + } +} diff --git a/MyCore/Models/WidgetWeather.cs b/MyCore/Models/WidgetWeather.cs new file mode 100644 index 0000000..4e43d66 --- /dev/null +++ b/MyCore/Models/WidgetWeather.cs @@ -0,0 +1,24 @@ +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Attributes; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MyCore.Models +{ + public class WidgetWeather : Widget + { + [BsonElement("City")] + public string City { get; set; } + + [BsonElement("Wind")] + public string Wind { get; set; } + + [BsonElement("Rain")] + public int Rain { get; set; } + + [BsonElement("Nextdays")] + public int Nextdays { get; set; } + } +} diff --git a/MyCore/Services/DeviceService.cs b/MyCore/Services/DeviceService.cs new file mode 100644 index 0000000..5b82283 --- /dev/null +++ b/MyCore/Services/DeviceService.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Collections.Generic; +using System.Linq; +using MyCore.Models; +using Microsoft.Extensions.Configuration; +using MongoDB.Driver; + +namespace MyCore.Services +{ + public class DeviceService + { + private readonly IMongoCollection _devices; + + public DeviceService(IConfiguration config) + { + var client = new MongoClient(config.GetConnectionString("MyCoreDb")); + var database = client.GetDatabase("MyCoreDb"); + _devices = database.GetCollection("Devices"); + } + + public List GetAll() + { + return _devices.Find(m => true).ToList(); + } + + public Device GetDeviceInfo(string id) + { + return _devices.Find(m => m.Id == id).FirstOrDefault(); + } + + public Device CreateDevice(Device device) + { + _devices.InsertOne(device); + return device; + } + + public void Update(string id, Device deviceIn) + { + _devices.ReplaceOne(device => device.Id == id, deviceIn); + } + + public void Remove(Device deviceIn) + { + _devices.DeleteOne(device => device.Id == deviceIn.Id); + } + + public void Remove(string id) + { + _devices.DeleteOne(device => device.Id == id); + } + } +}