public HttpResponseMessage BuscarTodos() { // CAD, CEN, EN, returnValue NivelRESTCAD nivelRESTCAD = null; NivelCEN nivelCEN = null; List <NivelEN> nivelEN = null; List <NivelDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); nivelRESTCAD = new NivelRESTCAD(session); nivelCEN = new NivelCEN(nivelRESTCAD); // Data // TODO: paginación nivelEN = nivelCEN.BuscarTodos(0, -1).ToList(); // Convert return if (nivelEN != null) { returnValue = new List <NivelDTOA>(); foreach (NivelEN entry in nivelEN) { returnValue.Add(NivelAssembler.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 void WhenObtengoLosNiveles() { niveles = nivelCEN.BuscarTodos(0, -1); }