Пример #1
0
        public List <Lugar> LugaresPorTipo(TipoLugar tipo)
        {
            List <Lugar> lista = new List <Lugar>();

            try
            {
                Conexion.Open();

                string Command = "SELECT * FROM lugar WHERE lu_tipo = @tipo";

                NpgsqlCommand Script = new NpgsqlCommand(Command, Conexion);

                switch (tipo)
                {
                case TipoLugar.Direccion:
                    Script.Parameters.AddWithValue("tipo", "Direccion");
                    break;

                case TipoLugar.Estado:
                    Script.Parameters.AddWithValue("tipo", "Estado");
                    break;

                case TipoLugar.Municipio:
                    Script.Parameters.AddWithValue("tipo", "Municipio");
                    break;

                case TipoLugar.Pais:
                    Script.Parameters.AddWithValue("tipo", "Pais");
                    break;

                case TipoLugar.Parroquia:
                    Script.Parameters.AddWithValue("tipo", "Parroquia");
                    break;

                default:
                    Tipo = null;
                    break;
                }

                Reader = Script.ExecuteReader();

                while (Reader.Read())
                {
                    Lugar lugar = new Lugar(ReadInt(0), ReadString(1), ReadString(2), ReadString(3), ReadInt(4));

                    lista.Add(lugar);
                }
            }
            catch (Exception e)
            {
                throw new Exception("Ha ocurrido un error en la base de datos", e);
            }
            finally
            {
                Conexion.Close();
            }

            return(lista);
        }
Пример #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            TipoLugar tipoLugar = _UnityOfWork.TipoLugares.Get(id);

            _UnityOfWork.TipoLugares.Remove(tipoLugar);
            _UnityOfWork.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            TipoLugar tipoLugar = db.TipoLugar.Find(id);

            db.TipoLugar.Remove(tipoLugar);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #4
0
 public ActionResult Edit([Bind(Include = "TipoLugarId,Descripcion,Vigente")] TipoLugar tipoLugar)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tipoLugar).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tipoLugar));
 }
Пример #5
0
 public ActionResult Edit([Bind(Include = "TipoLugarId,NombreTipo,LugarViajeId")] TipoLugar tipoLugar)
 {
     if (ModelState.IsValid)
     {
         _UnityOfWork.StateModified(tipoLugar);
         _UnityOfWork.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.LugarViajeId = new SelectList(_UnityOfWork.LugarViajes.GetEntity(), "LugarViajeId", "NombreLugar", tipoLugar.LugarViajeId);
     return(View(tipoLugar));
 }
Пример #6
0
        public ActionResult Create([Bind(Include = "TipoLugarId,Descripcion,Vigente")] TipoLugar tipoLugar)
        {
            if (ModelState.IsValid)
            {
                db.TipoLugar.Add(tipoLugar);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tipoLugar));
        }
Пример #7
0
        // GET: TipoLugares/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TipoLugar tipoLugar = _UnityOfWork.TipoLugares.Get(id);

            if (tipoLugar == null)
            {
                return(HttpNotFound());
            }
            return(View(tipoLugar));
        }
Пример #8
0
        // GET: Cnp/TipoLugars/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TipoLugar tipoLugar = db.TipoLugar.Find(id);

            if (tipoLugar == null)
            {
                return(HttpNotFound());
            }
            return(View(tipoLugar));
        }
Пример #9
0
        // GET: TipoLugares/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TipoLugar tipoLugar = _UnityOfWork.TipoLugares.Get(id);

            if (tipoLugar == null)
            {
                return(HttpNotFound());
            }
            ViewBag.LugarViajeId = new SelectList(_UnityOfWork.LugarViajes.GetEntity(), "LugarViajeId", "NombreLugar", tipoLugar.LugarViajeId);
            return(View(tipoLugar));
        }
Пример #10
0
        public Lugar(string nombre, TipoLugar tipo, string descripcion, Lugar ubicacion = null)
        {
            Nombre = nombre;
            switch (tipo)
            {
            case TipoLugar.Direccion:
                Tipo = "Direccion";
                break;

            case TipoLugar.Estado:
                Tipo = "Estado";
                break;

            case TipoLugar.Municipio:
                Tipo = "Municipio";
                break;

            case TipoLugar.Pais:
                Tipo = "Pais";
                break;

            case TipoLugar.Parroquia:
                Tipo = "Parroquia";
                break;

            default:
                Tipo = null;
                break;
            }
            Descripcion = descripcion;
            if (ubicacion == null)
            {
                CodigoUbicacion = 0;
            }
            else
            {
                CodigoUbicacion = ubicacion.Codigo;
            }
        }
Пример #11
0
        public async Task <ActionResult> SincronizaTipoLugar()
        {
            string username = "******";
            string password = "******";
            var    client   = new HttpClient();

            client.BaseAddress = new Uri("https://catalogoservicioweb.policia.gov.co");
            var url   = "/sw/api/ListaValor/ConsultaTipoLugar";
            var token = GeneradorToken.TokenPonal(username, password);

            client.DefaultRequestHeaders.Add("Authorization", token);
            var response = await client.GetAsync(url);

            if (!response.IsSuccessStatusCode)
            {
                return(null);
            }

            var result = await response.Content.ReadAsStringAsync();

            var tipoLugar = JsonConvert.DeserializeObject <List <DominioPonal> >(result);

            foreach (var item in tipoLugar)
            {
                bool existe = db.TipoLugar.Any(x => x.CodigoPonal == item.ID_DOMINIO);
                if (!existe)
                {
                    TipoLugar tipo = new TipoLugar();
                    tipo.CodigoPonal = Convert.ToInt32(item.ID_DOMINIO);
                    tipo.Descripcion = item.DESCRIPCION;
                    tipo.Vigente     = true;
                    db.TipoLugar.Add(tipo);
                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }