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]
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);
}
}
}