public HttpResponseMessage Destroy(int p_patientaccess_oid)
        {
            // CAD, CEN
            PatientAccessRESTCAD patientAccessRESTCAD = null;
            PatientAccessCEN     patientAccessCEN     = null;

            try
            {
                SessionInitializeTransaction();


                patientAccessRESTCAD = new PatientAccessRESTCAD(session);
                patientAccessCEN     = new PatientAccessCEN(patientAccessRESTCAD);

                patientAccessCEN.Destroy(p_patientaccess_oid);
                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 204 - No Content
            return(this.Request.CreateResponse(HttpStatusCode.NoContent));
        }
Esempio n. 2
0
public static PatientAccessDTOA Convert (EntityEN en, NHibernate.ISession session = null)
{
        PatientAccessDTOA dto = null;
        PatientAccessRESTCAD patientAccessRESTCAD = null;
        PatientAccessCEN patientAccessCEN = null;
        PatientAccessCP patientAccessCP = null;

        if (en != null) {
                dto = new PatientAccessDTOA ();
                patientAccessRESTCAD = new PatientAccessRESTCAD (session);
                patientAccessCEN = new PatientAccessCEN (patientAccessRESTCAD);
                patientAccessCP = new PatientAccessCP (session);


                PatientAccessEN enHijo = patientAccessRESTCAD.ReadOIDDefault (en.Id);




                //
                // Attributes

                dto.Id = en.Id;

                dto.Name = en.Name;


                dto.Description = en.Description;


                //
                // TravesalLink

                /* Rol: PatientAccess o--> AccessMode */
                dto.AccessMode = AccessModeAssembler.Convert ((AccessModeEN)enHijo.AccessMode, session);


                //
                // Service
        }

        return dto;
}
        public HttpResponseMessage ReadAll()
        {
            // CAD, CEN, EN, returnValue
            PatientAccessRESTCAD patientAccessRESTCAD = null;
            PatientAccessCEN     patientAccessCEN     = null;

            List <PatientAccessEN>   patientAccessEN = null;
            List <PatientAccessDTOA> returnValue     = null;

            try
            {
                SessionInitializeWithoutTransaction();


                patientAccessRESTCAD = new PatientAccessRESTCAD(session);
                patientAccessCEN     = new PatientAccessCEN(patientAccessRESTCAD);

                // Data
                // TODO: paginación

                patientAccessEN = patientAccessCEN.ReadAll(0, -1).ToList();

                // Convert return
                if (patientAccessEN != null)
                {
                    returnValue = new List <PatientAccessDTOA>();
                    foreach (PatientAccessEN entry in patientAccessEN)
                    {
                        returnValue.Add(PatientAccessAssembler.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 idPatientAccess, [FromBody] PatientAccessDTO dto)
        {
            // CAD, CEN, returnValue
            PatientAccessRESTCAD patientAccessRESTCAD = null;
            PatientAccessCEN     patientAccessCEN     = null;
            PatientAccessDTOA    returnValue          = null;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();


                patientAccessRESTCAD = new PatientAccessRESTCAD(session);
                patientAccessCEN     = new PatientAccessCEN(patientAccessRESTCAD);

                // Modify
                patientAccessCEN.Modify(idPatientAccess,
                                        dto.Name
                                        ,
                                        dto.Description
                                        );

                // Return modified object
                returnValue = PatientAccessAssembler.Convert(patientAccessRESTCAD.ReadOIDDefault(idPatientAccess), 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 New_([FromBody] PatientAccessDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            PatientAccessRESTCAD patientAccessRESTCAD = null;
            PatientAccessCEN     patientAccessCEN     = null;
            PatientAccessDTOA    returnValue          = null;
            int returnOID = -1;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();


                patientAccessRESTCAD = new PatientAccessRESTCAD(session);
                patientAccessCEN     = new PatientAccessCEN(patientAccessRESTCAD);

                // Create
                returnOID = patientAccessCEN.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_accessMode
                    // attr.estaRelacionado: true
                    dto.AccessMode_oid                     // association role

                    );
                SessionCommit();

                // Convert return
                returnValue = PatientAccessAssembler.Convert(patientAccessRESTCAD.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("GetOIDPatientAccess", routeValues);
             * response.Headers.Location = new Uri(uri);
             */

            return(response);
        }
        public HttpResponseMessage ReadOID(int idPatientAccess)
        {
            // CAD, CEN, EN, returnValue
            PatientAccessRESTCAD patientAccessRESTCAD = null;
            PatientAccessCEN     patientAccessCEN     = null;
            PatientAccessEN      patientAccessEN      = null;
            PatientAccessDTOA    returnValue          = null;

            try
            {
                SessionInitializeWithoutTransaction();


                patientAccessRESTCAD = new PatientAccessRESTCAD(session);
                patientAccessCEN     = new PatientAccessCEN(patientAccessRESTCAD);

                // Data
                patientAccessEN = patientAccessCEN.ReadOID(idPatientAccess);

                // Convert return
                if (patientAccessEN != null)
                {
                    returnValue = PatientAccessAssembler.Convert(patientAccessEN, 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));
            }
        }