示例#1
0
        public HttpResponseMessage CrearCP([FromBody] DudaDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            DudaRESTCAD dudaRESTCAD = null;
            DudaCEN     dudaCEN     = null;
            DudaDTOA    returnValue = null;
            DudaCP      dudaCP      = null;
            int         returnOID   = -1;

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

            try
            {
                SessionInitializeTransaction();
                dudaRESTCAD = new DudaRESTCAD(session);
                dudaCEN     = new DudaCEN(dudaRESTCAD);
                dudaCP      = new DudaCP(session);

                // Create
                returnOID = dudaCEN.Crear(dto.Titulo, dto.Cuerpo, dto.Usuario_oid, dto.Tema);
                dudaCP.CrearAccionDuda(returnOID);

                SessionCommit();

                // Convert return
                returnValue = DudaAssembler.Convert(dudaRESTCAD.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);
        }
示例#2
0
        public HttpResponseMessage IndicarDudaNoUtil(int p_oid)
        {
            // CAD, CEN, returnValue
            DudaRESTCAD dudaRESTCAD = null;
            DudaCEN     dudaCEN     = null;

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



                dudaRESTCAD = new DudaRESTCAD(session);
                dudaCEN     = new DudaCEN(dudaRESTCAD);


                // Operation
                dudaCEN.IndicarDudaNoUtil(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 static DudaDTOA Convert(DudaEN en, NHibernate.ISession session = null)
        {
            DudaDTOA    dto         = null;
            DudaRESTCAD dudaRESTCAD = null;
            DudaCEN     dudaCEN     = null;
            DudaCP      dudaCP      = null;

            if (en != null)
            {
                dto         = new DudaDTOA();
                dudaRESTCAD = new DudaRESTCAD(session);
                dudaCEN     = new DudaCEN(dudaRESTCAD);
                dudaCP      = new DudaCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Titulo = en.Titulo;


                dto.Cuerpo = en.Cuerpo;


                dto.Fecha = en.Fecha;


                dto.Util = en.Util;


                dto.Tema = en.Tema;


                //
                // TravesalLink

                /* Rol: Duda o--> UsuarioWebAutenticado */
                dto.UsuarioDuda = UsuarioWebAutenticadoAssembler.Convert((UsuarioEN)en.Usuario, session);


                //
                // Service

                /* ServiceLink: obtenerNumeroDeRespuestas */
                dto.ObtenerNumeroDeRespuestas = dudaCP.ObtenerNumeroDeRespuestas(en.Id);

                /* ServiceLink: obtenerSiRespuestaValida */
                dto.ObtenerSiRespuestaValida = dudaCP.ObtenerSiRespuestaValida(en.Id);
            }

            return(dto);
        }
示例#4
0
        public HttpResponseMessage RespuestasDuda(int idDuda)
        {
            // CAD, EN
            DudaRESTCAD dudaRESTCAD = null;
            DudaEN      dudaEN      = null;

            // returnValue
            List <RespuestaEN>   en          = null;
            List <RespuestaDTOA> returnValue = null;

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


                dudaRESTCAD = new DudaRESTCAD(session);

                // Exists Duda
                dudaEN = dudaRESTCAD.ReadOIDDefault(idDuda);
                if (dudaEN == null)
                {
                    throw new HttpResponseException(this.Request.CreateResponse(HttpStatusCode.NotFound, "Duda#" + idDuda + " not found"));
                }

                // Rol
                // TODO: paginación


                en = dudaRESTCAD.RespuestasDuda(idDuda).ToList();



                // Convert return
                if (en != null)
                {
                    returnValue = new List <RespuestaDTOA>();
                    foreach (RespuestaEN entry in en)
                    {
                        returnValue.Add(RespuestaAssembler.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));
            }
        }
示例#5
0
        public HttpResponseMessage Modificar(int idDuda, [FromBody] DudaDTO dto)
        {
            // CAD, CEN, returnValue
            DudaRESTCAD dudaRESTCAD = null;
            DudaCEN     dudaCEN     = null;
            DudaDTOA    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);



                dudaRESTCAD = new DudaRESTCAD(session);
                dudaCEN     = new DudaCEN(dudaRESTCAD);

                // Modify
                dudaCEN.Modificar(idDuda,
                                  dto.Titulo
                                  ,
                                  dto.Cuerpo
                                  ,
                                  dto.Fecha
                                  ,
                                  dto.Util
                                  ,
                                  dto.Tema
                                  );

                // Return modified object
                returnValue = DudaAssembler.Convert(dudaRESTCAD.ReadOIDDefault(idDuda), 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);
            }
        }
示例#6
0
        public HttpResponseMessage Crear([FromBody] DudaDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            DudaRESTCAD dudaRESTCAD = null;
            DudaCEN     dudaCEN     = null;
            DudaDTOA    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);



                dudaRESTCAD = new DudaRESTCAD(session);
                dudaCEN     = new DudaCEN(dudaRESTCAD);

                // Create
                returnOID = dudaCEN.Crear(
                    //Atributo Primitivo: p_titulo
                    dto.Titulo,                         //Atributo Primitivo: p_cuerpo
                    dto.Cuerpo,                         //Atributo OID: p_usuario
                    // attr.estaRelacionado: true
                    dto.Usuario_oid                     // association role

                    ,                                   //Atributo Primitivo: p_tema
                    dto.Tema);
                SessionCommit();

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

            return(response);
        }
示例#7
0
        public HttpResponseMessage BuscarDudaPorTema(ReciclaUAGenNHibernate.Enumerated.ReciclaUA.TemaEnum?p_tema)
        {
            // CAD, CEN, EN, returnValue

            DudaRESTCAD dudaRESTCAD = null;
            DudaCEN     dudaCEN     = null;


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

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

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



                dudaRESTCAD = new DudaRESTCAD(session);
                dudaCEN     = new DudaCEN(dudaRESTCAD);

                // CEN return



                en = dudaCEN.BuscarDudaPorTema(p_tema).ToList();



                // Convert return
                if (en != null)
                {
                    returnValue = new System.Collections.Generic.List <DudaDTOA>();
                    foreach (DudaEN entry in en)
                    {
                        returnValue.Add(DudaAssembler.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));
            }
        }
示例#8
0
        public HttpResponseMessage BuscarPorId(int idDuda)
        {
            // CAD, CEN, EN, returnValue
            DudaRESTCAD dudaRESTCAD = null;
            DudaCEN     dudaCEN     = null;
            DudaEN      dudaEN      = null;
            DudaDTOA    returnValue = null;

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



                dudaRESTCAD = new DudaRESTCAD(session);
                dudaCEN     = new DudaCEN(dudaRESTCAD);

                // Data
                dudaEN = dudaCEN.BuscarPorId(idDuda);

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