using Infrastructure.Data; using Infrastructure.Extensions; using 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 _sceneRepo; public SceneController(IRepository 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.Order); 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); } } } }