public static UsuarioWebNoAutenticadoDTOA Convert(UsuarioEN en, NHibernate.ISession session = null) { UsuarioWebNoAutenticadoDTOA dto = null; UsuarioWebNoAutenticadoRESTCAD usuarioWebNoAutenticadoRESTCAD = null; UsuarioCEN usuarioCEN = null; UsuarioCP usuarioCP = null; if (en != null) { dto = new UsuarioWebNoAutenticadoDTOA(); usuarioWebNoAutenticadoRESTCAD = new UsuarioWebNoAutenticadoRESTCAD(session); usuarioCEN = new UsuarioCEN(usuarioWebNoAutenticadoRESTCAD); usuarioCP = new UsuarioCP(session); // // Attributes dto.Id = en.Id; // // TravesalLink // // Service } return(dto); }
public HttpResponseMessage Login([FromBody] UsuarioDTO dto) { // CAD, CEN, returnValue UsuarioWebNoAutenticadoRESTCAD usuarioWebNoAutenticadoRESTCAD = null; UsuarioCEN usuarioCEN = null; string token = null; try { SessionInitializeTransaction(); usuarioWebNoAutenticadoRESTCAD = new UsuarioWebNoAutenticadoRESTCAD(session); usuarioCEN = new UsuarioCEN(usuarioWebNoAutenticadoRESTCAD); // 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, "")); } }
public HttpResponseMessage BuscarPorCorreo(string p_correo) { // CAD, CEN, EN, returnValue UsuarioWebNoAutenticadoRESTCAD usuarioWebNoAutenticadoRESTCAD = null; UsuarioCEN usuarioCEN = null; UsuarioEN en; UsuarioWebNoAutenticadoDTOA returnValue; try { SessionInitializeWithoutTransaction(); usuarioWebNoAutenticadoRESTCAD = new UsuarioWebNoAutenticadoRESTCAD(session); usuarioCEN = new UsuarioCEN(usuarioWebNoAutenticadoRESTCAD); // CEN return en = usuarioCEN.BuscarPorCorreo(p_correo); // Convert return returnValue = UsuarioWebNoAutenticadoAssembler.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)); } }