public HttpResponseMessage Borrar(int p_accionweb_oid)
        {
            // CAD, CEN
            AccionWebRESTCAD accionWebRESTCAD = null;
            AccionWebCEN     accionWebCEN     = null;

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



                accionWebRESTCAD = new AccionWebRESTCAD(session);
                accionWebCEN     = new AccionWebCEN(accionWebRESTCAD);

                accionWebCEN.Borrar(p_accionweb_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.º 2
0
        public static AccionWebDTOA Convert(AccionEN en, NHibernate.ISession session = null)
        {
            AccionWebDTOA    dto = null;
            AccionWebRESTCAD accionWebRESTCAD = null;
            AccionWebCEN     accionWebCEN     = null;
            AccionWebCP      accionWebCP      = null;

            if (en != null)
            {
                dto = new AccionWebDTOA();
                accionWebRESTCAD = new AccionWebRESTCAD(session);
                accionWebCEN     = new AccionWebCEN(accionWebRESTCAD);
                accionWebCP      = new AccionWebCP(session);


                AccionWebEN enHijo = accionWebRESTCAD.ReadOIDDefault(en.Id);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Fecha = en.Fecha;


                //
                // TravesalLink

                /* Rol: AccionWeb o--> TipoAccion */
                dto.Tipo = TipoAccionAssembler.Convert((TipoAccionEN)enHijo.Tipo, session);

                /* Rol: AccionWeb o--> UsuarioWeb */
                dto.UsuarioAccionWeb = UsuarioWebAssembler.Convert((UsuarioEN)enHijo.Usuario, session);


                //
                // Service
            }

            return(dto);
        }
        public HttpResponseMessage BuscarPorFecha(Nullable <DateTime> p_date)
        {
            // CAD, CEN, EN, returnValue

            AccionWebRESTCAD accionWebRESTCAD = null;
            AccionWebCEN     accionWebCEN     = null;


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

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

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



                accionWebRESTCAD = new AccionWebRESTCAD(session);
                accionWebCEN     = new AccionWebCEN(accionWebRESTCAD);

                // CEN return



                en = accionWebCEN.BuscarPorFecha(p_date).ToList();



                // Convert return
                if (en != null)
                {
                    returnValue = new System.Collections.Generic.List <AccionWebDTOA>();
                    foreach (AccionWebEN entry in en)
                    {
                        returnValue.Add(AccionWebAssembler.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 Modificar(int idAccionWeb, [FromBody] AccionWebDTO dto)
        {
            // CAD, CEN, returnValue
            AccionWebRESTCAD accionWebRESTCAD = null;
            AccionWebCEN     accionWebCEN     = null;
            AccionWebDTOA    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);



                accionWebRESTCAD = new AccionWebRESTCAD(session);
                accionWebCEN     = new AccionWebCEN(accionWebRESTCAD);

                // Modify
                accionWebCEN.Modificar(idAccionWeb,
                                       dto.Fecha
                                       );

                // Return modified object
                returnValue = AccionWebAssembler.Convert(accionWebRESTCAD.ReadOIDDefault(idAccionWeb), 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 HttpResponseMessage BuscarPorId(int idAccionWeb)
        {
            // CAD, CEN, EN, returnValue
            AccionWebRESTCAD accionWebRESTCAD = null;
            AccionWebCEN     accionWebCEN     = null;
            AccionWebEN      accionWebEN      = null;
            AccionWebDTOA    returnValue      = null;

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



                accionWebRESTCAD = new AccionWebRESTCAD(session);
                accionWebCEN     = new AccionWebCEN(accionWebRESTCAD);

                // Data
                accionWebEN = accionWebCEN.BuscarPorId(idAccionWeb);

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