Ejemplo n.º 1
0
        public HttpResponseMessage DescartarMaterial(int p_oid)
        {
            // CAD, CEN, returnValue
            MaterialRESTCAD materialRESTCAD = null;
            MaterialCEN     materialCEN     = null;

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



                materialRESTCAD = new MaterialRESTCAD(session);
                materialCEN     = new MaterialCEN(materialRESTCAD);


                // Operation
                materialCEN.DescartarMaterial(p_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 200 - OK
            return(this.Request.CreateResponse(HttpStatusCode.OK));
        }
        public HttpResponseMessage Borrar(int p_material_oid)
        {
            // CAD, CEN
            MaterialRESTCAD materialRESTCAD = null;
            MaterialCEN     materialCEN     = null;

            try
            {
                SessionInitializeTransaction();


                materialRESTCAD = new MaterialRESTCAD(session);
                materialCEN     = new MaterialCEN(materialRESTCAD);

                materialCEN.Borrar(p_material_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));
        }
Ejemplo n.º 3
0
        public static MaterialDTOA Convert(MaterialEN en, NHibernate.ISession session = null)
        {
            MaterialDTOA    dto             = null;
            MaterialRESTCAD materialRESTCAD = null;
            MaterialCEN     materialCEN     = null;
            MaterialCP      materialCP      = null;

            if (en != null)
            {
                dto             = new MaterialDTOA();
                materialRESTCAD = new MaterialRESTCAD(session);
                materialCEN     = new MaterialCEN(materialRESTCAD);
                materialCP      = new MaterialCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Nombre = en.Nombre;


                dto.Contenedor = en.Contenedor;


                dto.EsValido = en.EsValido;


                //
                // TravesalLink


                //
                // Service
            }

            return(dto);
        }
Ejemplo n.º 4
0
        public HttpResponseMessage Modificar(int idMaterial, [FromBody] MaterialDTO dto)
        {
            // CAD, CEN, returnValue
            MaterialRESTCAD materialRESTCAD = null;
            MaterialCEN     materialCEN     = null;
            MaterialDTOA    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);



                materialRESTCAD = new MaterialRESTCAD(session);
                materialCEN     = new MaterialCEN(materialRESTCAD);

                // Modify
                materialCEN.Modificar(idMaterial,
                                      dto.Nombre
                                      ,
                                      dto.Contenedor
                                      ,
                                      dto.EsValido
                                      );

                // Return modified object
                returnValue = MaterialAssembler.Convert(materialRESTCAD.ReadOIDDefault(idMaterial), 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);
            }
        }
Ejemplo n.º 5
0
        public HttpResponseMessage Crear([FromBody] MaterialDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            MaterialRESTCAD materialRESTCAD = null;
            MaterialCEN     materialCEN     = null;
            MaterialDTOA    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);



                materialRESTCAD = new MaterialRESTCAD(session);
                materialCEN     = new MaterialCEN(materialRESTCAD);

                // Create
                returnOID = materialCEN.Crear(
                    //Atributo Primitivo: p_nombre
                    dto.Nombre,                         //Atributo Primitivo: p_contenedor
                    dto.Contenedor,                     //Atributo OID: p_usuario
                    // attr.estaRelacionado: true
                    dto.Usuario_oid                     // association role

                    );
                SessionCommit();

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

            return(response);
        }
Ejemplo n.º 6
0
        public HttpResponseMessage BuscarMaterialesPorValidarCount(       )
        {
            // CAD, CEN, EN, returnValue

            MaterialRESTCAD materialRESTCAD = null;
            MaterialCEN     materialCEN     = null;


            int returnValue;

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



                materialRESTCAD = new MaterialRESTCAD(session);
                materialCEN     = new MaterialCEN(materialRESTCAD);

                // CEN return



                returnValue = materialCEN.BuscarMaterialesPorValidarCount(      );



                // Convert return
            }

            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)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NoContent));
            }
            // Return 200 - OK
            else
            {
                return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue));
            }
        }
Ejemplo n.º 7
0
        public HttpResponseMessage BuscarTodos()
        {
            // CAD, CEN, EN, returnValue
            MaterialRESTCAD materialRESTCAD = null;
            MaterialCEN     materialCEN     = null;

            List <MaterialEN>   materialEN  = null;
            List <MaterialDTOA> returnValue = null;

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



                materialRESTCAD = new MaterialRESTCAD(session);
                materialCEN     = new MaterialCEN(materialRESTCAD);

                // Data
                // TODO: paginación

                materialEN = materialCEN.BuscarTodos(0, -1).ToList();

                // Convert return
                if (materialEN != null)
                {
                    returnValue = new List <MaterialDTOA>();
                    foreach (MaterialEN entry in materialEN)
                    {
                        returnValue.Add(MaterialAssembler.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 CrearCP([FromBody] MaterialDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            MaterialRESTCAD materialRESTCAD = null;
            MaterialCEN     materialCEN     = null;
            MaterialDTOA    returnValue     = null;
            MaterialCP      materialCP      = null;
            int             returnOID       = -1;

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

            try
            {
                SessionInitializeTransaction();

                materialRESTCAD = new MaterialRESTCAD(session);
                materialCEN     = new MaterialCEN(materialRESTCAD);
                materialCP      = new MaterialCP(session);

                // Create
                returnOID = materialCEN.Crear(dto.Nombre, dto.Contenedor, dto.Usuario_oid);
                materialCP.CrearAccionMaterial(returnOID);

                SessionCommit();

                // Convert return
                returnValue = MaterialAssembler.Convert(materialRESTCAD.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 BuscarMaterialesPorUsuario(int id_usuario)
        {
            // CAD, CEN, EN, returnValue

            MaterialRESTCAD materialRESTCAD = null;
            MaterialCEN     materialCEN     = null;


            System.Collections.Generic.List <MaterialEN> en;

            System.Collections.Generic.List <MaterialDTOA> returnValue = null;

            try
            {
                SessionInitializeWithoutTransaction();



                materialRESTCAD = new MaterialRESTCAD(session);
                materialCEN     = new MaterialCEN(materialRESTCAD);

                // CEN return



                en = materialCEN.BuscarMaterialesPorUsuario(id_usuario).ToList();



                // Convert return
                if (en != null)
                {
                    returnValue = new System.Collections.Generic.List <MaterialDTOA>();
                    foreach (MaterialEN entry in en)
                    {
                        returnValue.Add(MaterialAssembler.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 BuscarPorId(int idMaterial)
        {
            // CAD, CEN, EN, returnValue
            MaterialRESTCAD materialRESTCAD = null;
            MaterialCEN     materialCEN     = null;
            MaterialEN      materialEN      = null;
            MaterialDTOA    returnValue     = null;

            try
            {
                SessionInitializeWithoutTransaction();


                materialRESTCAD = new MaterialRESTCAD(session);
                materialCEN     = new MaterialCEN(materialRESTCAD);

                // Data
                materialEN = materialCEN.BuscarPorId(idMaterial);

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