public static UsuarioWebAutenticadoDTOA Convert(UsuarioEN en, NHibernate.ISession session = null) { UsuarioWebAutenticadoDTOA dto = null; UsuarioWebAutenticadoRESTCAD usuarioWebAutenticadoRESTCAD = null; UsuarioWebCEN usuarioWebCEN = null; UsuarioWebCP usuarioWebCP = null; if (en != null) { dto = new UsuarioWebAutenticadoDTOA(); usuarioWebAutenticadoRESTCAD = new UsuarioWebAutenticadoRESTCAD(session); usuarioWebCEN = new UsuarioWebCEN(usuarioWebAutenticadoRESTCAD); usuarioWebCP = new UsuarioWebCP(session); UsuarioWebEN enHijo = usuarioWebAutenticadoRESTCAD.ReadOIDDefault(en.Id); // // Attributes dto.Id = en.Id; dto.Nombre = en.Nombre; dto.Apellidos = en.Apellidos; dto.Email = en.Email; if (enHijo != null) { dto.Puntuacion = enHijo.Puntuacion; } dto.Fecha = en.Fecha; dto.Borrado = en.Borrado; // // TravesalLink /* Rol: UsuarioWebAutenticado o--> Juego */ dto.JuegoUsuario = JuegoAssembler.Convert((JuegoEN)enHijo.Juegos, session); // // Service } return(dto); }
public HttpResponseMessage Borrar(int p_usuarioweb_oid) { UsuarioWebAutenticadoRESTCAD usuarioWebAutenticadoRESTCAD = null; UsuarioWebCEN usuarioWebCEN = 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); usuarioWebAutenticadoRESTCAD = new UsuarioWebAutenticadoRESTCAD(session); usuarioWebCEN = new UsuarioWebCEN(usuarioWebAutenticadoRESTCAD); // Destroy usuarioWebCEN.Borrar(p_usuarioweb_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)); }
public HttpResponseMessage CambiarPassword(int idUsuarioWebAutenticado, [FromBody] UsuarioWebDTO dto) { // CAD, CEN, returnValue UsuarioWebAutenticadoRESTCAD usuarioWebAutenticadoRESTCAD = null; UsuarioWebCEN usuarioWebCEN = null; UsuarioWebAutenticadoDTOA 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); usuarioWebAutenticadoRESTCAD = new UsuarioWebAutenticadoRESTCAD(session); usuarioWebCEN = new UsuarioWebCEN(usuarioWebAutenticadoRESTCAD); // Modify usuarioWebCEN.CambiarPassword(idUsuarioWebAutenticado, dto.Pass ); // Return modified object returnValue = UsuarioWebAutenticadoAssembler.Convert(usuarioWebAutenticadoRESTCAD.ReadOIDDefault(idUsuarioWebAutenticado), 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 idUsuarioWebAutenticado) { // CAD, CEN, EN, returnValue UsuarioWebAutenticadoRESTCAD usuarioWebAutenticadoRESTCAD = null; UsuarioWebCEN usuarioWebCEN = null; UsuarioWebEN usuarioWebEN = null; UsuarioWebAutenticadoDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); usuarioWebAutenticadoRESTCAD = new UsuarioWebAutenticadoRESTCAD(session); usuarioWebCEN = new UsuarioWebCEN(usuarioWebAutenticadoRESTCAD); // Data usuarioWebEN = usuarioWebCEN.BuscarPorId(idUsuarioWebAutenticado); // Convert return if (usuarioWebEN != null) { returnValue = UsuarioWebAutenticadoAssembler.Convert(usuarioWebEN, 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)); } }
public HttpResponseMessage ObtenerPuntuaciones( ) { // CAD, CEN, EN, returnValue UsuarioWebAutenticadoRESTCAD usuarioWebAutenticadoRESTCAD = null; UsuarioWebCEN usuarioWebCEN = null; System.Collections.Generic.List <UsuarioWebEN> en; System.Collections.Generic.List <UsuarioWebAutenticadoDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); usuarioWebAutenticadoRESTCAD = new UsuarioWebAutenticadoRESTCAD(session); usuarioWebCEN = new UsuarioWebCEN(usuarioWebAutenticadoRESTCAD); // CEN return en = usuarioWebCEN.ObtenerPuntuaciones( ).ToList(); // Convert return if (en != null) { returnValue = new System.Collections.Generic.List <UsuarioWebAutenticadoDTOA>(); foreach (UsuarioWebEN entry in en) { returnValue.Add(UsuarioWebAutenticadoAssembler.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)); } }