public HttpResponseMessage ReadAll()
        {
            // CAD, CEN, EN, returnValue
            EventTelemetryRESTCAD eventTelemetryRESTCAD = null;
            EventTelemetryCEN     eventTelemetryCEN     = null;

            List <EventTelemetryEN>   eventTelemetryEN = null;
            List <EventTelemetryDTOA> returnValue      = null;

            try
            {
                SessionInitializeWithoutTransaction();


                eventTelemetryRESTCAD = new EventTelemetryRESTCAD(session);
                eventTelemetryCEN     = new EventTelemetryCEN(eventTelemetryRESTCAD);

                // Data
                // TODO: paginación

                eventTelemetryEN = eventTelemetryCEN.ReadAll(0, -1).ToList();

                // Convert return
                if (eventTelemetryEN != null)
                {
                    returnValue = new List <EventTelemetryDTOA>();
                    foreach (EventTelemetryEN entry in eventTelemetryEN)
                    {
                        returnValue.Add(EventTelemetryAssembler.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 New_([FromBody] EventTelemetryDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            EventTelemetryRESTCAD eventTelemetryRESTCAD = null;
            EventTelemetryCEN     eventTelemetryCEN     = null;
            EventTelemetryDTOA    returnValue           = null;
            int returnOID = -1;

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

            try
            {
                SessionInitializeTransaction();


                eventTelemetryRESTCAD = new EventTelemetryRESTCAD(session);
                eventTelemetryCEN     = new EventTelemetryCEN(eventTelemetryRESTCAD);

                // Create
                returnOID = eventTelemetryCEN.New_(

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

                    , dto.Name                            //Atributo Primitivo: p_name
                    , dto.Severity                        //Atributo Primitivo: p_severity
                    );
                SessionCommit();

                // Convert return
                returnValue = EventTelemetryAssembler.Convert(eventTelemetryRESTCAD.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("GetOIDEventTelemetry", routeValues);
             * response.Headers.Location = new Uri(uri);
             */

            return(response);
        }
        public HttpResponseMessage Modify(int idEventTelemetry, [FromBody] EventTelemetryDTO dto)
        {
            // CAD, CEN, returnValue
            EventTelemetryRESTCAD eventTelemetryRESTCAD = null;
            EventTelemetryCEN     eventTelemetryCEN     = null;
            EventTelemetryDTOA    returnValue           = null;

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

            try
            {
                SessionInitializeTransaction();


                eventTelemetryRESTCAD = new EventTelemetryRESTCAD(session);
                eventTelemetryCEN     = new EventTelemetryCEN(eventTelemetryRESTCAD);

                // Modify
                eventTelemetryCEN.Modify(idEventTelemetry,
                                         dto.Name
                                         ,
                                         dto.Severity
                                         );

                // Return modified object
                returnValue = EventTelemetryAssembler.Convert(eventTelemetryRESTCAD.ReadOIDDefault(idEventTelemetry), 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 ReadOID(int idEventTelemetry)
        {
            // CAD, CEN, EN, returnValue
            EventTelemetryRESTCAD eventTelemetryRESTCAD = null;
            EventTelemetryCEN     eventTelemetryCEN     = null;
            EventTelemetryEN      eventTelemetryEN      = null;
            EventTelemetryDTOA    returnValue           = null;

            try
            {
                SessionInitializeWithoutTransaction();


                eventTelemetryRESTCAD = new EventTelemetryRESTCAD(session);
                eventTelemetryCEN     = new EventTelemetryCEN(eventTelemetryRESTCAD);

                // Data
                eventTelemetryEN = eventTelemetryCEN.ReadOID(idEventTelemetry);

                // Convert return
                if (eventTelemetryEN != null)
                {
                    returnValue = EventTelemetryAssembler.Convert(eventTelemetryEN, 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));
            }
        }