예제 #1
0
        public HttpResponseMessage ReadOID(int idEntity)
        {
            // CAD, CEN, EN, returnValue
            EntityRESTCAD entityRESTCAD = null;
            EntityCEN     entityCEN     = null;
            EntityEN      entityEN      = null;
            EntityDTOA    returnValue   = null;

            try
            {
                SessionInitializeWithoutTransaction();


                entityRESTCAD = new EntityRESTCAD(session);
                entityCEN     = new EntityCEN(entityRESTCAD);

                // Data
                entityEN = entityCEN.ReadOID(idEntity);

                // Convert return
                if (entityEN != null)
                {
                    returnValue = EntityAssembler.Convert(entityEN, 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));
            }
        }
예제 #2
0
        public HttpResponseMessage ReadAll()
        {
            // CAD, CEN, EN, returnValue
            EntityRESTCAD entityRESTCAD = null;
            EntityCEN     entityCEN     = null;

            List <EntityEN>   entityEN    = null;
            List <EntityDTOA> returnValue = null;

            try
            {
                SessionInitializeWithoutTransaction();


                entityRESTCAD = new EntityRESTCAD(session);
                entityCEN     = new EntityCEN(entityRESTCAD);

                // Data
                // TODO: paginación

                entityEN = entityCEN.ReadAll(0, -1).ToList();

                // Convert return
                if (entityEN != null)
                {
                    returnValue = new List <EntityDTOA>();
                    foreach (EntityEN entry in entityEN)
                    {
                        returnValue.Add(EntityAssembler.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));
            }
        }
예제 #3
0
        public HttpResponseMessage Entities(int idIoTScenario)
        {
            // CAD, EN
            IoTScenarioRESTCAD ioTScenarioRESTCAD = null;
            IoTScenarioEN      ioTScenarioEN      = null;

            // returnValue
            List <EntityEN>   en          = null;
            List <EntityDTOA> 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.Entities(idIoTScenario).ToList();



                // Convert return
                if (en != null)
                {
                    returnValue = new List <EntityDTOA>();
                    foreach (EntityEN entry in en)
                    {
                        returnValue.Add(EntityAssembler.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));
            }
        }