Files
cms_thermo_active/Thermo.Active/Controllers/WebApi/ModulesController.cs
T
2021-03-23 12:09:10 +01:00

42 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 : aBaseApiController // ApiController
{
#if false
/// <summary>
/// Oggetto adapter condiviso da WebAPI
/// </summary>
protected static NcAdapter ncAdapter = new NcAdapter();
#endif
[Route("current"), HttpGet]
public IHttpActionResult GetCurrentModules()
{
// 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);
}
}
}