mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
96 lines
2.5 KiB
C#
96 lines
2.5 KiB
C#
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
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="id">Id of the device you want to get informatiun</param>
|
|
[HttpGet]
|
|
public ActionResult<List<Device>> GetAllDevices()
|
|
{
|
|
return _DeviceService.GetAll();
|
|
}
|
|
|
|
// GET: Device
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="idDevice">Id of the device you want to get information</param>
|
|
[HttpGet("{idDevice}")]
|
|
public ActionResult<Device> GetDeviceInfo(string idDevice)
|
|
{
|
|
return _DeviceService.GetDeviceInfo(idDevice);
|
|
}
|
|
|
|
// POST: Device/Create
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[HttpPost]
|
|
public IActionResult CreateDevice(int idDevice, [FromBody] Device device)
|
|
{
|
|
if (idDevice == 0)
|
|
{
|
|
_DeviceService.CreateDevice(device);
|
|
|
|
return StatusCode(201);
|
|
}
|
|
return StatusCode(500);
|
|
}
|
|
|
|
// PUT: Device/Update
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[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
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[HttpDelete("{idDevice}")]
|
|
public IActionResult DeleteDevice(int idDevice, [FromBody] string deviceId)
|
|
{
|
|
if (idDevice == 0)
|
|
{
|
|
_DeviceService.Remove(deviceId);
|
|
|
|
return StatusCode(201);
|
|
}
|
|
return StatusCode(500);
|
|
}
|
|
}
|
|
} |