You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/Platform/Api/SceneController.cs

64 lines
1.9 KiB

using Infrastructure.Data;
using Infrastructure.Extensions;
using IoT.Shared.Application.Domain.Entities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
namespace Platform.Apis.Controllers
{
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]/[action]")]
[ApiController]
public class SceneController : ControllerBase
{
private readonly IRepository<IoTScene> _sceneRepo;
public SceneController(IRepository<IoTScene> sceneRepo)
{
this._sceneRepo = sceneRepo;
}
[HttpPost]
public ActionResult GetScenes(Guid? organId)
{
try
{
var model = this._sceneRepo.ReadOnlyTable()
.Include(o => o.Building).ThenInclude(o=>o.Organ)
.WhereIf(organId.HasValue, o => o.Building.OrganId == organId.Value)
.Where(o => !o.Hidden)
.OrderBy(o => o.DisplayOrder);
return Ok(model);
}
catch (Exception ex)
{
ex.PrintStack();
return Problem(ex.Message);
}
}
[HttpPost]
public ActionResult GetScene([Required(ErrorMessage = nameof(RequiredAttribute))] Guid id)
{
try
{
var model = this._sceneRepo.ReadOnlyTable()
.Include(o => o.IoTSceneIoTCommands)
.Include(o => o.IoTTimers)
.Include(o => o.IoTTiggers)
.Where(o => o.Id == id)
.FirstOrDefault();
return Ok(model);
}
catch (Exception ex)
{
ex.PrintStack();
return Problem(ex.Message);
}
}
}
}