Ejemplo n.º 1
0
        public int New_(int p_goal, string p_desiredValue, string p_description, Nullable <DateTime> p_dueDate)
        {
            TargetEN targetEN = null;
            int      oid;

            //Initialized TargetEN
            targetEN = new TargetEN();

            if (p_goal != -1)
            {
                // El argumento p_goal -> Property goal es oid = false
                // Lista de oids id
                targetEN.Goal    = new MoSIoTGenNHibernate.EN.MosIoT.GoalEN();
                targetEN.Goal.Id = p_goal;
            }

            targetEN.DesiredValue = p_desiredValue;

            targetEN.Description = p_description;

            targetEN.DueDate = p_dueDate;

            //Call to TargetCAD

            oid = _ITargetCAD.New_(targetEN);
            return(oid);
        }
Ejemplo n.º 2
0
        public TargetEN ReadOIDDefault(int id
                                       )
        {
            TargetEN targetEN = null;

            try
            {
                SessionInitializeTransaction();
                targetEN = (TargetEN)session.Get(typeof(TargetEN), id);
                SessionCommit();
            }

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


            finally
            {
                SessionClose();
            }

            return(targetEN);
        }
Ejemplo n.º 3
0
        public void Destroy(int id
                            )
        {
            try
            {
                SessionInitializeTransaction();
                TargetEN targetEN = (TargetEN)session.Load(typeof(TargetEN), id);
                session.Delete(targetEN);
                SessionCommit();
            }

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


            finally
            {
                SessionClose();
            }
        }
Ejemplo n.º 4
0
        public void Modify(TargetEN target)
        {
            try
            {
                SessionInitializeTransaction();
                TargetEN targetEN = (TargetEN)session.Load(typeof(TargetEN), target.Id);

                targetEN.DesiredValue = target.DesiredValue;


                targetEN.Description = target.Description;


                targetEN.DueDate = target.DueDate;

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

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


            finally
            {
                SessionClose();
            }
        }
Ejemplo n.º 5
0
        public int New_(TargetEN target)
        {
            try
            {
                SessionInitializeTransaction();
                if (target.Goal != null)
                {
                    // Argumento OID y no colección.
                    target.Goal = (MoSIoTGenNHibernate.EN.MosIoT.GoalEN)session.Load(typeof(MoSIoTGenNHibernate.EN.MosIoT.GoalEN), target.Goal.Id);

                    target.Goal.Targets
                    .Add(target);
                }

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

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


            finally
            {
                SessionClose();
            }

            return(target.Id);
        }
Ejemplo n.º 6
0
        public TargetEN ReadOID(int id
                                )
        {
            TargetEN targetEN = null;

            targetEN = _ITargetCAD.ReadOID(id);
            return(targetEN);
        }
Ejemplo n.º 7
0
        public void Modify(int p_Target_OID, string p_desiredValue, string p_description, Nullable <DateTime> p_dueDate)
        {
            TargetEN targetEN = null;

            //Initialized TargetEN
            targetEN              = new TargetEN();
            targetEN.Id           = p_Target_OID;
            targetEN.DesiredValue = p_desiredValue;
            targetEN.Description  = p_description;
            targetEN.DueDate      = p_dueDate;
            //Call to TargetCAD

            _ITargetCAD.Modify(targetEN);
        }
Ejemplo n.º 8
0
        public static TargetDTOA Convert(TargetEN en, NHibernate.ISession session = null)
        {
            TargetDTOA    dto           = null;
            TargetRESTCAD targetRESTCAD = null;
            TargetCEN     targetCEN     = null;
            TargetCP      targetCP      = null;

            if (en != null)
            {
                dto           = new TargetDTOA();
                targetRESTCAD = new TargetRESTCAD(session);
                targetCEN     = new TargetCEN(targetRESTCAD);
                targetCP      = new TargetCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.DesiredValue = en.DesiredValue;


                dto.Description = en.Description;


                dto.DueDate = en.DueDate;


                //
                // TravesalLink

                /* Rol: Target o--> Measure */
                dto.Measure = MeasureAssembler.Convert((MeasureEN)en.Measure, session);


                //
                // Service
            }

            return(dto);
        }
        public static TargetEN Convert(TargetDTO dto)
        {
            TargetEN newinstance = null;

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



                    newinstance.Id = dto.Id;
                    if (dto.Goal_oid != -1)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IGoalCAD goalCAD = new MoSIoTGenNHibernate.CAD.MosIoT.GoalCAD();

                        newinstance.Goal = goalCAD.ReadOIDDefault(dto.Goal_oid);
                    }
                    newinstance.DesiredValue = dto.DesiredValue;
                    if (dto.Measure_oid != -1)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IMeasureCAD measureCAD = new MoSIoTGenNHibernate.CAD.MosIoT.MeasureCAD();

                        newinstance.Measure = measureCAD.ReadOIDDefault(dto.Measure_oid);
                    }
                    newinstance.Description = dto.Description;
                    newinstance.DueDate     = dto.DueDate;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newinstance);
        }
Ejemplo n.º 10
0
        public HttpResponseMessage ReadOID(int idTarget)
        {
            // CAD, CEN, EN, returnValue
            TargetRESTCAD targetRESTCAD = null;
            TargetCEN     targetCEN     = null;
            TargetEN      targetEN      = null;
            TargetDTOA    returnValue   = null;

            try
            {
                SessionInitializeWithoutTransaction();


                targetRESTCAD = new TargetRESTCAD(session);
                targetCEN     = new TargetCEN(targetRESTCAD);

                // Data
                targetEN = targetCEN.ReadOID(idTarget);

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