public static PatientDTOA Convert(EntityEN en, NHibernate.ISession session = null)
        {
            PatientDTOA    dto            = null;
            PatientRESTCAD patientRESTCAD = null;
            PatientCEN     patientCEN     = null;
            PatientCP      patientCP      = null;

            if (en != null)
            {
                dto            = new PatientDTOA();
                patientRESTCAD = new PatientRESTCAD(session);
                patientCEN     = new PatientCEN(patientRESTCAD);
                patientCP      = new PatientCP(session);


                PatientEN enHijo = patientRESTCAD.ReadOIDDefault(en.Id);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Name = en.Name;


                dto.Description = en.Description;


                //
                // TravesalLink

                /* Rol: Patient o--> PatientProfile */
                dto.PatientProfile = PatientProfileAssembler.Convert((PatientProfileEN)enHijo.PatientProfile, session);

                /* Rol: Patient o--> User */
                dto.UserData = UserAssembler.Convert((UserEN)enHijo.UserPatient, session);


                //
                // Service
            }

            return(dto);
        }
Esempio n. 2
0
        public HttpResponseMessage Modify(int idPatient, [FromBody] PatientDTO dto)
        {
            // CAD, CEN, returnValue
            PatientRESTCAD patientRESTCAD = null;
            PatientCEN     patientCEN     = null;
            PatientDTOA    returnValue    = null;

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

            try
            {
                SessionInitializeTransaction();


                patientRESTCAD = new PatientRESTCAD(session);
                patientCEN     = new PatientCEN(patientRESTCAD);

                // Modify
                patientCEN.Modify(idPatient,
                                  dto.Name
                                  ,
                                  dto.Description
                                  );

                // Return modified object
                returnValue = PatientAssembler.Convert(patientRESTCAD.ReadOIDDefault(idPatient), 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);
            }
        }
Esempio n. 3
0
        public HttpResponseMessage New_([FromBody] PatientDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            PatientRESTCAD patientRESTCAD = null;
            PatientCEN     patientCEN     = null;
            PatientDTOA    returnValue    = null;
            int            returnOID      = -1;

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

            try
            {
                SessionInitializeTransaction();


                patientRESTCAD = new PatientRESTCAD(session);
                patientCEN     = new PatientCEN(patientRESTCAD);

                // Create
                returnOID = patientCEN.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_patientProfile
                    // attr.estaRelacionado: true
                    dto.PatientProfile_oid                     // association role

                    ,
                    //Atributo OID: p_userPatient
                    // attr.estaRelacionado: true
                    dto.UserPatient_oid                     // association role

                    );
                SessionCommit();

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

            return(response);
        }
Esempio n. 4
0
        public HttpResponseMessage ReadOID(int idPatient)
        {
            // CAD, CEN, EN, returnValue
            PatientRESTCAD patientRESTCAD = null;
            PatientCEN     patientCEN     = null;
            PatientEN      patientEN      = null;
            PatientDTOA    returnValue    = null;

            try
            {
                SessionInitializeWithoutTransaction();


                patientRESTCAD = new PatientRESTCAD(session);
                patientCEN     = new PatientCEN(patientRESTCAD);

                // Data
                patientEN = patientCEN.ReadOID(idPatient);

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