Beispiel #1
0
        public HttpResponseMessage ReadAll()
        {
            // CAD, CEN, EN, returnValue
            GoalRESTCAD goalRESTCAD = null;
            GoalCEN     goalCEN     = null;

            List <GoalEN>   goalEN      = null;
            List <GoalDTOA> returnValue = null;

            try
            {
                SessionInitializeWithoutTransaction();


                goalRESTCAD = new GoalRESTCAD(session);
                goalCEN     = new GoalCEN(goalRESTCAD);

                // Data
                // TODO: paginación

                goalEN = goalCEN.ReadAll(0, -1).ToList();

                // Convert return
                if (goalEN != null)
                {
                    returnValue = new List <GoalDTOA>();
                    foreach (GoalEN entry in goalEN)
                    {
                        returnValue.Add(GoalAssembler.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));
            }
        }
Beispiel #2
0
        public HttpResponseMessage New_([FromBody] GoalDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            GoalRESTCAD goalRESTCAD = null;
            GoalCEN     goalCEN     = null;
            GoalDTOA    returnValue = null;
            int         returnOID   = -1;

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

            try
            {
                SessionInitializeTransaction();


                goalRESTCAD = new GoalRESTCAD(session);
                goalCEN     = new GoalCEN(goalRESTCAD);

                // Create
                returnOID = goalCEN.New_(

                    //Atributo OID: p_carePlanTemplate
                    // attr.estaRelacionado: true
                    dto.CarePlanTemplate_oid                     // association role

                    , dto.Priority                               //Atributo Primitivo: p_priority
                    , dto.Status                                 //Atributo Primitivo: p_status
                    ,
                    //Atributo OID: p_condition
                    // attr.estaRelacionado: true
                    dto.Condition_oid                     // association role

                    , dto.Description                     //Atributo Primitivo: p_description
                    , dto.Category                        //Atributo Primitivo: p_category
                    , dto.OutcomeCode                     //Atributo Primitivo: p_outcomeCode
                    , dto.Name                            //Atributo Primitivo: p_name
                    );
                SessionCommit();

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

            return(response);
        }
Beispiel #3
0
        public HttpResponseMessage Modify(int idGoal, [FromBody] GoalDTO dto)
        {
            // CAD, CEN, returnValue
            GoalRESTCAD goalRESTCAD = null;
            GoalCEN     goalCEN     = null;
            GoalDTOA    returnValue = null;

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

            try
            {
                SessionInitializeTransaction();


                goalRESTCAD = new GoalRESTCAD(session);
                goalCEN     = new GoalCEN(goalRESTCAD);

                // Modify
                goalCEN.Modify(idGoal,
                               dto.Priority
                               ,
                               dto.Status
                               ,
                               dto.Description
                               ,
                               dto.Category
                               ,
                               dto.OutcomeCode
                               ,
                               dto.Name
                               );

                // Return modified object
                returnValue = GoalAssembler.Convert(goalRESTCAD.ReadOIDDefault(idGoal), 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);
            }
        }
Beispiel #4
0
        public HttpResponseMessage ReadOID(int idGoal)
        {
            // CAD, CEN, EN, returnValue
            GoalRESTCAD goalRESTCAD = null;
            GoalCEN     goalCEN     = null;
            GoalEN      goalEN      = null;
            GoalDTOA    returnValue = null;

            try
            {
                SessionInitializeWithoutTransaction();


                goalRESTCAD = new GoalRESTCAD(session);
                goalCEN     = new GoalCEN(goalRESTCAD);

                // Data
                goalEN = goalCEN.ReadOID(idGoal);

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