コード例 #1
0
        public HttpResponseMessage DescartarItem(int p_oid)
        {
            // CAD, CEN, returnValue
            ItemRESTCAD itemRESTCAD = null;
            ItemCEN     itemCEN     = null;

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



                itemRESTCAD = new ItemRESTCAD(session);
                itemCEN     = new ItemCEN(itemRESTCAD);


                // Operation
                itemCEN.DescartarItem(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));
        }
コード例 #2
0
        public static ItemDTOA Convert(ItemEN en, NHibernate.ISession session = null)
        {
            ItemDTOA    dto         = null;
            ItemRESTCAD itemRESTCAD = null;
            ItemCEN     itemCEN     = null;
            ItemCP      itemCP      = null;

            if (en != null)
            {
                dto         = new ItemDTOA();
                itemRESTCAD = new ItemRESTCAD(session);
                itemCEN     = new ItemCEN(itemRESTCAD);
                itemCP      = new ItemCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Nombre = en.Nombre;


                dto.Descripcion = en.Descripcion;


                dto.Imagen = en.Imagen;


                dto.EsValido = en.EsValido;


                dto.Puntuacion = en.Puntuacion;


                //
                // TravesalLink

                /* Rol: Item o--> Material */
                dto.MaterialItem = MaterialAssembler.Convert((MaterialEN)en.Material, session);


                //
                // Service
            }

            return(dto);
        }
コード例 #3
0
        public HttpResponseMessage NivelItem(int idItem)
        {
            // CAD, EN
            ItemRESTCAD itemRESTCAD = null;
            ItemEN      itemEN      = null;

            // returnValue
            NivelEN   en          = null;
            NivelDTOA returnValue = null;

            try
            {
                SessionInitializeWithoutTransaction();


                itemRESTCAD = new ItemRESTCAD(session);

                // Exists Item
                itemEN = itemRESTCAD.ReadOIDDefault(idItem);
                if (itemEN == null)
                {
                    throw new HttpResponseException(this.Request.CreateResponse(HttpStatusCode.NotFound, "Item#" + idItem + " not found"));
                }

                // Rol
                // TODO: paginación


                en = itemRESTCAD.NivelItem(idItem);



                // Convert return
                if (en != null)
                {
                    returnValue = NivelAssembler.Convert(en, 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)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NoContent));
            }
            // Return 200 - OK
            else
            {
                return(this.Request.CreateResponse(HttpStatusCode.OK, returnValue));
            }
        }
コード例 #4
0
        public HttpResponseMessage Modificar(int idItem, [FromBody] ItemDTO dto)
        {
            // CAD, CEN, returnValue
            ItemRESTCAD itemRESTCAD = null;
            ItemCEN     itemCEN     = null;
            ItemDTOA    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);



                itemRESTCAD = new ItemRESTCAD(session);
                itemCEN     = new ItemCEN(itemRESTCAD);

                // Modify
                itemCEN.Modificar(idItem,
                                  dto.Nombre
                                  ,
                                  dto.Descripcion
                                  ,
                                  dto.Imagen
                                  ,
                                  dto.EsValido
                                  ,
                                  dto.Puntuacion
                                  );

                // Return modified object
                returnValue = ItemAssembler.Convert(itemRESTCAD.ReadOIDDefault(idItem), 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);
            }
        }
コード例 #5
0
        public HttpResponseMessage Crear([FromBody] ItemDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            ItemRESTCAD itemRESTCAD = null;
            ItemCEN     itemCEN     = null;
            ItemDTOA    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);



                itemRESTCAD = new ItemRESTCAD(session);
                itemCEN     = new ItemCEN(itemRESTCAD);

                // Create
                returnOID = itemCEN.Crear(
                    //Atributo Primitivo: p_nombre
                    dto.Nombre,                         //Atributo Primitivo: p_descripcion
                    dto.Descripcion,                    //Atributo Primitivo: p_imagen
                    dto.Imagen,                         //Atributo OID: p_usuario
                    // attr.estaRelacionado: true
                    dto.Usuario_oid                     // association role

                    ,                                   //Atributo OID: p_material
                    // attr.estaRelacionado: true
                    dto.Material_oid                    // association role

                    );
                SessionCommit();

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

            return(response);
        }
コード例 #6
0
        public HttpResponseMessage BuscarItemsPorNivel(int id_nivel)
        {
            // CAD, CEN, EN, returnValue

            ItemRESTCAD itemRESTCAD = null;
            ItemCEN     itemCEN     = null;


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

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

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



                itemRESTCAD = new ItemRESTCAD(session);
                itemCEN     = new ItemCEN(itemRESTCAD);

                // CEN return



                en = itemCEN.BuscarItemsPorNivel(id_nivel).ToList();



                // Convert return
                if (en != null)
                {
                    returnValue = new System.Collections.Generic.List <ItemDTOA>();
                    foreach (ItemEN entry in en)
                    {
                        returnValue.Add(ItemAssembler.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));
            }
        }
コード例 #7
0
        public HttpResponseMessage BuscarItemsPorValidarCount(            )
        {
            // CAD, CEN, EN, returnValue

            ItemRESTCAD itemRESTCAD = null;
            ItemCEN     itemCEN     = null;


            int returnValue;

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



                itemRESTCAD = new ItemRESTCAD(session);
                itemCEN     = new ItemCEN(itemRESTCAD);

                // CEN return



                returnValue = itemCEN.BuscarItemsPorValidarCount(       );



                // 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));
            }
        }
コード例 #8
0
        public HttpResponseMessage CrearCP([FromBody] ItemDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            ItemRESTCAD itemRESTCAD = null;
            ItemCEN     itemCEN     = null;
            ItemDTOA    returnValue = null;
            ItemCP      itemCP      = null;
            int         returnOID   = -1;

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

            try
            {
                SessionInitializeTransaction();


                itemRESTCAD = new ItemRESTCAD(session);
                itemCEN     = new ItemCEN(itemRESTCAD);
                itemCP      = new ItemCP(session);

                // Create
                returnOID = itemCEN.Crear(dto.Nombre, dto.Descripcion, dto.Imagen, dto.Usuario_oid, dto.Material_oid);
                itemCP.CrearAccionItem(returnOID);

                SessionCommit();

                // Convert return
                returnValue = ItemAssembler.Convert(itemRESTCAD.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);
        }