public HttpResponseMessage ReadAll() { // CAD, CEN, EN, returnValue VitalSignRESTCAD vitalSignRESTCAD = null; VitalSignCEN vitalSignCEN = null; List <VitalSignEN> vitalSignEN = null; List <VitalSignDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); vitalSignRESTCAD = new VitalSignRESTCAD(session); vitalSignCEN = new VitalSignCEN(vitalSignRESTCAD); // Data // TODO: paginación vitalSignEN = vitalSignCEN.ReadAll(0, -1).ToList(); // Convert return if (vitalSignEN != null) { returnValue = new List <VitalSignDTOA>(); foreach (VitalSignEN entry in vitalSignEN) { returnValue.Add(VitalSignAssembler.Convert(entry, session)); } } } catch (Exception e) { if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.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 Modify(int idVitalSign, [FromBody] VitalSignDTO dto) { // CAD, CEN, returnValue VitalSignRESTCAD vitalSignRESTCAD = null; VitalSignCEN vitalSignCEN = null; VitalSignDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); vitalSignRESTCAD = new VitalSignRESTCAD(session); vitalSignCEN = new VitalSignCEN(vitalSignRESTCAD); // Modify vitalSignCEN.Modify(idVitalSign, dto.Name , dto.Description ); // Return modified object returnValue = VitalSignAssembler.Convert(vitalSignRESTCAD.ReadOIDDefault(idVitalSign), session); SessionCommit(); } catch (Exception e) { SessionRollBack(); if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.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 ReadOID(int idVitalSign) { // CAD, CEN, EN, returnValue VitalSignRESTCAD vitalSignRESTCAD = null; VitalSignCEN vitalSignCEN = null; VitalSignEN vitalSignEN = null; VitalSignDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); vitalSignRESTCAD = new VitalSignRESTCAD(session); vitalSignCEN = new VitalSignCEN(vitalSignRESTCAD); // Data vitalSignEN = vitalSignCEN.ReadOID(idVitalSign); // Convert return if (vitalSignEN != null) { returnValue = VitalSignAssembler.Convert(vitalSignEN, session); } } catch (Exception e) { if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.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 New_([FromBody] VitalSignDTO dto) { // CAD, CEN, returnValue, returnOID VitalSignRESTCAD vitalSignRESTCAD = null; VitalSignCEN vitalSignCEN = null; VitalSignDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); vitalSignRESTCAD = new VitalSignRESTCAD(session); vitalSignCEN = new VitalSignCEN(vitalSignRESTCAD); // Create returnOID = vitalSignCEN.New_( //Atributo Primitivo: p_name dto.Name, //Atributo Primitivo: p_description dto.Description, //Atributo OID: p_carePlan // attr.estaRelacionado: true dto.CarePlan_oid // association role ); SessionCommit(); // Convert return returnValue = VitalSignAssembler.Convert(vitalSignRESTCAD.ReadOIDDefault(returnOID), session); } catch (Exception e) { SessionRollBack(); if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.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("GetOIDVitalSign", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage VitalSigns(int idIoTScenario) { // CAD, EN IoTScenarioRESTCAD ioTScenarioRESTCAD = null; IoTScenarioEN ioTScenarioEN = null; // returnValue List <VitalSignEN> en = null; List <VitalSignDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); ioTScenarioRESTCAD = new IoTScenarioRESTCAD(session); // Exists IoTScenario ioTScenarioEN = ioTScenarioRESTCAD.ReadOIDDefault(idIoTScenario); if (ioTScenarioEN == null) { throw new HttpResponseException(this.Request.CreateResponse(HttpStatusCode.NotFound, "IoTScenario#" + idIoTScenario + " not found")); } // Rol // TODO: paginación en = ioTScenarioRESTCAD.VitalSigns(idIoTScenario).ToList(); // Convert return if (en != null) { returnValue = new List <VitalSignDTOA>(); foreach (VitalSignEN entry in en) { returnValue.Add(VitalSignAssembler.Convert(entry, session)); } } } catch (Exception e) { if (e.GetType() == typeof(HttpResponseException)) { throw e; } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto")) { throw new HttpResponseException(HttpStatusCode.Forbidden); } else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.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)); } }