public static UsuarioWebDTOA Convert(UsuarioEN en, NHibernate.ISession session = null) { UsuarioWebDTOA dto = null; UsuarioWebRESTCAD usuarioWebRESTCAD = null; UsuarioWebCEN usuarioWebCEN = null; UsuarioWebCP usuarioWebCP = null; if (en != null) { dto = new UsuarioWebDTOA(); usuarioWebRESTCAD = new UsuarioWebRESTCAD(session); usuarioWebCEN = new UsuarioWebCEN(usuarioWebRESTCAD); usuarioWebCP = new UsuarioWebCP(session); UsuarioWebEN enHijo = usuarioWebRESTCAD.ReadOIDDefault(en.Id); // // Attributes dto.Id = en.Id; dto.Nombre = en.Nombre; dto.Apellidos = en.Apellidos; dto.Email = en.Email; dto.Fecha = en.Fecha; if (enHijo != null) { dto.Puntuacion = enHijo.Puntuacion; } dto.EmailVerificado = en.EmailVerificado; dto.Borrado = en.Borrado; // // TravesalLink // // Service } return(dto); }
public HttpResponseMessage Crear([FromBody] UsuarioWebDTO dto) { // CAD, CEN, returnValue, returnOID UsuarioWebRESTCAD usuarioWebRESTCAD = null; UsuarioWebCEN usuarioWebCEN = null; UsuarioWebDTOA 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); usuarioWebRESTCAD = new UsuarioWebRESTCAD(session); usuarioWebCEN = new UsuarioWebCEN(usuarioWebRESTCAD); // Create returnOID = usuarioWebCEN.Crear( //Atributo Primitivo: p_nombre dto.Nombre, //Atributo Primitivo: p_apellidos dto.Apellidos, //Atributo Primitivo: p_email dto.Email, //Atributo Primitivo: p_pass dto.Pass); SessionCommit(); // Convert return returnValue = UsuarioWebAssembler.Convert(usuarioWebRESTCAD.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("GetOIDUsuarioWeb", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage Modificar(int idUsuarioWeb, [FromBody] UsuarioWebDTO dto) { // CAD, CEN, returnValue UsuarioWebRESTCAD usuarioWebRESTCAD = null; UsuarioWebCEN usuarioWebCEN = null; UsuarioWebDTOA 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); usuarioWebRESTCAD = new UsuarioWebRESTCAD(session); usuarioWebCEN = new UsuarioWebCEN(usuarioWebRESTCAD); // Modify usuarioWebCEN.Modificar(idUsuarioWeb, dto.Nombre , dto.Apellidos , dto.Email ); // Return modified object returnValue = UsuarioWebAssembler.Convert(usuarioWebRESTCAD.ReadOIDDefault(idUsuarioWeb), 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 idUsuarioWeb) { // CAD, CEN, EN, returnValue UsuarioWebRESTCAD usuarioWebRESTCAD = null; UsuarioWebCEN usuarioWebCEN = null; UsuarioWebEN usuarioWebEN = null; UsuarioWebDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); usuarioWebRESTCAD = new UsuarioWebRESTCAD(session); usuarioWebCEN = new UsuarioWebCEN(usuarioWebRESTCAD); // Data usuarioWebEN = usuarioWebCEN.BuscarPorId(idUsuarioWeb); // Convert return if (usuarioWebEN != null) { returnValue = UsuarioWebAssembler.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)); } }