public static TipoAccionDTOA Convert(TipoAccionEN en, NHibernate.ISession session = null)
        {
            TipoAccionDTOA    dto = null;
            TipoAccionRESTCAD tipoAccionRESTCAD = null;
            TipoAccionCEN     tipoAccionCEN     = null;
            TipoAccionCP      tipoAccionCP      = null;

            if (en != null)
            {
                dto = new TipoAccionDTOA();
                tipoAccionRESTCAD = new TipoAccionRESTCAD(session);
                tipoAccionCEN     = new TipoAccionCEN(tipoAccionRESTCAD);
                tipoAccionCP      = new TipoAccionCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Puntuacion = en.Puntuacion;


                dto.Nombre = en.Nombre;


                //
                // TravesalLink


                //
                // Service
            }

            return(dto);
        }
        public HttpResponseMessage Modificar(int idTipoAccion, [FromBody] TipoAccionDTO dto)
        {
            // CAD, CEN, returnValue
            TipoAccionRESTCAD tipoAccionRESTCAD = null;
            TipoAccionCEN     tipoAccionCEN     = null;
            TipoAccionDTOA    returnValue       = null;

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

            try
            {
                SessionInitializeTransaction();
                string token = "";
                if (Request.Headers.Authorization != null)
                {
                    token = Request.Headers.Authorization.ToString();
                }
                int id = new UsuarioCEN().CheckToken(token);



                tipoAccionRESTCAD = new TipoAccionRESTCAD(session);
                tipoAccionCEN     = new TipoAccionCEN(tipoAccionRESTCAD);

                // Modify
                tipoAccionCEN.Modificar(idTipoAccion,
                                        dto.Puntuacion
                                        ,
                                        dto.Nombre
                                        );

                // Return modified object
                returnValue = TipoAccionAssembler.Convert(tipoAccionRESTCAD.ReadOIDDefault(idTipoAccion), session);

                SessionCommit();
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.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 BuscarPorId(int idTipoAccion)
        {
            // CAD, CEN, EN, returnValue
            TipoAccionRESTCAD tipoAccionRESTCAD = null;
            TipoAccionCEN     tipoAccionCEN     = null;
            TipoAccionEN      tipoAccionEN      = null;
            TipoAccionDTOA    returnValue       = null;

            try
            {
                SessionInitializeWithoutTransaction();
                string token = "";
                if (Request.Headers.Authorization != null)
                {
                    token = Request.Headers.Authorization.ToString();
                }
                int id = new UsuarioCEN().CheckToken(token);



                tipoAccionRESTCAD = new TipoAccionRESTCAD(session);
                tipoAccionCEN     = new TipoAccionCEN(tipoAccionRESTCAD);

                // Data
                tipoAccionEN = tipoAccionCEN.BuscarPorId(idTipoAccion);

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

            catch (Exception e)
            {
                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.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 Crear([FromBody] TipoAccionDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            TipoAccionRESTCAD tipoAccionRESTCAD = null;
            TipoAccionCEN     tipoAccionCEN     = null;
            TipoAccionDTOA    returnValue       = null;
            int returnOID = -1;

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

            try
            {
                SessionInitializeTransaction();
                string token = "";
                if (Request.Headers.Authorization != null)
                {
                    token = Request.Headers.Authorization.ToString();
                }
                int id = new UsuarioCEN().CheckToken(token);



                tipoAccionRESTCAD = new TipoAccionRESTCAD(session);
                tipoAccionCEN     = new TipoAccionCEN(tipoAccionRESTCAD);

                // Create
                returnOID = tipoAccionCEN.Crear(
                    //Atributo Primitivo: p_puntuacion
                    dto.Puntuacion,                                                                                                                                         //Atributo Primitivo: p_nombre
                    dto.Nombre);
                SessionCommit();

                // Convert return
                returnValue = TipoAccionAssembler.Convert(tipoAccionRESTCAD.ReadOIDDefault(returnOID), session);
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.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("GetOIDTipoAccion", routeValues);
             * response.Headers.Location = new Uri(uri);
             */

            return(response);
        }