public void GivenExisteUnNivelConIdEspecifico() { nivelCEN = new NivelCEN(); }
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 BuscarTodos() { // CAD, CEN, EN, returnValue NivelRESTCAD nivelRESTCAD = null; NivelCEN nivelCEN = null; List <NivelEN> nivelEN = null; List <NivelDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); 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); // 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 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); }
public HttpResponseMessage BuscarNivelCount( ) { // CAD, CEN, EN, returnValue NivelRESTCAD nivelRESTCAD = null; NivelCEN nivelCEN = null; int returnValue; try { SessionInitializeWithoutTransaction(); 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); // CEN return returnValue = nivelCEN.BuscarNivelCount( ); // Convert return } 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 ReciclaUAGenNHibernate.EN.ReciclaUA.JuegoEN SiguienteItem(int p_oid, ReciclaUAGenNHibernate.Enumerated.ReciclaUA.TipoContenedorEnum p_tipocontenedor) { /*PROTECTED REGION ID(ReciclaUAGenNHibernate.CP.ReciclaUA_Juego_siguienteItem) ENABLED START*/ IJuegoCAD juegoCAD = null; JuegoCEN juegoCEN = null; JuegoEN juegoEN = null; INivelCAD nivelCAD = null; NivelCEN nivelCEN = null; NivelEN nivelEN = null; try { SessionInitializeTransaction(); juegoCAD = new JuegoCAD(session); juegoCEN = new JuegoCEN(juegoCAD); juegoEN = juegoCAD.BuscarPorId(p_oid); nivelCAD = new NivelCAD(session); nivelCEN = new NivelCEN(nivelCAD); IList <NivelEN> niveles = new List <NivelEN>(); ItemCAD Itemcad = new ItemCAD(session); niveles = nivelCAD.BuscarTodos(0, -1); nivelEN = niveles [juegoEN.NivelActual - 1]; IList <ItemEN> itemsen = Itemcad.BuscarItemsPorNivel(nivelEN.Id); if (itemsen [juegoEN.ItemActual].Material.Contenedor == p_tipocontenedor) { //Acierto juegoEN.Aciertos++; //Decimal penalizacion = 1 / juegoEN.IntentosItemActual; Decimal penalizacion = Decimal.Divide(1, juegoEN.IntentosItemActual); juegoEN.Puntuacion += Decimal.ToDouble(Decimal.Multiply(Convert.ToDecimal(nivelEN.Puntuacion), penalizacion)); juegoEN.IntentosItemActual = 1; if (juegoEN.ItemActual + 1 < itemsen.Count) { juegoEN.ItemActual++; } else { juegoEN.ItemActual = 0; niveles = nivelCAD.BuscarTodos(0, -1); if (juegoEN.NivelActual < niveles.Count) { juegoEN.NivelActual++; } else { juegoEN.Finalizado = true; } } } else { //Fallo juegoEN.Fallos++; juegoEN.IntentosItemActual++; } juegoCAD.Modificar(juegoEN); SessionCommit(); } catch (Exception ex) { SessionRollBack(); throw ex; } finally { SessionClose(); } return(juegoEN); /*PROTECTED REGION END*/ }