public HttpResponseMessage ReadAll() { // CAD, CEN, EN, returnValue AppointmentRESTCAD appointmentRESTCAD = null; AppointmentCEN appointmentCEN = null; List <AppointmentEN> appointmentEN = null; List <AppointmentDTOA> returnValue = null; try { SessionInitializeWithoutTransaction(); appointmentRESTCAD = new AppointmentRESTCAD(session); appointmentCEN = new AppointmentCEN(appointmentRESTCAD); // Data // TODO: paginación appointmentEN = appointmentCEN.ReadAll(0, -1).ToList(); // Convert return if (appointmentEN != null) { returnValue = new List <AppointmentDTOA>(); foreach (AppointmentEN entry in appointmentEN) { returnValue.Add(AppointmentAssembler.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] AppointmentDTO dto) { // CAD, CEN, returnValue, returnOID AppointmentRESTCAD appointmentRESTCAD = null; AppointmentCEN appointmentCEN = null; AppointmentDTOA returnValue = null; int returnOID = -1; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); appointmentRESTCAD = new AppointmentRESTCAD(session); appointmentCEN = new AppointmentCEN(appointmentRESTCAD); // Create returnOID = appointmentCEN.New_( dto.IsVirtual //Atributo Primitivo: p_isVirtual , dto.Description //Atributo Primitivo: p_description , dto.Direction //Atributo Primitivo: p_direction , dto.ReasonCode //Atributo Primitivo: p_reasonCode , //Atributo OID: p_careActivity // attr.estaRelacionado: true dto.CareActivity_oid // association role ); SessionCommit(); // Convert return returnValue = AppointmentAssembler.Convert(appointmentRESTCAD.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("GetOIDAppointment", routeValues); * response.Headers.Location = new Uri(uri); */ return(response); }
public HttpResponseMessage Modify(int idAppointment, [FromBody] AppointmentDTO dto) { // CAD, CEN, returnValue AppointmentRESTCAD appointmentRESTCAD = null; AppointmentCEN appointmentCEN = null; AppointmentDTOA returnValue = null; // HTTP response HttpResponseMessage response = null; string uri = null; try { SessionInitializeTransaction(); appointmentRESTCAD = new AppointmentRESTCAD(session); appointmentCEN = new AppointmentCEN(appointmentRESTCAD); // Modify appointmentCEN.Modify(idAppointment, dto.IsVirtual , dto.Description , dto.Direction , dto.ReasonCode ); // Return modified object returnValue = AppointmentAssembler.Convert(appointmentRESTCAD.ReadOIDDefault(idAppointment), 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 idAppointment) { // CAD, CEN, EN, returnValue AppointmentRESTCAD appointmentRESTCAD = null; AppointmentCEN appointmentCEN = null; AppointmentEN appointmentEN = null; AppointmentDTOA returnValue = null; try { SessionInitializeWithoutTransaction(); appointmentRESTCAD = new AppointmentRESTCAD(session); appointmentCEN = new AppointmentCEN(appointmentRESTCAD); // Data appointmentEN = appointmentCEN.ReadOID(idAppointment); // Convert return if (appointmentEN != null) { returnValue = AppointmentAssembler.Convert(appointmentEN, 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)); } }