public void CrearAccionPunto(int p_oid)
        {
            /*PROTECTED REGION ID(ReciclaUAGenNHibernate.CP.ReciclaUA_PuntoReciclaje_crearAccionPunto) ENABLED START*/

            IPuntoReciclajeCAD puntoReciclajeCAD = null;
            PuntoReciclajeCEN  puntoReciclajeCEN = null;
            AccionWebCEN       accionWebCEN      = null;
            ITipoAccionCAD     tipoAccionCAD     = null;
            TipoAccionCEN      tipoAccionCEN     = null;
            TipoAccionEN       tipoAccion        = null;
            IUsuarioWebCAD     usuarioWebCAD     = null;
            UsuarioWebCEN      usuarioWebCEN     = null;
            PuntoReciclajeEN   punto             = null;


            try
            {
                SessionInitializeTransaction();
                puntoReciclajeCAD = new PuntoReciclajeCAD(session);
                puntoReciclajeCEN = new PuntoReciclajeCEN(puntoReciclajeCAD);
                tipoAccionCAD     = new TipoAccionCAD(session);
                tipoAccionCEN     = new TipoAccionCEN(tipoAccionCAD);
                usuarioWebCAD     = new UsuarioWebCAD(session);
                usuarioWebCEN     = new UsuarioWebCEN(usuarioWebCAD);
                accionWebCEN      = new AccionWebCEN();

                punto = puntoReciclajeCEN.BuscarPorId(p_oid);

                if (punto.Usuario != null && usuarioWebCEN.BuscarPorId(punto.Usuario.Id) != null)
                {
                    tipoAccion = tipoAccionCEN.BuscarTodos(0, -1).Where(t => t.Nombre.Equals("Punto")).FirstOrDefault();

                    if (tipoAccion == null)
                    {
                        var id = tipoAccionCEN.Crear(30, "Punto");
                        tipoAccion = tipoAccionCEN.BuscarPorId(id);
                    }
                    accionWebCEN.Crear(punto.Usuario.Id, tipoAccion.Id);
                }

                SessionCommit();
            }
            catch (Exception ex)
            {
                SessionRollBack();
                throw ex;
            }
            finally
            {
                SessionClose();
            }


            /*PROTECTED REGION END*/
        }
 public static void InitializeData()
 {
     // Console.WriteLine("Init");
     foreach (PuntoReciclajeEN p in puntoCEN.BuscarTodos(0, -1))
     {
         if (p.EsValido == EstadoEnum.enProceso)
         {
             changed_ids.Add(p.Id);
             puntoCEN.Modificar(p.Id, p.Latitud, p.Longitud, EstadoEnum.descartado);
             // Console.WriteLine("Mod " +  m.Id);
         }
     }
     for (int i = 0; i < new_elements; i++)
     {
         int id = puntoCEN.Crear(0.0d, 0.0d, -1, null);
         punto = puntoCEN.BuscarPorId(id);
         puntoCEN.Modificar(id, punto.Latitud, punto.Longitud, EstadoEnum.enProceso);
         ids.Add(id);
         // Console.WriteLine("Added " + id);
     }
 }
 public static void InitializeData()
 {
     id    = puntoCEN.Crear(0.0d, 0.0d, -1, null);
     punto = puntoCEN.BuscarPorId(id);
 }
Exemple #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));
            }
        }
 public void ThenSeBorraElPunto()
 {
     Assert.IsNull(puntoReciclajeCEN.BuscarPorId(punto_id));
 }