// Modify default (Update all attributes of the class)

        public void ModifyDefault(RangeStateTelemetryEN rangeStateTelemetry)
        {
            try
            {
                SessionInitializeTransaction();
                RangeStateTelemetryEN rangeStateTelemetryEN = (RangeStateTelemetryEN)session.Load(typeof(RangeStateTelemetryEN), rangeStateTelemetry.Id);


                rangeStateTelemetryEN.Name = rangeStateTelemetry.Name;


                rangeStateTelemetryEN.Value = rangeStateTelemetry.Value;

                session.Update(rangeStateTelemetryEN);
                SessionCommit();
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is MoSIoTGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in RangeStateTelemetryCAD.", ex);
            }


            finally
            {
                SessionClose();
            }
        }
        public RangeStateTelemetryEN ReadOIDDefault(int id
                                                    )
        {
            RangeStateTelemetryEN rangeStateTelemetryEN = null;

            try
            {
                SessionInitializeTransaction();
                rangeStateTelemetryEN = (RangeStateTelemetryEN)session.Get(typeof(RangeStateTelemetryEN), id);
                SessionCommit();
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is MoSIoTGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in RangeStateTelemetryCAD.", ex);
            }


            finally
            {
                SessionClose();
            }

            return(rangeStateTelemetryEN);
        }
        public void Destroy(int id
                            )
        {
            try
            {
                SessionInitializeTransaction();
                RangeStateTelemetryEN rangeStateTelemetryEN = (RangeStateTelemetryEN)session.Load(typeof(RangeStateTelemetryEN), id);
                session.Delete(rangeStateTelemetryEN);
                SessionCommit();
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is MoSIoTGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in RangeStateTelemetryCAD.", ex);
            }


            finally
            {
                SessionClose();
            }
        }
        public int New_(RangeStateTelemetryEN rangeStateTelemetry)
        {
            try
            {
                SessionInitializeTransaction();

                session.Save(rangeStateTelemetry);
                SessionCommit();
            }

            catch (Exception ex) {
                SessionRollBack();
                if (ex is MoSIoTGenNHibernate.Exceptions.ModelException)
                {
                    throw ex;
                }
                throw new MoSIoTGenNHibernate.Exceptions.DataLayerException("Error in RangeStateTelemetryCAD.", ex);
            }


            finally
            {
                SessionClose();
            }

            return(rangeStateTelemetry.Id);
        }
        public static RangeStateTelemetryEN Convert(RangeStateTelemetryDTO dto)
        {
            RangeStateTelemetryEN newinstance = null;

            try
            {
                if (dto != null)
                {
                    newinstance = new RangeStateTelemetryEN();



                    if (dto.StateTelemetry_oid != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IStateTelemetryCAD stateTelemetryCAD = new MoSIoTGenNHibernate.CAD.MosIoT.StateTelemetryCAD();

                        newinstance.StateTelemetry = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.StateTelemetryEN>();
                        foreach (int entry in dto.StateTelemetry_oid)
                        {
                            newinstance.StateTelemetry.Add(stateTelemetryCAD.ReadOIDDefault(entry));
                        }
                    }
                    newinstance.Id    = dto.Id;
                    newinstance.Name  = dto.Name;
                    newinstance.Value = dto.Value;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newinstance);
        }
        public static RangeStateTelemetryDTOA Convert(RangeStateTelemetryEN en, NHibernate.ISession session = null)
        {
            RangeStateTelemetryDTOA    dto = null;
            RangeStateTelemetryRESTCAD rangeStateTelemetryRESTCAD = null;
            RangeStateTelemetryCEN     rangeStateTelemetryCEN     = null;
            RangeStateTelemetryCP      rangeStateTelemetryCP      = null;

            if (en != null)
            {
                dto = new RangeStateTelemetryDTOA();
                rangeStateTelemetryRESTCAD = new RangeStateTelemetryRESTCAD(session);
                rangeStateTelemetryCEN     = new RangeStateTelemetryCEN(rangeStateTelemetryRESTCAD);
                rangeStateTelemetryCP      = new RangeStateTelemetryCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Name = en.Name;


                dto.Value = en.Value;


                //
                // TravesalLink


                //
                // Service
            }

            return(dto);
        }
Example #7
0
        public HttpResponseMessage ReadOID(int idRangeStateTelemetry)
        {
            // CAD, CEN, EN, returnValue
            RangeStateTelemetryRESTCAD rangeStateTelemetryRESTCAD = null;
            RangeStateTelemetryCEN     rangeStateTelemetryCEN     = null;
            RangeStateTelemetryEN      rangeStateTelemetryEN      = null;
            RangeStateTelemetryDTOA    returnValue = null;

            try
            {
                SessionInitializeWithoutTransaction();


                rangeStateTelemetryRESTCAD = new RangeStateTelemetryRESTCAD(session);
                rangeStateTelemetryCEN     = new RangeStateTelemetryCEN(rangeStateTelemetryRESTCAD);

                // Data
                rangeStateTelemetryEN = rangeStateTelemetryCEN.ReadOID(idRangeStateTelemetry);

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