public HttpResponseMessage Borrar(int p_accionreciclar_oid)
        {
            // CAD, CEN
            AccionReciclarRESTCAD accionReciclarRESTCAD = null;
            AccionReciclarCEN     accionReciclarCEN     = 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);

                accionReciclarCEN.Borrar(p_accionreciclar_oid);
                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 204 - No Content
            return(this.Request.CreateResponse(HttpStatusCode.NoContent));
        }
        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);
        }
Beispiel #3
0
        public void CrearAccion(int p_oid)
        {
            /*PROTECTED REGION ID(ReciclaUAGenNHibernate.CP.ReciclaUA_AccionReciclar_crearAccion) ENABLED START*/

            IAccionReciclarCAD accionReciclarCAD = null;
            AccionReciclarCEN  accionReciclarCEN = null;
            IUsuarioWebCAD     usuarioWebCAD     = null;
            UsuarioWebCEN      usuarioWebCEN     = null;
            AccionReciclarEN   result            = null;


            try
            {
                SessionInitializeTransaction();
                accionReciclarCAD = new AccionReciclarCAD(session);
                accionReciclarCEN = new AccionReciclarCEN(accionReciclarCAD);
                usuarioWebCAD     = new UsuarioWebCAD(session);
                usuarioWebCEN     = new UsuarioWebCEN(usuarioWebCAD);

                result = accionReciclarCAD.ReadOIDDefault(p_oid);

                if (result.Usuario != null)
                {
                    usuarioWebCEN.IncrementarPuntuacion(result.Usuario.Id, result.Item.Puntuacion * result.Cantidad);
                }

                SessionCommit();
            }
            catch (Exception ex)
            {
                SessionRollBack();
                throw ex;
            }
            finally
            {
                SessionClose();
            }


            /*PROTECTED REGION END*/
        }
        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 BuscarTodos()
        {
            // CAD, CEN, EN, returnValue
            AccionReciclarRESTCAD accionReciclarRESTCAD = null;
            AccionReciclarCEN     accionReciclarCEN     = null;

            List <AccionReciclarEN>   accionReciclarEN = null;
            List <AccionReciclarDTOA> returnValue      = null;

            try
            {
                SessionInitializeWithoutTransaction();
                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);

                // Data
                // TODO: paginación

                accionReciclarEN = accionReciclarCEN.BuscarTodos(0, -1).ToList();

                // Convert return
                if (accionReciclarEN != null)
                {
                    returnValue = new List <AccionReciclarDTOA>();
                    foreach (AccionReciclarEN entry in accionReciclarEN)
                    {
                        returnValue.Add(AccionReciclarAssembler.Convert(entry, 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 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 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 BuscarPorId(int idAccionReciclar)
        {
            // CAD, CEN, EN, returnValue
            AccionReciclarRESTCAD accionReciclarRESTCAD = null;
            AccionReciclarCEN     accionReciclarCEN     = null;
            AccionReciclarEN      accionReciclarEN      = null;
            AccionReciclarDTOA    returnValue           = null;

            try
            {
                SessionInitializeWithoutTransaction();
                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);

                // Data
                accionReciclarEN = accionReciclarCEN.BuscarPorId(idAccionReciclar);

                // Convert return
                if (accionReciclarEN != null)
                {
                    returnValue = AccionReciclarAssembler.Convert(accionReciclarEN, 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 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);
            }
        }
        public ReciclaUAGenNHibernate.EN.ReciclaUA.AccionReciclarEN Crear(int p_usuario, int p_contenedor, int p_item, int p_cantidad)
        {
            /*PROTECTED REGION ID(ReciclaUAGenNHibernate.CP.ReciclaUA_AccionReciclar_crear) ENABLED START*/

            IAccionReciclarCAD accionReciclarCAD = null;
            AccionReciclarCEN  accionReciclarCEN = null;

            IUsuarioWebCAD usuarioWebCAD = null;
            UsuarioWebCEN  usuarioWebCEN = null;

            ReciclaUAGenNHibernate.EN.ReciclaUA.AccionReciclarEN result = null;


            try
            {
                SessionInitializeTransaction();
                accionReciclarCAD = new AccionReciclarCAD(session);
                accionReciclarCEN = new AccionReciclarCEN(accionReciclarCAD);
                usuarioWebCAD     = new UsuarioWebCAD(session);
                usuarioWebCEN     = new UsuarioWebCEN(usuarioWebCAD);



                int oid;
                //Initialized AccionReciclarEN
                AccionReciclarEN accionReciclarEN;
                accionReciclarEN = new AccionReciclarEN();

                if (p_usuario != -1)
                {
                    accionReciclarEN.Usuario    = new ReciclaUAGenNHibernate.EN.ReciclaUA.UsuarioWebEN();
                    accionReciclarEN.Usuario.Id = p_usuario;
                }

                accionReciclarEN.Fecha = DateTime.Now;


                if (p_contenedor != -1)
                {
                    accionReciclarEN.Contenedor    = new ReciclaUAGenNHibernate.EN.ReciclaUA.ContenedorEN();
                    accionReciclarEN.Contenedor.Id = p_contenedor;
                }


                if (p_item != -1)
                {
                    accionReciclarEN.Item    = new ReciclaUAGenNHibernate.EN.ReciclaUA.ItemEN();
                    accionReciclarEN.Item.Id = p_item;
                }

                accionReciclarEN.Cantidad = p_cantidad;

                //Call to AccionReciclarCAD

                oid    = accionReciclarCAD.Crear(accionReciclarEN);
                result = accionReciclarCAD.ReadOIDDefault(oid);

                usuarioWebCEN.IncrementarPuntuacion(result.Usuario.Id, result.Item.Puntuacion * result.Cantidad);

                SessionCommit();
            }
            catch (Exception ex)
            {
                SessionRollBack();
                throw ex;
            }
            finally
            {
                SessionClose();
            }
            return(result);


            /*PROTECTED REGION END*/
        }