Example #1
0
        public static IMCommunicationDTOA Convert(EntityEN en, NHibernate.ISession session = null)
        {
            IMCommunicationDTOA    dto = null;
            IMCommunicationRESTCAD iMCommunicationRESTCAD = null;
            IMCommunicationCEN     iMCommunicationCEN     = null;
            IMCommunicationCP      iMCommunicationCP      = null;

            if (en != null)
            {
                dto = new IMCommunicationDTOA();
                iMCommunicationRESTCAD = new IMCommunicationRESTCAD(session);
                iMCommunicationCEN     = new IMCommunicationCEN(iMCommunicationRESTCAD);
                iMCommunicationCP      = new IMCommunicationCP(session);


                IMCommunicationEN enHijo = iMCommunicationRESTCAD.ReadOIDDefault(en.Id);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Name = en.Name;


                dto.Description = en.Description;


                //
                // TravesalLink

                /* Rol: IMCommunication o--> Comunication */
                dto.ValueCommunication = ComunicationAssembler.Convert((ComunicationEN)enHijo.Comunication, session);


                //
                // Service
            }

            return(dto);
        }
Example #2
0
        public HttpResponseMessage Modify(int idIMCommunication, [FromBody] IMCommunicationDTO dto)
        {
            // CAD, CEN, returnValue
            IMCommunicationRESTCAD iMCommunicationRESTCAD = null;
            IMCommunicationCEN     iMCommunicationCEN     = null;
            IMCommunicationDTOA    returnValue            = null;

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

            try
            {
                SessionInitializeTransaction();


                iMCommunicationRESTCAD = new IMCommunicationRESTCAD(session);
                iMCommunicationCEN     = new IMCommunicationCEN(iMCommunicationRESTCAD);

                // Modify
                iMCommunicationCEN.Modify(idIMCommunication,
                                          dto.Name
                                          ,
                                          dto.Description
                                          );

                // Return modified object
                returnValue = IMCommunicationAssembler.Convert(iMCommunicationRESTCAD.ReadOIDDefault(idIMCommunication), 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);
            }
        }
Example #3
0
        public HttpResponseMessage New_([FromBody] IMCommunicationDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            IMCommunicationRESTCAD iMCommunicationRESTCAD = null;
            IMCommunicationCEN     iMCommunicationCEN     = null;
            IMCommunicationDTOA    returnValue            = null;
            int returnOID = -1;

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

            try
            {
                SessionInitializeTransaction();


                iMCommunicationRESTCAD = new IMCommunicationRESTCAD(session);
                iMCommunicationCEN     = new IMCommunicationCEN(iMCommunicationRESTCAD);

                // Create
                returnOID = iMCommunicationCEN.New_(
                    dto.Name                                                                                     //Atributo Primitivo: p_name
                    ,
                    //Atributo OID: p_scenario
                    // attr.estaRelacionado: true
                    dto.Scenario_oid                     // association role

                    , dto.Description                    //Atributo Primitivo: p_description
                    ,
                    //Atributo OID: p_comunication
                    // attr.estaRelacionado: true
                    dto.Comunication_oid                     // association role

                    );
                SessionCommit();

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

            return(response);
        }