public static IMMedicationDTOA Convert(EntityAttributesEN en, NHibernate.ISession session = null)
        {
            IMMedicationDTOA    dto = null;
            IMMedicationRESTCAD iMMedicationRESTCAD = null;
            IMMedicationCEN     iMMedicationCEN     = null;
            IMMedicationCP      iMMedicationCP      = null;

            if (en != null)
            {
                dto = new IMMedicationDTOA();
                iMMedicationRESTCAD = new IMMedicationRESTCAD(session);
                iMMedicationCEN     = new IMMedicationCEN(iMMedicationRESTCAD);
                iMMedicationCP      = new IMMedicationCP(session);


                IMMedicationEN enHijo = iMMedicationRESTCAD.ReadOIDDefault(en.Id);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Name = en.Name;


                dto.Description = en.Description;


                //
                // TravesalLink

                /* Rol: IMMedication o--> Medication */
                dto.ValueMedication = MedicationAssembler.Convert((MedicationEN)enHijo.Medication, session);


                //
                // Service
            }

            return(dto);
        }
        public HttpResponseMessage New_([FromBody] IMMedicationDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            IMMedicationRESTCAD iMMedicationRESTCAD = null;
            IMMedicationCEN     iMMedicationCEN     = null;
            IMMedicationDTOA    returnValue         = null;
            int returnOID = -1;

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

            try
            {
                SessionInitializeTransaction();


                iMMedicationRESTCAD = new IMMedicationRESTCAD(session);
                iMMedicationCEN     = new IMMedicationCEN(iMMedicationRESTCAD);

                // Create
                returnOID = iMMedicationCEN.New_(
                    dto.Name                                                                                     //Atributo Primitivo: p_name
                    , dto.Type                                                                                   //Atributo Primitivo: p_type
                    , dto.IsOID                                                                                  //Atributo Primitivo: p_isOID
                    , dto.IsWritable                                                                             //Atributo Primitivo: p_isWritable
                    , dto.Description                                                                            //Atributo Primitivo: p_description
                    ,
                    //Atributo OID: p_entity
                    // attr.estaRelacionado: true
                    dto.Entity_oid                     // association role

                    , dto.Value                        //Atributo Primitivo: p_value
                    ,
                    //Atributo OID: p_medication
                    // attr.estaRelacionado: true
                    dto.Medication_oid                     // association role

                    );
                SessionCommit();

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

            return(response);
        }
        public HttpResponseMessage Modify(int idIMMedication, [FromBody] IMMedicationDTO dto)
        {
            // CAD, CEN, returnValue
            IMMedicationRESTCAD iMMedicationRESTCAD = null;
            IMMedicationCEN     iMMedicationCEN     = null;
            IMMedicationDTOA    returnValue         = null;

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

            try
            {
                SessionInitializeTransaction();


                iMMedicationRESTCAD = new IMMedicationRESTCAD(session);
                iMMedicationCEN     = new IMMedicationCEN(iMMedicationRESTCAD);

                // Modify
                iMMedicationCEN.Modify(idIMMedication,
                                       dto.Name
                                       ,
                                       dto.Type
                                       ,
                                       dto.IsOID
                                       ,
                                       dto.IsWritable
                                       ,
                                       dto.Description
                                       ,
                                       dto.Value
                                       );

                // Return modified object
                returnValue = IMMedicationAssembler.Convert(iMMedicationRESTCAD.ReadOIDDefault(idIMMedication), 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 idIMMedication)
        {
            // CAD, CEN, EN, returnValue
            IMMedicationRESTCAD iMMedicationRESTCAD = null;
            IMMedicationCEN     iMMedicationCEN     = null;
            IMMedicationEN      iMMedicationEN      = null;
            IMMedicationDTOA    returnValue         = null;

            try
            {
                SessionInitializeWithoutTransaction();


                iMMedicationRESTCAD = new IMMedicationRESTCAD(session);
                iMMedicationCEN     = new IMMedicationCEN(iMMedicationRESTCAD);

                // Data
                iMMedicationEN = iMMedicationCEN.ReadOID(idIMMedication);

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