Example #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));
            }
        }
        public static EntityDTOA Convert(EntityEN en, NHibernate.ISession session = null)
        {
            EntityDTOA    dto           = null;
            EntityRESTCAD entityRESTCAD = null;
            EntityCEN     entityCEN     = null;
            EntityCP      entityCP      = null;

            if (en != null)
            {
                dto           = new EntityDTOA();
                entityRESTCAD = new EntityRESTCAD(session);
                entityCEN     = new EntityCEN(entityRESTCAD);
                entityCP      = new EntityCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                //
                // TravesalLink

                /* Rol: Entity o--> Association */
                dto.OriginAssociations = null;
                List <AssociationEN> OriginAssociations = entityRESTCAD.OriginAssociations(en.Id).ToList();
                if (OriginAssociations != null)
                {
                    dto.OriginAssociations = new List <AssociationDTOA>();
                    foreach (AssociationEN entry in OriginAssociations)
                    {
                        dto.OriginAssociations.Add(AssociationAssembler.Convert(entry, session));
                    }
                }

                /* Rol: Entity o--> Association */
                dto.TargetAssociations = null;
                List <AssociationEN> TargetAssociations = entityRESTCAD.TargetAssociations(en.Id).ToList();
                if (TargetAssociations != null)
                {
                    dto.TargetAssociations = new List <AssociationDTOA>();
                    foreach (AssociationEN entry in TargetAssociations)
                    {
                        dto.TargetAssociations.Add(AssociationAssembler.Convert(entry, session));
                    }
                }

                /* Rol: Entity o--> EntityAttributes */
                dto.Attributes = null;
                List <EntityAttributesEN> Attributes = entityRESTCAD.Attributes(en.Id).ToList();
                if (Attributes != null)
                {
                    dto.Attributes = new List <EntityAttributesDTOA>();
                    foreach (EntityAttributesEN entry in Attributes)
                    {
                        dto.Attributes.Add(EntityAttributesAssembler.Convert(entry, session));
                    }
                }

                /* Rol: Entity o--> EntityOperation */
                dto.Operations = null;
                List <EntityOperationEN> Operations = entityRESTCAD.Operations(en.Id).ToList();
                if (Operations != null)
                {
                    dto.Operations = new List <EntityOperationDTOA>();
                    foreach (EntityOperationEN entry in Operations)
                    {
                        dto.Operations.Add(EntityOperationAssembler.Convert(entry, session));
                    }
                }


                //
                // Service
            }

            return(dto);
        }