public static IMCommandDTOA Convert(EntityOperationEN en, NHibernate.ISession session = null)
        {
            IMCommandDTOA    dto = null;
            IMCommandRESTCAD iMCommandRESTCAD = null;
            IMCommandCEN     iMCommandCEN     = null;
            IMCommandCP      iMCommandCP      = null;

            if (en != null)
            {
                dto = new IMCommandDTOA();
                iMCommandRESTCAD = new IMCommandRESTCAD(session);
                iMCommandCEN     = new IMCommandCEN(iMCommandRESTCAD);
                iMCommandCP      = new IMCommandCP(session);


                IMCommandEN enHijo = iMCommandRESTCAD.ReadOIDDefault(en.Id);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Name = en.Name;


                dto.Description = en.Description;


                //
                // TravesalLink

                /* Rol: IMCommand o--> Command */
                dto.ValueCommand = CommandAssembler.Convert((CommandEN)enHijo.Command, session);


                //
                // Service
            }

            return(dto);
        }
Пример #2
0
        public HttpResponseMessage Modify(int idIMCommand, [FromBody] IMCommandDTO dto)
        {
            // CAD, CEN, returnValue
            IMCommandRESTCAD iMCommandRESTCAD = null;
            IMCommandCEN     iMCommandCEN     = null;
            IMCommandDTOA    returnValue      = null;

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

            try
            {
                SessionInitializeTransaction();


                iMCommandRESTCAD = new IMCommandRESTCAD(session);
                iMCommandCEN     = new IMCommandCEN(iMCommandRESTCAD);

                // Modify
                iMCommandCEN.Modify(idIMCommand,
                                    dto.Name
                                    ,
                                    dto.Type
                                    ,
                                    dto.ServiceType
                                    ,
                                    dto.Description
                                    );

                // Return modified object
                returnValue = IMCommandAssembler.Convert(iMCommandRESTCAD.ReadOIDDefault(idIMCommand), 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);
            }
        }
Пример #3
0
        public HttpResponseMessage New_([FromBody] IMCommandDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            IMCommandRESTCAD iMCommandRESTCAD = null;
            IMCommandCEN     iMCommandCEN     = null;
            IMCommandDTOA    returnValue      = null;
            int returnOID = -1;

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

            try
            {
                SessionInitializeTransaction();


                iMCommandRESTCAD = new IMCommandRESTCAD(session);
                iMCommandCEN     = new IMCommandCEN(iMCommandRESTCAD);

                // Create
                returnOID = iMCommandCEN.New_(
                    dto.Name                                                                                     //Atributo Primitivo: p_name
                    , dto.Type                                                                                   //Atributo Primitivo: p_type
                    , dto.ServiceType                                                                            //Atributo Primitivo: p_serviceType
                    , dto.Description                                                                            //Atributo Primitivo: p_description
                    ,
                    //Atributo OID: p_entity
                    // attr.estaRelacionado: true
                    dto.Entity_oid                     // association role

                    ,
                    //Atributo OID: p_command
                    // attr.estaRelacionado: true
                    dto.Command_oid                     // association role

                    );
                SessionCommit();

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

            return(response);
        }