public HttpResponseMessage New_([FromBody] IMDisabilityDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            IMDisabilityRESTCAD iMDisabilityRESTCAD = null;
            IMDisabilityCEN     iMDisabilityCEN     = null;
            IMDisabilityDTOA    returnValue         = null;
            int returnOID = -1;

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

            try
            {
                SessionInitializeTransaction();


                iMDisabilityRESTCAD = new IMDisabilityRESTCAD(session);
                iMDisabilityCEN     = new IMDisabilityCEN(iMDisabilityRESTCAD);

                // Create
                returnOID = iMDisabilityCEN.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_disability
                    // attr.estaRelacionado: true
                    dto.Disability_oid                     // association role

                    );
                SessionCommit();

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

            return(response);
        }
        public HttpResponseMessage Modify(int idIMDisability, [FromBody] IMDisabilityDTO dto)
        {
            // CAD, CEN, returnValue
            IMDisabilityRESTCAD iMDisabilityRESTCAD = null;
            IMDisabilityCEN     iMDisabilityCEN     = null;
            IMDisabilityDTOA    returnValue         = null;

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

            try
            {
                SessionInitializeTransaction();


                iMDisabilityRESTCAD = new IMDisabilityRESTCAD(session);
                iMDisabilityCEN     = new IMDisabilityCEN(iMDisabilityRESTCAD);

                // Modify
                iMDisabilityCEN.Modify(idIMDisability,
                                       dto.Name
                                       ,
                                       dto.Type
                                       ,
                                       dto.IsOID
                                       ,
                                       dto.IsWritable
                                       ,
                                       dto.Description
                                       ,
                                       dto.Value
                                       );

                // Return modified object
                returnValue = IMDisabilityAssembler.Convert(iMDisabilityRESTCAD.ReadOIDDefault(idIMDisability), 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);
            }
        }
Exemple #3
0
        public static IMDisabilityEN Convert(IMDisabilityDTO dto)
        {
            IMDisabilityEN newinstance = null;

            try
            {
                if (dto != null)
                {
                    newinstance = new IMDisabilityEN();



                    if (dto.Disability_oid != -1)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IDisabilityCAD disabilityCAD = new MoSIoTGenNHibernate.CAD.MosIoT.DisabilityCAD();

                        newinstance.Disability = disabilityCAD.ReadOIDDefault(dto.Disability_oid);
                    }
                    newinstance.Id    = dto.Id;
                    newinstance.Name  = dto.Name;
                    newinstance.Type  = dto.Type;
                    newinstance.IsOID = dto.IsOID;
                    if (dto.TargetAssociation_oid != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IAssociationCAD associationCAD = new MoSIoTGenNHibernate.CAD.MosIoT.AssociationCAD();

                        newinstance.TargetAssociation = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.AssociationEN>();
                        foreach (int entry in dto.TargetAssociation_oid)
                        {
                            newinstance.TargetAssociation.Add(associationCAD.ReadOIDDefault(entry));
                        }
                    }
                    if (dto.OriginAsociation_oid != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IAssociationCAD associationCAD = new MoSIoTGenNHibernate.CAD.MosIoT.AssociationCAD();

                        newinstance.OriginAsociation = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.AssociationEN>();
                        foreach (int entry in dto.OriginAsociation_oid)
                        {
                            newinstance.OriginAsociation.Add(associationCAD.ReadOIDDefault(entry));
                        }
                    }
                    newinstance.AssociationType = dto.AssociationType;
                    newinstance.IsWritable      = dto.IsWritable;
                    newinstance.Description     = dto.Description;
                    if (dto.Entity_oid != -1)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IEntityCAD entityCAD = new MoSIoTGenNHibernate.CAD.MosIoT.EntityCAD();

                        newinstance.Entity = entityCAD.ReadOIDDefault(dto.Entity_oid);
                    }
                    if (dto.Trigger_oid != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IRecipeTriggerCAD recipeTriggerCAD = new MoSIoTGenNHibernate.CAD.MosIoT.RecipeTriggerCAD();

                        newinstance.Trigger = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.RecipeTriggerEN>();
                        foreach (int entry in dto.Trigger_oid)
                        {
                            newinstance.Trigger.Add(recipeTriggerCAD.ReadOIDDefault(entry));
                        }
                    }
                    if (dto.Register_oid != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IRegisterCAD registerCAD = new MoSIoTGenNHibernate.CAD.MosIoT.RegisterCAD();

                        newinstance.Register = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.RegisterEN>();
                        foreach (int entry in dto.Register_oid)
                        {
                            newinstance.Register.Add(registerCAD.ReadOIDDefault(entry));
                        }
                    }
                    newinstance.Value = dto.Value;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newinstance);
        }