예제 #1
0
        public static AdaptationDetailRequiredDTOA Convert(AdaptationDetailRequiredEN en, NHibernate.ISession session = null)
        {
            AdaptationDetailRequiredDTOA    dto = null;
            AdaptationDetailRequiredRESTCAD adaptationDetailRequiredRESTCAD = null;
            AdaptationDetailRequiredCEN     adaptationDetailRequiredCEN     = null;
            AdaptationDetailRequiredCP      adaptationDetailRequiredCP      = null;

            if (en != null)
            {
                dto = new AdaptationDetailRequiredDTOA();
                adaptationDetailRequiredRESTCAD = new AdaptationDetailRequiredRESTCAD(session);
                adaptationDetailRequiredCEN     = new AdaptationDetailRequiredCEN(adaptationDetailRequiredRESTCAD);
                adaptationDetailRequiredCP      = new AdaptationDetailRequiredCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.AdaptationRequest = en.AdaptationRequest;


                dto.Description = en.Description;


                //
                // TravesalLink


                //
                // Service
            }

            return(dto);
        }
예제 #2
0
        public HttpResponseMessage New_([FromBody] AdaptationDetailRequiredDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            AdaptationDetailRequiredRESTCAD adaptationDetailRequiredRESTCAD = null;
            AdaptationDetailRequiredCEN     adaptationDetailRequiredCEN     = null;
            AdaptationDetailRequiredDTOA    returnValue = null;
            int returnOID = -1;

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

            try
            {
                SessionInitializeTransaction();


                adaptationDetailRequiredRESTCAD = new AdaptationDetailRequiredRESTCAD(session);
                adaptationDetailRequiredCEN     = new AdaptationDetailRequiredCEN(adaptationDetailRequiredRESTCAD);

                // Create
                returnOID = adaptationDetailRequiredCEN.New_(
                    dto.AdaptationRequest                                                                                //Atributo Primitivo: p_adaptationRequest
                    ,
                    //Atributo OID: p_accessMode
                    // attr.estaRelacionado: true
                    dto.AccessMode_oid                     // association role

                    , dto.Description                      //Atributo Primitivo: p_description
                    );
                SessionCommit();

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

            return(response);
        }
예제 #3
0
        public HttpResponseMessage Modify(int idAdaptationDetailRequired, [FromBody] AdaptationDetailRequiredDTO dto)
        {
            // CAD, CEN, returnValue
            AdaptationDetailRequiredRESTCAD adaptationDetailRequiredRESTCAD = null;
            AdaptationDetailRequiredCEN     adaptationDetailRequiredCEN     = null;
            AdaptationDetailRequiredDTOA    returnValue = null;

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

            try
            {
                SessionInitializeTransaction();


                adaptationDetailRequiredRESTCAD = new AdaptationDetailRequiredRESTCAD(session);
                adaptationDetailRequiredCEN     = new AdaptationDetailRequiredCEN(adaptationDetailRequiredRESTCAD);

                // Modify
                adaptationDetailRequiredCEN.Modify(idAdaptationDetailRequired,
                                                   dto.AdaptationRequest
                                                   ,
                                                   dto.Description
                                                   );

                // Return modified object
                returnValue = AdaptationDetailRequiredAssembler.Convert(adaptationDetailRequiredRESTCAD.ReadOIDDefault(idAdaptationDetailRequired), 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 idAdaptationDetailRequired)
        {
            // CAD, CEN, EN, returnValue
            AdaptationDetailRequiredRESTCAD adaptationDetailRequiredRESTCAD = null;
            AdaptationDetailRequiredCEN     adaptationDetailRequiredCEN     = null;
            AdaptationDetailRequiredEN      adaptationDetailRequiredEN      = null;
            AdaptationDetailRequiredDTOA    returnValue = null;

            try
            {
                SessionInitializeWithoutTransaction();


                adaptationDetailRequiredRESTCAD = new AdaptationDetailRequiredRESTCAD(session);
                adaptationDetailRequiredCEN     = new AdaptationDetailRequiredCEN(adaptationDetailRequiredRESTCAD);

                // Data
                adaptationDetailRequiredEN = adaptationDetailRequiredCEN.ReadOID(idAdaptationDetailRequired);

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