public static ContenedorDTOA Convert(ContenedorEN en, NHibernate.ISession session = null) { ContenedorDTOA dto = null; ContenedorRESTCAD contenedorRESTCAD = null; ContenedorCEN contenedorCEN = null; ContenedorCP contenedorCP = null; if (en != null) { dto = new ContenedorDTOA(); contenedorRESTCAD = new ContenedorRESTCAD(session); contenedorCEN = new ContenedorCEN(contenedorRESTCAD); contenedorCP = new ContenedorCP(session); // // Attributes dto.Id = en.Id; dto.Tipo = en.Tipo; // // TravesalLink // // Service } return(dto); }
public HttpResponseMessage Borrar(int p_contenedor_oid) { // CAD, CEN ContenedorRESTCAD contenedorRESTCAD = null; ContenedorCEN contenedorCEN = null; try { SessionInitializeTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); contenedorRESTCAD = new ContenedorRESTCAD(session); contenedorCEN = new ContenedorCEN(contenedorRESTCAD); contenedorCEN.Borrar(p_contenedor_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 Modificar(int idContenedor, [FromBody] ContenedorDTO dto) { // CAD, CEN, returnValue ContenedorRESTCAD contenedorRESTCAD = null; ContenedorCEN contenedorCEN = null; ContenedorDTOA 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); contenedorRESTCAD = new ContenedorRESTCAD(session); contenedorCEN = new ContenedorCEN(contenedorRESTCAD); // Modify contenedorCEN.Modificar(idContenedor, dto.Tipo ); // Return modified object returnValue = ContenedorAssembler.Convert(contenedorRESTCAD.ReadOIDDefault(idContenedor), 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 BuscarTodos() { // CAD, CEN, EN, returnValue ContenedorRESTCAD contenedorRESTCAD = null; ContenedorCEN contenedorCEN = null; List <ContenedorEN> contenedorEN = null; List <ContenedorDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); contenedorRESTCAD = new ContenedorRESTCAD(session); contenedorCEN = new ContenedorCEN(contenedorRESTCAD); // Data // TODO: paginación contenedorEN = contenedorCEN.BuscarTodos(0, -1).ToList(); // Convert return if (contenedorEN != null) { returnValue = new List <ContenedorDTOA>(); foreach (ContenedorEN entry in contenedorEN) { returnValue.Add(ContenedorAssembler.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)); } }
public HttpResponseMessage Crear([FromBody] ContenedorDTO dto) { // CAD, CEN, returnValue, returnOID ContenedorRESTCAD contenedorRESTCAD = null; ContenedorCEN contenedorCEN = null; ContenedorDTOA 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); contenedorRESTCAD = new ContenedorRESTCAD(session); contenedorCEN = new ContenedorCEN(contenedorRESTCAD); // Create returnOID = contenedorCEN.Crear( //Atributo Primitivo: p_tipo dto.Tipo, //Atributo OID: p_punto // attr.estaRelacionado: true dto.Punto_oid // association role ); SessionCommit(); // Convert return returnValue = ContenedorAssembler.Convert(contenedorRESTCAD.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("GetOIDContenedor", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage BuscarPorId(int idContenedor) { // CAD, CEN, EN, returnValue ContenedorRESTCAD contenedorRESTCAD = null; ContenedorCEN contenedorCEN = null; ContenedorEN contenedorEN = null; ContenedorDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); contenedorRESTCAD = new ContenedorRESTCAD(session); contenedorCEN = new ContenedorCEN(contenedorRESTCAD); // Data contenedorEN = contenedorCEN.BuscarPorId(idContenedor); // Convert return if (contenedorEN != null) { returnValue = ContenedorAssembler.Convert(contenedorEN, 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)); } }