public static AccionReciclarDTOA Convert(AccionEN en, NHibernate.ISession session = null)
        {
            AccionReciclarDTOA    dto = null;
            AccionReciclarRESTCAD accionReciclarRESTCAD = null;
            AccionReciclarCEN     accionReciclarCEN     = null;
            AccionReciclarCP      accionReciclarCP      = null;

            if (en != null)
            {
                dto = new AccionReciclarDTOA();
                accionReciclarRESTCAD = new AccionReciclarRESTCAD(session);
                accionReciclarCEN     = new AccionReciclarCEN(accionReciclarRESTCAD);
                accionReciclarCP      = new AccionReciclarCP(session);


                AccionReciclarEN enHijo = accionReciclarRESTCAD.ReadOIDDefault(en.Id);



                //
                // Attributes

                dto.Id = en.Id;

                if (enHijo != null)
                {
                    dto.Cantidad = enHijo.Cantidad;
                }


                dto.Fecha = en.Fecha;


                //
                // TravesalLink

                /* Rol: AccionReciclar o--> Item */
                dto.ItemAccion = ItemAssembler.Convert((ItemEN)enHijo.Item, session);

                /* Rol: AccionReciclar o--> Contenedor */
                dto.ContenedorAccion = ContenedorAssembler.Convert((ContenedorEN)enHijo.Contenedor, session);

                /* Rol: AccionReciclar o--> UsuarioWeb */
                dto.UsuarioAccionReciclar = UsuarioWebAssembler.Convert((UsuarioEN)enHijo.Usuario, session);


                //
                // Service
            }

            return(dto);
        }
        public HttpResponseMessage CrearCP([FromBody] AccionReciclarDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            AccionReciclarRESTCAD accionReciclarRESTCAD = null;
            AccionReciclarCEN     accionReciclarCEN     = null;
            AccionReciclarDTOA    returnValue           = null;
            AccionReciclarCP      cp = null;
            int returnOID            = -1;

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

            try
            {
                SessionInitializeTransaction();

                accionReciclarRESTCAD = new AccionReciclarRESTCAD(session);
                accionReciclarCEN     = new AccionReciclarCEN(accionReciclarRESTCAD);
                cp = new AccionReciclarCP(session);

                // Create
                returnOID = accionReciclarCEN.Crear(dto.Usuario_oid, dto.Contenedor_oid, dto.Item_oid, dto.Cantidad);
                cp.CrearAccion(returnOID);

                SessionCommit();

                // Convert return
                returnValue = AccionReciclarAssembler.Convert(accionReciclarRESTCAD.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);

            return(response);
        }