示例#1
0
        public HttpResponseMessage ReadAll()
        {
            // CAD, CEN, EN, returnValue
            IMCommunicationRESTCAD iMCommunicationRESTCAD = null;
            IMCommunicationCEN     iMCommunicationCEN     = null;

            List <IMCommunicationEN>   iMCommunicationEN = null;
            List <IMCommunicationDTOA> returnValue       = null;

            try
            {
                SessionInitializeWithoutTransaction();


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

                // Data
                // TODO: paginación

                iMCommunicationEN = iMCommunicationCEN.ReadAll(0, -1).ToList();

                // Convert return
                if (iMCommunicationEN != null)
                {
                    returnValue = new List <IMCommunicationDTOA>();
                    foreach (IMCommunicationEN entry in iMCommunicationEN)
                    {
                        returnValue.Add(IMCommunicationAssembler.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));
            }
        }
示例#2
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);
        }
示例#3
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);
            }
        }
示例#4
0
        public HttpResponseMessage ReadOID(int idIMCommunication)
        {
            // CAD, CEN, EN, returnValue
            IMCommunicationRESTCAD iMCommunicationRESTCAD = null;
            IMCommunicationCEN     iMCommunicationCEN     = null;
            IMCommunicationEN      iMCommunicationEN      = null;
            IMCommunicationDTOA    returnValue            = null;

            try
            {
                SessionInitializeWithoutTransaction();


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

                // Data
                iMCommunicationEN = iMCommunicationCEN.ReadOID(idIMCommunication);

                // Convert return
                if (iMCommunicationEN != null)
                {
                    returnValue = IMCommunicationAssembler.Convert(iMCommunicationEN, 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));
            }
        }