Files
cms_thermo_active/Thermo.Active/Controllers/WebApi/ModulesController.cs
T
2020-06-19 19:28:07 +02:00

38 lines
1.3 KiB
C#

using CMS_CORE_Library.Models;
using System.Collections.Generic;
using System.Web.Http;
using Thermo.Active.Model.DTOModels.ThModules;
using Thermo.Active.NC;
using Thermo.Active.Utils;
namespace Thermo.Active.Controllers.WebApi
{
[RoutePrefix("api/ModBlock")]
public class ModulesController : ApiController
{
[Route("current"), HttpGet]
public IHttpActionResult GetCurrentModules()
{
using (NcAdapter ncAdapter = new NcAdapter())
{
// Try connection
CmsError libraryError = ncAdapter.Connect();
if (libraryError.errorCode != 0)
{
ThermoActiveLogger.LogError($"NC Not connected! | GetCurrentModules | {libraryError.exception}");
return InternalServerError();
}
libraryError = ncAdapter.ReadModulesBlock(out Dictionary<int, DTOModulesBlock> currModules);
if (libraryError.IsError())
{
ThermoActiveLogger.LogError($"GetRecipeOverview error | {libraryError.exception}");
return BadRequest(libraryError.localizationKey);
}
return Ok(currModules);
}
}
}
}