mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 09:41:19 +00:00
124 lines
3.4 KiB
C#
124 lines
3.4 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/screen")]
|
|
[ApiController]
|
|
public class ScreenDeviceController : ControllerBase
|
|
{
|
|
private readonly ScreenDeviceService _ScreenDeviceService;
|
|
|
|
public ScreenDeviceController(ScreenDeviceService ScreenDeviceService)
|
|
{
|
|
_ScreenDeviceService = ScreenDeviceService;
|
|
}
|
|
|
|
// GET: Devices
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[ProducesResponseType(typeof(List<ScreenDevice>), 200)]
|
|
[HttpGet]
|
|
public ObjectResult GetAllScreenDevices()
|
|
{
|
|
try
|
|
{
|
|
List<ScreenDevice> screenDevices = _ScreenDeviceService.GetAll();
|
|
|
|
return new OkObjectResult(screenDevices);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
// GET: ScreenDevice
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="idScreenDevice">Id of the screen device you want to get information</param>
|
|
[ProducesResponseType(typeof(ScreenDevice), 200)]
|
|
[HttpGet("{idScreenDevice}")]
|
|
public ObjectResult GetDeviceInfo(string idScreenDevice)
|
|
{
|
|
try
|
|
{
|
|
ScreenDevice screenDevice = _ScreenDeviceService.GetInfo(idScreenDevice);
|
|
|
|
return new OkObjectResult(screenDevice);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
// POST: Device/Create
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[HttpPost]
|
|
public ObjectResult CreateDevice([FromBody] ScreenDevice screenDevice)
|
|
{
|
|
try
|
|
{
|
|
_ScreenDeviceService.Create(screenDevice);
|
|
|
|
return new OkObjectResult(201);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
// PUT: Device/Update
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[HttpPut("{idScreenDevice}")]
|
|
public ObjectResult UpdateDevice(int idScreenDevice, [FromBody] ScreenDevice screenDevice)
|
|
{
|
|
try
|
|
{
|
|
_ScreenDeviceService.Update(screenDevice.Id, screenDevice);
|
|
|
|
return new OkObjectResult(201);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
// Delete: Device/Delete
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[HttpDelete("{idDevice}")]
|
|
public ObjectResult DeleteDevice(int idDevice, [FromBody] string deviceId)
|
|
{
|
|
try
|
|
{
|
|
_ScreenDeviceService.Remove(deviceId);
|
|
|
|
return new OkObjectResult(201);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
}
|
|
} |