public HttpResponseMessage ReadAll() { // CAD, CEN, EN, returnValue MeasureRESTCAD measureRESTCAD = null; MeasureCEN measureCEN = null; List <MeasureEN> measureEN = null; List <MeasureDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); measureRESTCAD = new MeasureRESTCAD(session); measureCEN = new MeasureCEN(measureRESTCAD); // Data // TODO: paginación measureEN = measureCEN.ReadAll(0, -1).ToList(); // Convert return if (measureEN != null) { returnValue = new List <MeasureDTOA>(); foreach (MeasureEN entry in measureEN) { returnValue.Add(MeasureAssembler.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 New_([FromBody] MeasureDTO dto) { // CAD, CEN, returnValue, returnOID MeasureRESTCAD measureRESTCAD = null; MeasureCEN measureCEN = null; MeasureDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); measureRESTCAD = new MeasureRESTCAD(session); measureCEN = new MeasureCEN(measureRESTCAD); // Create returnOID = measureCEN.New_( dto.Name //Atributo Primitivo: p_name , dto.Description //Atributo Primitivo: p_description , dto.LOINCcode //Atributo Primitivo: p_LOINCcode ); SessionCommit(); // Convert return returnValue = MeasureAssembler.Convert(measureRESTCAD.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("GetOIDMeasure", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage Modify(int idMeasure, [FromBody] MeasureDTO dto) { // CAD, CEN, returnValue MeasureRESTCAD measureRESTCAD = null; MeasureCEN measureCEN = null; MeasureDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); measureRESTCAD = new MeasureRESTCAD(session); measureCEN = new MeasureCEN(measureRESTCAD); // Modify measureCEN.Modify(idMeasure, dto.Name , dto.Description , dto.LOINCcode ); // Return modified object returnValue = MeasureAssembler.Convert(measureRESTCAD.ReadOIDDefault(idMeasure), 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 idMeasure) { // CAD, CEN, EN, returnValue MeasureRESTCAD measureRESTCAD = null; MeasureCEN measureCEN = null; MeasureEN measureEN = null; MeasureDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); measureRESTCAD = new MeasureRESTCAD(session); measureCEN = new MeasureCEN(measureRESTCAD); // Data measureEN = measureCEN.ReadOID(idMeasure); // Convert return if (measureEN != null) { returnValue = MeasureAssembler.Convert(measureEN, 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)); } }