public HttpResponseMessage Destroy(int p_disability_oid)
        {
            // CAD, CEN
            DisabilityRESTCAD disabilityRESTCAD = null;
            DisabilityCEN     disabilityCEN     = null;

            try
            {
                SessionInitializeTransaction();


                disabilityRESTCAD = new DisabilityRESTCAD(session);
                disabilityCEN     = new DisabilityCEN(disabilityRESTCAD);

                disabilityCEN.Destroy(p_disability_oid);
                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 204 - No Content
            return(this.Request.CreateResponse(HttpStatusCode.NoContent));
        }
        public static DisabilityDTOA Convert(DisabilityEN en, NHibernate.ISession session = null)
        {
            DisabilityDTOA    dto = null;
            DisabilityRESTCAD disabilityRESTCAD = null;
            DisabilityCEN     disabilityCEN     = null;
            DisabilityCP      disabilityCP      = null;

            if (en != null)
            {
                dto = new DisabilityDTOA();
                disabilityRESTCAD = new DisabilityRESTCAD(session);
                disabilityCEN     = new DisabilityCEN(disabilityRESTCAD);
                disabilityCP      = new DisabilityCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Name = en.Name;


                dto.Type = en.Type;


                dto.Severity = en.Severity;


                dto.Description = en.Description;


                //
                // TravesalLink


                //
                // Service
            }

            return(dto);
        }
        public HttpResponseMessage ReadAll()
        {
            // CAD, CEN, EN, returnValue
            DisabilityRESTCAD disabilityRESTCAD = null;
            DisabilityCEN     disabilityCEN     = null;

            List <DisabilityEN>   disabilityEN = null;
            List <DisabilityDTOA> returnValue  = null;

            try
            {
                SessionInitializeWithoutTransaction();


                disabilityRESTCAD = new DisabilityRESTCAD(session);
                disabilityCEN     = new DisabilityCEN(disabilityRESTCAD);

                // Data
                // TODO: paginación

                disabilityEN = disabilityCEN.ReadAll(0, -1).ToList();

                // Convert return
                if (disabilityEN != null)
                {
                    returnValue = new List <DisabilityDTOA>();
                    foreach (DisabilityEN entry in disabilityEN)
                    {
                        returnValue.Add(DisabilityAssembler.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 Modify(int idDisability, [FromBody] DisabilityDTO dto)
        {
            // CAD, CEN, returnValue
            DisabilityRESTCAD disabilityRESTCAD = null;
            DisabilityCEN     disabilityCEN     = null;
            DisabilityDTOA    returnValue       = null;

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

            try
            {
                SessionInitializeTransaction();


                disabilityRESTCAD = new DisabilityRESTCAD(session);
                disabilityCEN     = new DisabilityCEN(disabilityRESTCAD);

                // Modify
                disabilityCEN.Modify(idDisability,
                                     dto.Name
                                     ,
                                     dto.Type
                                     ,
                                     dto.Severity
                                     ,
                                     dto.Description
                                     );

                // Return modified object
                returnValue = DisabilityAssembler.Convert(disabilityRESTCAD.ReadOIDDefault(idDisability), 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 New_([FromBody] DisabilityDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            DisabilityRESTCAD disabilityRESTCAD = null;
            DisabilityCEN     disabilityCEN     = null;
            DisabilityDTOA    returnValue       = null;
            int returnOID = -1;

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

            try
            {
                SessionInitializeTransaction();


                disabilityRESTCAD = new DisabilityRESTCAD(session);
                disabilityCEN     = new DisabilityCEN(disabilityRESTCAD);

                // Create
                returnOID = disabilityCEN.New_(

                    //Atributo OID: p_patient
                    // attr.estaRelacionado: true
                    dto.Patient_oid                     // association role

                    , dto.Name                          //Atributo Primitivo: p_name
                    , dto.Type                          //Atributo Primitivo: p_type
                    , dto.Severity                      //Atributo Primitivo: p_severity
                    , dto.Description                   //Atributo Primitivo: p_description
                    );
                SessionCommit();

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

            return(response);
        }
        public HttpResponseMessage ReadOID(int idDisability)
        {
            // CAD, CEN, EN, returnValue
            DisabilityRESTCAD disabilityRESTCAD = null;
            DisabilityCEN     disabilityCEN     = null;
            DisabilityEN      disabilityEN      = null;
            DisabilityDTOA    returnValue       = null;

            try
            {
                SessionInitializeWithoutTransaction();


                disabilityRESTCAD = new DisabilityRESTCAD(session);
                disabilityCEN     = new DisabilityCEN(disabilityRESTCAD);

                // Data
                disabilityEN = disabilityCEN.ReadOID(idDisability);

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