Exemplo n.º 1
0
        public static UsuarioAdminNoAutenticadoDTOA Convert(UsuarioEN en, NHibernate.ISession session = null)
        {
            UsuarioAdminNoAutenticadoDTOA    dto = null;
            UsuarioAdminNoAutenticadoRESTCAD usuarioAdminNoAutenticadoRESTCAD = null;
            UsuarioCEN usuarioCEN = null;
            UsuarioCP  usuarioCP  = null;

            if (en != null)
            {
                dto = new UsuarioAdminNoAutenticadoDTOA();
                usuarioAdminNoAutenticadoRESTCAD = new UsuarioAdminNoAutenticadoRESTCAD(session);
                usuarioCEN = new UsuarioCEN(usuarioAdminNoAutenticadoRESTCAD);
                usuarioCP  = new UsuarioCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                //
                // TravesalLink


                //
                // Service
            }

            return(dto);
        }
Exemplo n.º 2
0
        public HttpResponseMessage Login([FromBody] UsuarioDTO dto)
        {
            // CAD, CEN, returnValue
            UsuarioAdminNoAutenticadoRESTCAD usuarioAdminNoAutenticadoRESTCAD = null;
            UsuarioCEN usuarioCEN = null;
            string     token      = null;

            try
            {
                SessionInitializeTransaction();
                usuarioAdminNoAutenticadoRESTCAD = new UsuarioAdminNoAutenticadoRESTCAD(session);
                usuarioCEN = new UsuarioCEN(usuarioAdminNoAutenticadoRESTCAD);


                // Operation
                token = usuarioCEN.Login(
                    dto.Pass
                    , dto.Email
                    );

                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
            if (token != null)
            {
                return(this.Request.CreateResponse(HttpStatusCode.OK, token));
            }
            else
            {
                return(this.Request.CreateResponse(HttpStatusCode.Unauthorized, ""));
            }
        }
Exemplo n.º 3
0
        public HttpResponseMessage BuscarPorCorreo(string p_correo)
        {
            // CAD, CEN, EN, returnValue

            UsuarioAdminNoAutenticadoRESTCAD usuarioAdminNoAutenticadoRESTCAD = null;
            UsuarioCEN usuarioCEN = null;


            UsuarioEN en;

            UsuarioAdminNoAutenticadoDTOA returnValue;

            try
            {
                SessionInitializeWithoutTransaction();



                usuarioAdminNoAutenticadoRESTCAD = new UsuarioAdminNoAutenticadoRESTCAD(session);
                usuarioCEN = new UsuarioCEN(usuarioAdminNoAutenticadoRESTCAD);

                // CEN return



                en = usuarioCEN.BuscarPorCorreo(p_correo);



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