Example #1
0
        public static IMAppointmentDTOA Convert(EntityEN en, NHibernate.ISession session = null)
        {
            IMAppointmentDTOA    dto = null;
            IMAppointmentRESTCAD iMAppointmentRESTCAD = null;
            IMAppointmentCEN     iMAppointmentCEN     = null;
            IMAppointmentCP      iMAppointmentCP      = null;

            if (en != null)
            {
                dto = new IMAppointmentDTOA();
                iMAppointmentRESTCAD = new IMAppointmentRESTCAD(session);
                iMAppointmentCEN     = new IMAppointmentCEN(iMAppointmentRESTCAD);
                iMAppointmentCP      = new IMAppointmentCP(session);


                IMAppointmentEN enHijo = iMAppointmentRESTCAD.ReadOIDDefault(en.Id);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Name = en.Name;


                if (enHijo != null)
                {
                    dto.Date = enHijo.Date;
                }


                dto.Description = en.Description;


                //
                // TravesalLink

                /* Rol: IMAppointment o--> Appointment */
                dto.ValueAppointment = AppointmentAssembler.Convert((AppointmentEN)enHijo.Appointment, session);


                //
                // Service
            }

            return(dto);
        }
Example #2
0
        public HttpResponseMessage New_([FromBody] IMAppointmentDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            IMAppointmentRESTCAD iMAppointmentRESTCAD = null;
            IMAppointmentCEN     iMAppointmentCEN     = null;
            IMAppointmentDTOA    returnValue          = null;
            int returnOID = -1;

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

            try
            {
                SessionInitializeTransaction();


                iMAppointmentRESTCAD = new IMAppointmentRESTCAD(session);
                iMAppointmentCEN     = new IMAppointmentCEN(iMAppointmentRESTCAD);

                // Create
                returnOID = iMAppointmentCEN.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
                    , dto.Date                           //Atributo Primitivo: p_date
                    ,
                    //Atributo OID: p_appointment
                    // attr.estaRelacionado: true
                    dto.Appointment_oid                     // association role

                    );
                SessionCommit();

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

            return(response);
        }
Example #3
0
        public HttpResponseMessage Modify(int idIMAppointment, [FromBody] IMAppointmentDTO dto)
        {
            // CAD, CEN, returnValue
            IMAppointmentRESTCAD iMAppointmentRESTCAD = null;
            IMAppointmentCEN     iMAppointmentCEN     = null;
            IMAppointmentDTOA    returnValue          = null;

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

            try
            {
                SessionInitializeTransaction();


                iMAppointmentRESTCAD = new IMAppointmentRESTCAD(session);
                iMAppointmentCEN     = new IMAppointmentCEN(iMAppointmentRESTCAD);

                // Modify
                iMAppointmentCEN.Modify(idIMAppointment,
                                        dto.Name
                                        ,
                                        dto.Description
                                        ,
                                        dto.Date
                                        );

                // Return modified object
                returnValue = IMAppointmentAssembler.Convert(iMAppointmentRESTCAD.ReadOIDDefault(idIMAppointment), 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 #4
0
        public HttpResponseMessage ReadOID(int idIMAppointment)
        {
            // CAD, CEN, EN, returnValue
            IMAppointmentRESTCAD iMAppointmentRESTCAD = null;
            IMAppointmentCEN     iMAppointmentCEN     = null;
            IMAppointmentEN      iMAppointmentEN      = null;
            IMAppointmentDTOA    returnValue          = null;

            try
            {
                SessionInitializeWithoutTransaction();


                iMAppointmentRESTCAD = new IMAppointmentRESTCAD(session);
                iMAppointmentCEN     = new IMAppointmentCEN(iMAppointmentRESTCAD);

                // Data
                iMAppointmentEN = iMAppointmentCEN.ReadOID(idIMAppointment);

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