public static PuntoReciclajeDTOA Convert(PuntoReciclajeEN en, NHibernate.ISession session = null)
        {
            PuntoReciclajeDTOA    dto = null;
            PuntoReciclajeRESTCAD puntoReciclajeRESTCAD = null;
            PuntoReciclajeCEN     puntoReciclajeCEN     = null;
            PuntoReciclajeCP      puntoReciclajeCP      = null;

            if (en != null)
            {
                dto = new PuntoReciclajeDTOA();
                puntoReciclajeRESTCAD = new PuntoReciclajeRESTCAD(session);
                puntoReciclajeCEN     = new PuntoReciclajeCEN(puntoReciclajeRESTCAD);
                puntoReciclajeCP      = new PuntoReciclajeCP(session);



                //
                // Attributes

                dto.Id = en.Id;

                dto.Latitud = en.Latitud;


                dto.Longitud = en.Longitud;


                dto.EsValido = en.EsValido;


                //
                // TravesalLink

                /* Rol: PuntoReciclaje o--> Contenedor */
                dto.Contenedores = null;
                List <ContenedorEN> Contenedores = puntoReciclajeRESTCAD.Contenedores(en.Id).ToList();
                if (Contenedores != null)
                {
                    dto.Contenedores = new List <ContenedorDTOA>();
                    foreach (ContenedorEN entry in Contenedores)
                    {
                        dto.Contenedores.Add(ContenedorAssembler.Convert(entry, session));
                    }
                }

                /* Rol: PuntoReciclaje o--> Estancia */
                dto.EstanciaPunto = EstanciaAssembler.Convert((EstanciaEN)en.Estancia, session);


                //
                // Service
            }

            return(dto);
        }
Example #2
0
        public HttpResponseMessage Modificar(int idPuntoReciclaje, [FromBody] PuntoReciclajeDTO dto)
        {
            // CAD, CEN, returnValue
            PuntoReciclajeRESTCAD puntoReciclajeRESTCAD = null;
            PuntoReciclajeCEN     puntoReciclajeCEN     = null;
            PuntoReciclajeDTOA    returnValue           = null;

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

            try
            {
                SessionInitializeTransaction();
                string token = "";
                if (Request.Headers.Authorization != null)
                {
                    token = Request.Headers.Authorization.ToString();
                }
                int id = new UsuarioCEN().CheckToken(token);



                puntoReciclajeRESTCAD = new PuntoReciclajeRESTCAD(session);
                puntoReciclajeCEN     = new PuntoReciclajeCEN(puntoReciclajeRESTCAD);

                // Modify
                puntoReciclajeCEN.Modificar(idPuntoReciclaje,
                                            dto.Latitud
                                            ,
                                            dto.Longitud
                                            ,
                                            dto.EsValido
                                            );

                // Return modified object
                returnValue = PuntoReciclajeAssembler.Convert(puntoReciclajeRESTCAD.ReadOIDDefault(idPuntoReciclaje), session);

                SessionCommit();
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.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 #3
0
        public HttpResponseMessage Crear([FromBody] PuntoReciclajeDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            PuntoReciclajeRESTCAD puntoReciclajeRESTCAD = null;
            PuntoReciclajeCEN     puntoReciclajeCEN     = null;
            PuntoReciclajeDTOA    returnValue           = null;
            int returnOID = -1;

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

            try
            {
                SessionInitializeTransaction();
                string token = "";
                if (Request.Headers.Authorization != null)
                {
                    token = Request.Headers.Authorization.ToString();
                }
                int id = new UsuarioCEN().CheckToken(token);



                puntoReciclajeRESTCAD = new PuntoReciclajeRESTCAD(session);
                puntoReciclajeCEN     = new PuntoReciclajeCEN(puntoReciclajeRESTCAD);

                // Create
                returnOID = puntoReciclajeCEN.Crear(
                    //Atributo Primitivo: p_latitud
                    dto.Latitud,                        //Atributo Primitivo: p_longitud
                    dto.Longitud,                       //Atributo OID: p_usuario
                    // attr.estaRelacionado: true
                    dto.Usuario_oid                     // association role

                    ,                                   //Atributo OID: p_estancia
                    // attr.estaRelacionado: true
                    dto.Estancia_oid                    // association role

                    );
                SessionCommit();

                // Convert return
                returnValue = PuntoReciclajeAssembler.Convert(puntoReciclajeRESTCAD.ReadOIDDefault(returnOID), session);
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.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("GetOIDPuntoReciclaje", routeValues);
             * response.Headers.Location = new Uri(uri);
             */

            return(response);
        }
Example #4
0
        public HttpResponseMessage BuscarPorId(int idPuntoReciclaje)
        {
            // CAD, CEN, EN, returnValue
            PuntoReciclajeRESTCAD puntoReciclajeRESTCAD = null;
            PuntoReciclajeCEN     puntoReciclajeCEN     = null;
            PuntoReciclajeEN      puntoReciclajeEN      = null;
            PuntoReciclajeDTOA    returnValue           = null;

            try
            {
                SessionInitializeWithoutTransaction();
                string token = "";
                if (Request.Headers.Authorization != null)
                {
                    token = Request.Headers.Authorization.ToString();
                }
                int id = new UsuarioCEN().CheckToken(token);



                puntoReciclajeRESTCAD = new PuntoReciclajeRESTCAD(session);
                puntoReciclajeCEN     = new PuntoReciclajeCEN(puntoReciclajeRESTCAD);

                // Data
                puntoReciclajeEN = puntoReciclajeCEN.BuscarPorId(idPuntoReciclaje);

                // Convert return
                if (puntoReciclajeEN != null)
                {
                    returnValue = PuntoReciclajeAssembler.Convert(puntoReciclajeEN, session);
                }
            }

            catch (Exception e)
            {
                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.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));
            }
        }
Example #5
0
        public HttpResponseMessage CrearCP([FromBody] PuntoReciclajeDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            PuntoReciclajeRESTCAD puntoReciclajeRESTCAD = null;
            PuntoReciclajeCEN     puntoReciclajeCEN     = null;
            PuntoReciclajeDTOA    returnValue           = null;
            PuntoReciclajeCP      puntoCP = null;
            int returnOID = -1;

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

            try
            {
                SessionInitializeTransaction();


                puntoReciclajeRESTCAD = new PuntoReciclajeRESTCAD(session);
                puntoReciclajeCEN     = new PuntoReciclajeCEN(puntoReciclajeRESTCAD);
                puntoCP = new PuntoReciclajeCP(session);

                // Create
                returnOID = puntoReciclajeCEN.Crear(dto.Latitud, dto.Longitud, dto.Usuario_oid, dto.Estancia_oid);
                puntoCP.CrearAccionPunto(returnOID);
                SessionCommit();

                // Convert return
                returnValue = PuntoReciclajeAssembler.Convert(puntoReciclajeRESTCAD.ReadOIDDefault(returnOID), session);
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(ReciclaUAGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(ReciclaUAGenNHibernate.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);

            return(response);
        }