public static NivelDTOA Convert(NivelEN en, NHibernate.ISession session = null) { NivelDTOA dto = null; NivelRESTCAD nivelRESTCAD = null; NivelCEN nivelCEN = null; NivelCP nivelCP = null; if (en != null) { dto = new NivelDTOA(); nivelRESTCAD = new NivelRESTCAD(session); nivelCEN = new NivelCEN(nivelRESTCAD); nivelCP = new NivelCP(session); // // Attributes dto.Id = en.Id; dto.Numero = en.Numero; dto.Puntuacion = en.Puntuacion; // // TravesalLink // // Service } return(dto); }
public HttpResponseMessage BuscarPorId(int idNivel) { // CAD, CEN, EN, returnValue NivelRESTCAD nivelRESTCAD = null; NivelCEN nivelCEN = null; NivelEN nivelEN = null; NivelDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); nivelRESTCAD = new NivelRESTCAD(session); nivelCEN = new NivelCEN(nivelRESTCAD); // Data nivelEN = nivelCEN.BuscarPorId(idNivel); // Convert return if (nivelEN != null) { returnValue = NivelAssembler.Convert(nivelEN, 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 NivelItem(int idItem) { // CAD, EN ItemRESTCAD itemRESTCAD = null; ItemEN itemEN = null; // returnValue NivelEN en = null; NivelDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); itemRESTCAD = new ItemRESTCAD(session); // Exists Item itemEN = itemRESTCAD.ReadOIDDefault(idItem); if (itemEN == null) { throw new HttpResponseException(this.Request.CreateResponse(HttpStatusCode.NotFound, "Item#" + idItem + " not found")); } // Rol // TODO: paginación en = itemRESTCAD.NivelItem(idItem); // Convert return if (en != null) { returnValue = NivelAssembler.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)); } }
public HttpResponseMessage Modificar(int idNivel, [FromBody] NivelDTO dto) { // CAD, CEN, returnValue NivelRESTCAD nivelRESTCAD = null; NivelCEN nivelCEN = null; NivelDTOA 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); nivelRESTCAD = new NivelRESTCAD(session); nivelCEN = new NivelCEN(nivelRESTCAD); // Modify nivelCEN.Modificar(idNivel, dto.Numero , dto.Puntuacion ); // Return modified object returnValue = NivelAssembler.Convert(nivelRESTCAD.ReadOIDDefault(idNivel), 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 Crear([FromBody] NivelDTO dto) { // CAD, CEN, returnValue, returnOID NivelRESTCAD nivelRESTCAD = null; NivelCEN nivelCEN = null; NivelDTOA 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); nivelRESTCAD = new NivelRESTCAD(session); nivelCEN = new NivelCEN(nivelRESTCAD); // Create returnOID = nivelCEN.Crear( //Atributo Primitivo: p_numero dto.Numero, //Atributo Primitivo: p_puntuacion dto.Puntuacion); SessionCommit(); // Convert return returnValue = NivelAssembler.Convert(nivelRESTCAD.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("GetOIDNivel", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }