public static AccionReciclarEN Convert(AccionReciclarDTO dto)
        {
            AccionReciclarEN newinstance = null;

            try
            {
                if (dto != null)
                {
                    newinstance = new AccionReciclarEN();



                    if (dto.Contenedor_oid != -1)
                    {
                        ReciclaUAGenNHibernate.CAD.ReciclaUA.IContenedorCAD contenedorCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.ContenedorCAD();

                        newinstance.Contenedor = contenedorCAD.ReadOIDDefault(dto.Contenedor_oid);
                    }
                    if (dto.Item_oid != -1)
                    {
                        ReciclaUAGenNHibernate.CAD.ReciclaUA.IItemCAD itemCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.ItemCAD();

                        newinstance.Item = itemCAD.ReadOIDDefault(dto.Item_oid);
                    }
                    newinstance.Cantidad = dto.Cantidad;
                    newinstance.Id       = dto.Id;
                    if (dto.Usuario_oid != -1)
                    {
                        ReciclaUAGenNHibernate.CAD.ReciclaUA.IUsuarioWebCAD usuarioWebCAD = new ReciclaUAGenNHibernate.CAD.ReciclaUA.UsuarioWebCAD();

                        newinstance.Usuario = usuarioWebCAD.ReadOIDDefault(dto.Usuario_oid);
                    }
                    newinstance.Fecha = dto.Fecha;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newinstance);
        }
        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);
        }
        public HttpResponseMessage Crear([FromBody] AccionReciclarDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            AccionReciclarRESTCAD accionReciclarRESTCAD = null;
            AccionReciclarCEN     accionReciclarCEN     = null;
            AccionReciclarDTOA    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);



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

                // Create
                returnOID = accionReciclarCEN.Crear(
                    //Atributo OID: p_usuario
                    // attr.estaRelacionado: true
                    dto.Usuario_oid                  // association role

                    ,                                //Atributo OID: p_contenedor
                    // attr.estaRelacionado: true
                    dto.Contenedor_oid               // association role

                    ,                                //Atributo OID: p_item
                    // attr.estaRelacionado: true
                    dto.Item_oid                     // association role

                    ,                                //Atributo Primitivo: p_cantidad
                    dto.Cantidad);
                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);

            // Location Header

            /*
             * Dictionary<string, object> routeValues = new Dictionary<string, object>();
             *
             * // TODO: y rolPaths
             * routeValues.Add("id", returnOID);
             *
             * uri = Url.Link("GetOIDAccionReciclar", routeValues);
             * response.Headers.Location = new Uri(uri);
             */

            return(response);
        }
        public HttpResponseMessage Modificar(int idAccionReciclar, [FromBody] AccionReciclarDTO dto)
        {
            // CAD, CEN, returnValue
            AccionReciclarRESTCAD accionReciclarRESTCAD = null;
            AccionReciclarCEN     accionReciclarCEN     = null;
            AccionReciclarDTOA    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);



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

                // Modify
                accionReciclarCEN.Modificar(idAccionReciclar,
                                            dto.Fecha
                                            ,
                                            dto.Cantidad
                                            );

                // Return modified object
                returnValue = AccionReciclarAssembler.Convert(accionReciclarRESTCAD.ReadOIDDefault(idAccionReciclar), 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);
            }
        }