public HttpResponseMessage Borrar(int p_notainformativa_oid) { // CAD, CEN NotaInformativaRESTCAD notaInformativaRESTCAD = null; NotaInformativaCEN notaInformativaCEN = null; try { SessionInitializeTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); notaInformativaRESTCAD = new NotaInformativaRESTCAD(session); notaInformativaCEN = new NotaInformativaCEN(notaInformativaRESTCAD); notaInformativaCEN.Borrar(p_notainformativa_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 static NotaInformativaDTOA Convert(NotaInformativaEN en, NHibernate.ISession session = null) { NotaInformativaDTOA dto = null; NotaInformativaRESTCAD notaInformativaRESTCAD = null; NotaInformativaCEN notaInformativaCEN = null; NotaInformativaCP notaInformativaCP = null; if (en != null) { dto = new NotaInformativaDTOA(); notaInformativaRESTCAD = new NotaInformativaRESTCAD(session); notaInformativaCEN = new NotaInformativaCEN(notaInformativaRESTCAD); notaInformativaCP = new NotaInformativaCP(session); // // Attributes dto.Id = en.Id; dto.Titulo = en.Titulo; dto.Cuerpo = en.Cuerpo; dto.Fecha = en.Fecha; // // TravesalLink // // Service } return(dto); }
public HttpResponseMessage BuscarTodos() { // CAD, CEN, EN, returnValue NotaInformativaRESTCAD notaInformativaRESTCAD = null; NotaInformativaCEN notaInformativaCEN = null; List <NotaInformativaEN> notaInformativaEN = null; List <NotaInformativaDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); notaInformativaRESTCAD = new NotaInformativaRESTCAD(session); notaInformativaCEN = new NotaInformativaCEN(notaInformativaRESTCAD); // Data // TODO: paginación notaInformativaEN = notaInformativaCEN.BuscarTodos(0, -1).ToList(); // Convert return if (notaInformativaEN != null) { returnValue = new List <NotaInformativaDTOA>(); foreach (NotaInformativaEN entry in notaInformativaEN) { returnValue.Add(NotaInformativaAssembler.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 BuscarPorId(int idNotaInformativa) { // CAD, CEN, EN, returnValue NotaInformativaRESTCAD notaInformativaRESTCAD = null; NotaInformativaCEN notaInformativaCEN = null; NotaInformativaEN notaInformativaEN = null; NotaInformativaDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); string token = ""; if (Request.Headers.Authorization != null) { token = Request.Headers.Authorization.ToString(); } int id = new UsuarioCEN().CheckToken(token); notaInformativaRESTCAD = new NotaInformativaRESTCAD(session); notaInformativaCEN = new NotaInformativaCEN(notaInformativaRESTCAD); // Data notaInformativaEN = notaInformativaCEN.BuscarPorId(idNotaInformativa); // Convert return if (notaInformativaEN != null) { returnValue = NotaInformativaAssembler.Convert(notaInformativaEN, 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)); } }
public HttpResponseMessage Modificar(int idNotaInformativa, [FromBody] NotaInformativaDTO dto) { // CAD, CEN, returnValue NotaInformativaRESTCAD notaInformativaRESTCAD = null; NotaInformativaCEN notaInformativaCEN = null; NotaInformativaDTOA 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); notaInformativaRESTCAD = new NotaInformativaRESTCAD(session); notaInformativaCEN = new NotaInformativaCEN(notaInformativaRESTCAD); // Modify notaInformativaCEN.Modificar(idNotaInformativa, dto.Titulo , dto.Cuerpo , dto.Fecha ); // Return modified object returnValue = NotaInformativaAssembler.Convert(notaInformativaRESTCAD.ReadOIDDefault(idNotaInformativa), 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] NotaInformativaDTO dto) { // CAD, CEN, returnValue, returnOID NotaInformativaRESTCAD notaInformativaRESTCAD = null; NotaInformativaCEN notaInformativaCEN = null; NotaInformativaDTOA 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); notaInformativaRESTCAD = new NotaInformativaRESTCAD(session); notaInformativaCEN = new NotaInformativaCEN(notaInformativaRESTCAD); // Create returnOID = notaInformativaCEN.Crear( //Atributo OID: p_usuarioAdministrador // attr.estaRelacionado: true dto.UsuarioAdministrador_oid // association role , //Atributo Primitivo: p_titulo dto.Titulo, //Atributo Primitivo: p_cuerpo dto.Cuerpo); SessionCommit(); // Convert return returnValue = NotaInformativaAssembler.Convert(notaInformativaRESTCAD.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("GetOIDNotaInformativa", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }