public HttpResponseMessage BuscarTodos() { // CAD, CEN, EN, returnValue EdificioRESTCAD edificioRESTCAD = null; EdificioCEN edificioCEN = null; List <EdificioEN> edificioEN = null; List <EdificioDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); edificioRESTCAD = new EdificioRESTCAD(session); edificioCEN = new EdificioCEN(edificioRESTCAD); // Data // TODO: paginación edificioEN = edificioCEN.BuscarTodos(0, -1).ToList(); // Convert return if (edificioEN != null) { returnValue = new List <EdificioDTOA>(); foreach (EdificioEN entry in edificioEN) { returnValue.Add(EdificioAssembler.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 Modificar(int idEdificio, [FromBody] EdificioDTO dto) { // CAD, CEN, returnValue EdificioRESTCAD edificioRESTCAD = null; EdificioCEN edificioCEN = null; EdificioDTOA 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); edificioRESTCAD = new EdificioRESTCAD(session); edificioCEN = new EdificioCEN(edificioRESTCAD); // Modify edificioCEN.Modificar(idEdificio, dto.Nombre ); // Return modified object returnValue = EdificioAssembler.Convert(edificioRESTCAD.ReadOIDDefault(idEdificio), 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 BuscarEdificioPorPlanta(int planta_id) { // CAD, CEN, EN, returnValue EdificioRESTCAD edificioRESTCAD = null; EdificioCEN edificioCEN = null; EdificioEN en; EdificioDTOA returnValue; try { SessionInitializeWithoutTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); edificioRESTCAD = new EdificioRESTCAD(session); edificioCEN = new EdificioCEN(edificioRESTCAD); // CEN return en = edificioCEN.BuscarEdificioPorPlanta(planta_id); // Convert return returnValue = EdificioAssembler.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 Crear([FromBody] EdificioDTO dto) { // CAD, CEN, returnValue, returnOID EdificioRESTCAD edificioRESTCAD = null; EdificioCEN edificioCEN = null; EdificioDTOA 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); edificioRESTCAD = new EdificioRESTCAD(session); edificioCEN = new EdificioCEN(edificioRESTCAD); // Create returnOID = edificioCEN.Crear( //Atributo Primitivo: p_nombre dto.Nombre, //Atributo Primitivo: p_id dto.Id); SessionCommit(); // Convert return returnValue = EdificioAssembler.Convert(edificioRESTCAD.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("GetOIDEdificio", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }