public HttpResponseMessage Modify (int idSensorTelemetry, [FromBody] SensorTelemetryDTO dto)
{
        // CAD, CEN, returnValue
        SensorTelemetryRESTCAD sensorTelemetryRESTCAD = null;
        SensorTelemetryCEN sensorTelemetryCEN = null;
        SensorTelemetryDTOA returnValue = null;

        // HTTP response
        HttpResponseMessage response = null;
        string uri = null;

        try
        {
                SessionInitializeTransaction ();


                sensorTelemetryRESTCAD = new SensorTelemetryRESTCAD (session);
                sensorTelemetryCEN = new SensorTelemetryCEN (sensorTelemetryRESTCAD);

                // Modify
                sensorTelemetryCEN.Modify (idSensorTelemetry,
                        dto.Name
                        ,
                        dto.SensorType
                        );

                // Return modified object
                returnValue = SensorTelemetryAssembler.Convert (sensorTelemetryRESTCAD.ReadOIDDefault (idSensorTelemetry), session);

                SessionCommit ();
        }

        catch (Exception e)
        {
                SessionRollBack ();

                if (e.GetType () == typeof(HttpResponseException)) throw e;
                else if (e.GetType () == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals ("El token es incorrecto")) throw new HttpResponseException (HttpStatusCode.Forbidden);
                else if (e.GetType () == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType () == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException)) throw new HttpResponseException (HttpStatusCode.BadRequest);
                else throw new HttpResponseException (HttpStatusCode.InternalServerError);
        }
        finally
        {
                SessionClose ();
        }

        // Return 404 - Not found
        if (returnValue == null)
                return this.Request.CreateResponse (HttpStatusCode.NotFound);
        // Return 200 - OK
        else{
                response = this.Request.CreateResponse (HttpStatusCode.OK, returnValue);

                return response;
        }
}
public HttpResponseMessage ReadAll ()
{
        // CAD, CEN, EN, returnValue
        SensorTelemetryRESTCAD sensorTelemetryRESTCAD = null;
        SensorTelemetryCEN sensorTelemetryCEN = null;

        List<SensorTelemetryEN> sensorTelemetryEN = null;
        List<SensorTelemetryDTOA> returnValue = null;

        try
        {
                SessionInitializeWithoutTransaction ();


                sensorTelemetryRESTCAD = new SensorTelemetryRESTCAD (session);
                sensorTelemetryCEN = new SensorTelemetryCEN (sensorTelemetryRESTCAD);

                // Data
                // TODO: paginación

                sensorTelemetryEN = sensorTelemetryCEN.ReadAll (0, -1).ToList ();

                // Convert return
                if (sensorTelemetryEN != null) {
                        returnValue = new List<SensorTelemetryDTOA>();
                        foreach (SensorTelemetryEN entry in sensorTelemetryEN)
                                returnValue.Add (SensorTelemetryAssembler.Convert (entry, session));
                }
        }

        catch (Exception e)
        {
                if (e.GetType () == typeof(HttpResponseException)) throw e;
                else if (e.GetType () == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals ("El token es incorrecto")) throw new HttpResponseException (HttpStatusCode.Forbidden);
                else if (e.GetType () == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType () == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException)) throw new HttpResponseException (HttpStatusCode.BadRequest);
                else throw new HttpResponseException (HttpStatusCode.InternalServerError);
        }
        finally
        {
                SessionClose ();
        }

        // Return 204 - Empty
        if (returnValue == null || returnValue.Count == 0)
                return this.Request.CreateResponse (HttpStatusCode.NoContent);
        // Return 200 - OK
        else return this.Request.CreateResponse (HttpStatusCode.OK, returnValue);
}
public HttpResponseMessage ReadOID (int idSensorTelemetry)
{
        // CAD, CEN, EN, returnValue
        SensorTelemetryRESTCAD sensorTelemetryRESTCAD = null;
        SensorTelemetryCEN sensorTelemetryCEN = null;
        SensorTelemetryEN sensorTelemetryEN = null;
        SensorTelemetryDTOA returnValue = null;

        try
        {
                SessionInitializeWithoutTransaction ();


                sensorTelemetryRESTCAD = new SensorTelemetryRESTCAD (session);
                sensorTelemetryCEN = new SensorTelemetryCEN (sensorTelemetryRESTCAD);

                // Data
                sensorTelemetryEN = sensorTelemetryCEN.ReadOID (idSensorTelemetry);

                // Convert return
                if (sensorTelemetryEN != null) {
                        returnValue = SensorTelemetryAssembler.Convert (sensorTelemetryEN, session);
                }
        }

        catch (Exception e)
        {
                if (e.GetType () == typeof(HttpResponseException)) throw e;
                else if (e.GetType () == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals ("El token es incorrecto")) throw new HttpResponseException (HttpStatusCode.Forbidden);
                else if (e.GetType () == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType () == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException)) throw new HttpResponseException (HttpStatusCode.BadRequest);
                else throw new HttpResponseException (HttpStatusCode.InternalServerError);
        }
        finally
        {
                SessionClose ();
        }

        // Return 404 - Not found
        if (returnValue == null)
                return this.Request.CreateResponse (HttpStatusCode.NotFound);
        // Return 200 - OK
        else return this.Request.CreateResponse (HttpStatusCode.OK, returnValue);
}
public HttpResponseMessage New_ ( [FromBody] SensorTelemetryDTO dto)
{
        // CAD, CEN, returnValue, returnOID
        SensorTelemetryRESTCAD sensorTelemetryRESTCAD = null;
        SensorTelemetryCEN sensorTelemetryCEN = null;
        SensorTelemetryDTOA returnValue = null;
        int returnOID = -1;

        // HTTP response
        HttpResponseMessage response = null;
        string uri = null;

        try
        {
                SessionInitializeTransaction ();


                sensorTelemetryRESTCAD = new SensorTelemetryRESTCAD (session);
                sensorTelemetryCEN = new SensorTelemetryCEN (sensorTelemetryRESTCAD);

                // Create
                returnOID = sensorTelemetryCEN.New_ (

                        //Atributo OID: p_telemetry
                        // attr.estaRelacionado: true
                        dto.Telemetry_oid                 // association role

                        , dto.Name                                                                                                                                                       //Atributo Primitivo: p_name
                        , dto.SensorType                                                                                                                                                 //Atributo Primitivo: p_sensorType
                        );
                SessionCommit ();

                // Convert return
                returnValue = SensorTelemetryAssembler.Convert (sensorTelemetryRESTCAD.ReadOIDDefault (returnOID), session);
        }

        catch (Exception e)
        {
                SessionRollBack ();

                if (e.GetType () == typeof(HttpResponseException)) throw e;
                else if (e.GetType () == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals ("El token es incorrecto")) throw new HttpResponseException (HttpStatusCode.Forbidden);
                else if (e.GetType () == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType () == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException)) throw new HttpResponseException (HttpStatusCode.BadRequest);
                else throw new HttpResponseException (HttpStatusCode.InternalServerError);
        }
        finally
        {
                SessionClose ();
        }

        // Return 201 - Created
        response = this.Request.CreateResponse (HttpStatusCode.Created, returnValue);

        // Location Header
        /*
         * Dictionary<string, object> routeValues = new Dictionary<string, object>();
         *
         * // TODO: y rolPaths
         * routeValues.Add("id", returnOID);
         *
         * uri = Url.Link("GetOIDSensorTelemetry", routeValues);
         * response.Headers.Location = new Uri(uri);
         */

        return response;
}