public HttpResponseMessage CrearCP([FromBody] DudaDTO dto) { // CAD, CEN, returnValue, returnOID DudaRESTCAD dudaRESTCAD = null; DudaCEN dudaCEN = null; DudaDTOA returnValue = null; DudaCP dudaCP = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); dudaRESTCAD = new DudaRESTCAD(session); dudaCEN = new DudaCEN(dudaRESTCAD); dudaCP = new DudaCP(session); // Create returnOID = dudaCEN.Crear(dto.Titulo, dto.Cuerpo, dto.Usuario_oid, dto.Tema); dudaCP.CrearAccionDuda(returnOID); SessionCommit(); // Convert return returnValue = DudaAssembler.Convert(dudaRESTCAD.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); return(response); }
public HttpResponseMessage RespuestasDuda(int idDuda) { // CAD, EN DudaRESTCAD dudaRESTCAD = null; DudaEN dudaEN = null; // returnValue List <RespuestaEN> en = null; List <RespuestaDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } new UsuarioCEN().CheckToken(token); dudaRESTCAD = new DudaRESTCAD(session); // Exists Duda dudaEN = dudaRESTCAD.ReadOIDDefault(idDuda); if (dudaEN == null) { throw new HttpResponseException(this.Request.CreateResponse(HttpStatusCode.NotFound, "Duda#" + idDuda + " not found")); } // Rol // TODO: paginaciĆ³n en = dudaRESTCAD.RespuestasDuda(idDuda).ToList(); // Convert return if (en != null) { returnValue = new List <RespuestaDTOA>(); foreach (RespuestaEN entry in en) { returnValue.Add(RespuestaAssembler.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 idDuda, [FromBody] DudaDTO dto) { // CAD, CEN, returnValue DudaRESTCAD dudaRESTCAD = null; DudaCEN dudaCEN = null; DudaDTOA 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); dudaRESTCAD = new DudaRESTCAD(session); dudaCEN = new DudaCEN(dudaRESTCAD); // Modify dudaCEN.Modificar(idDuda, dto.Titulo , dto.Cuerpo , dto.Fecha , dto.Util , dto.Tema ); // Return modified object returnValue = DudaAssembler.Convert(dudaRESTCAD.ReadOIDDefault(idDuda), 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] DudaDTO dto) { // CAD, CEN, returnValue, returnOID DudaRESTCAD dudaRESTCAD = null; DudaCEN dudaCEN = null; DudaDTOA 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); dudaRESTCAD = new DudaRESTCAD(session); dudaCEN = new DudaCEN(dudaRESTCAD); // Create returnOID = dudaCEN.Crear( //Atributo Primitivo: p_titulo dto.Titulo, //Atributo Primitivo: p_cuerpo dto.Cuerpo, //Atributo OID: p_usuario // attr.estaRelacionado: true dto.Usuario_oid // association role , //Atributo Primitivo: p_tema dto.Tema); SessionCommit(); // Convert return returnValue = DudaAssembler.Convert(dudaRESTCAD.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("GetOIDDuda", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }