public HttpResponseMessage ReadAll() { // CAD, CEN, EN, returnValue PractitionerRESTCAD practitionerRESTCAD = null; PractitionerCEN practitionerCEN = null; List <PractitionerEN> practitionerEN = null; List <PractitionerDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); practitionerRESTCAD = new PractitionerRESTCAD(session); practitionerCEN = new PractitionerCEN(practitionerRESTCAD); // Data // TODO: paginación practitionerEN = practitionerCEN.ReadAll(0, -1).ToList(); // Convert return if (practitionerEN != null) { returnValue = new List <PractitionerDTOA>(); foreach (PractitionerEN entry in practitionerEN) { returnValue.Add(PractitionerAssembler.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 idPractitioner, [FromBody] PractitionerDTO dto) { // CAD, CEN, returnValue PractitionerRESTCAD practitionerRESTCAD = null; PractitionerCEN practitionerCEN = null; PractitionerDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); practitionerRESTCAD = new PractitionerRESTCAD(session); practitionerCEN = new PractitionerCEN(practitionerRESTCAD); // Modify practitionerCEN.Modify(idPractitioner, dto.Name , dto.Description ); // Return modified object returnValue = PractitionerAssembler.Convert(practitionerRESTCAD.ReadOIDDefault(idPractitioner), 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 idPractitioner) { // CAD, CEN, EN, returnValue PractitionerRESTCAD practitionerRESTCAD = null; PractitionerCEN practitionerCEN = null; PractitionerEN practitionerEN = null; PractitionerDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); practitionerRESTCAD = new PractitionerRESTCAD(session); practitionerCEN = new PractitionerCEN(practitionerRESTCAD); // Data practitionerEN = practitionerCEN.ReadOID(idPractitioner); // Convert return if (practitionerEN != null) { returnValue = PractitionerAssembler.Convert(practitionerEN, 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] PractitionerDTO dto) { // CAD, CEN, returnValue, returnOID PractitionerRESTCAD practitionerRESTCAD = null; PractitionerCEN practitionerCEN = null; PractitionerDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); practitionerRESTCAD = new PractitionerRESTCAD(session); practitionerCEN = new PractitionerCEN(practitionerRESTCAD); // Create returnOID = practitionerCEN.New_( dto.Name //Atributo Primitivo: p_name , //Atributo OID: p_scenario // attr.estaRelacionado: true dto.Scenario_oid // association role , dto.Description //Atributo Primitivo: p_description , //Atributo OID: p_userPractitioner // attr.estaRelacionado: true dto.UserPractitioner_oid // association role ); SessionCommit(); // Convert return returnValue = PractitionerAssembler.Convert(practitionerRESTCAD.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("GetOIDPractitioner", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage Practitioners(int idIoTScenario) { // CAD, EN IoTScenarioRESTCAD ioTScenarioRESTCAD = null; IoTScenarioEN ioTScenarioEN = null; // returnValue List <PractitionerEN> en = null; List <PractitionerDTOA> 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.Practitioners(idIoTScenario).ToList(); // Convert return if (en != null) { returnValue = new List <PractitionerDTOA>(); foreach (PractitionerEN entry in en) { returnValue.Add(PractitionerAssembler.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)); } }