コード例 #1
0
        public HttpResponseMessage ReadAll()
        {
            // CAD, CEN, EN, returnValue
            IMMedicationRESTCAD iMMedicationRESTCAD = null;
            IMMedicationCEN     iMMedicationCEN     = null;

            List <IMMedicationEN>   iMMedicationEN = null;
            List <IMMedicationDTOA> returnValue    = null;

            try
            {
                SessionInitializeWithoutTransaction();


                iMMedicationRESTCAD = new IMMedicationRESTCAD(session);
                iMMedicationCEN     = new IMMedicationCEN(iMMedicationRESTCAD);

                // Data
                // TODO: paginación

                iMMedicationEN = iMMedicationCEN.ReadAll(0, -1).ToList();

                // Convert return
                if (iMMedicationEN != null)
                {
                    returnValue = new List <IMMedicationDTOA>();
                    foreach (IMMedicationEN entry in iMMedicationEN)
                    {
                        returnValue.Add(IMMedicationAssembler.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));
            }
        }
コード例 #2
0
        public HttpResponseMessage New_([FromBody] IMMedicationDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            IMMedicationRESTCAD iMMedicationRESTCAD = null;
            IMMedicationCEN     iMMedicationCEN     = null;
            IMMedicationDTOA    returnValue         = null;
            int returnOID = -1;

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

            try
            {
                SessionInitializeTransaction();


                iMMedicationRESTCAD = new IMMedicationRESTCAD(session);
                iMMedicationCEN     = new IMMedicationCEN(iMMedicationRESTCAD);

                // Create
                returnOID = iMMedicationCEN.New_(
                    dto.Name                                                                                     //Atributo Primitivo: p_name
                    , dto.Type                                                                                   //Atributo Primitivo: p_type
                    , dto.IsOID                                                                                  //Atributo Primitivo: p_isOID
                    , dto.IsWritable                                                                             //Atributo Primitivo: p_isWritable
                    , dto.Description                                                                            //Atributo Primitivo: p_description
                    ,
                    //Atributo OID: p_entity
                    // attr.estaRelacionado: true
                    dto.Entity_oid                     // association role

                    , dto.Value                        //Atributo Primitivo: p_value
                    ,
                    //Atributo OID: p_medication
                    // attr.estaRelacionado: true
                    dto.Medication_oid                     // association role

                    );
                SessionCommit();

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

            return(response);
        }
コード例 #3
0
        public HttpResponseMessage Modify(int idIMMedication, [FromBody] IMMedicationDTO dto)
        {
            // CAD, CEN, returnValue
            IMMedicationRESTCAD iMMedicationRESTCAD = null;
            IMMedicationCEN     iMMedicationCEN     = null;
            IMMedicationDTOA    returnValue         = null;

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

            try
            {
                SessionInitializeTransaction();


                iMMedicationRESTCAD = new IMMedicationRESTCAD(session);
                iMMedicationCEN     = new IMMedicationCEN(iMMedicationRESTCAD);

                // Modify
                iMMedicationCEN.Modify(idIMMedication,
                                       dto.Name
                                       ,
                                       dto.Type
                                       ,
                                       dto.IsOID
                                       ,
                                       dto.IsWritable
                                       ,
                                       dto.Description
                                       ,
                                       dto.Value
                                       );

                // Return modified object
                returnValue = IMMedicationAssembler.Convert(iMMedicationRESTCAD.ReadOIDDefault(idIMMedication), 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);
            }
        }
コード例 #4
0
        public HttpResponseMessage ReadOID(int idIMMedication)
        {
            // CAD, CEN, EN, returnValue
            IMMedicationRESTCAD iMMedicationRESTCAD = null;
            IMMedicationCEN     iMMedicationCEN     = null;
            IMMedicationEN      iMMedicationEN      = null;
            IMMedicationDTOA    returnValue         = null;

            try
            {
                SessionInitializeWithoutTransaction();


                iMMedicationRESTCAD = new IMMedicationRESTCAD(session);
                iMMedicationCEN     = new IMMedicationCEN(iMMedicationRESTCAD);

                // Data
                iMMedicationEN = iMMedicationCEN.ReadOID(idIMMedication);

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