public IHttpActionResult PutContinente(int id, Continente continente) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != continente.idContinente) { return(BadRequest()); } db.Entry(continente).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ContinenteExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IActionResult> Edit(int id, [Bind("ContinenteId,NombreContinente")] Continente continente) { if (id != continente.ContinenteId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(continente); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContinenteExists(continente.ContinenteId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(continente)); }
public void ordenarPais() { //Agrega los paises de los continentes a un array nuevo que va a ser ordenado if (continentes.Count != 0) { for (int i = 0; i < continentes.Count; i++) { Continente c = (Continente)continentes[i]; for (int j = 0; j < c.Paises.Count; j++) { Pais p = (Pais)c.Paises[j]; paises.Add(p); } } //Metodo burbuja que ordena los paises en forma ascendente segun saturacion for (int i = 0; i <= paises.Count - 1; i++) { for (int j = 0; j < paises.Count - i - 1; j++) { if (((Pais)paises[j]).Satuacion > ((Pais)paises[j + 1]).Satuacion) { object tem = paises[j]; paises[j] = paises[j + 1]; paises[j + 1] = tem; } } } } }
public static void Insert(Continente c) { SQLiteCommand cmd = new SQLiteCommand("INSERT INTO CONTINENTE(nombre) VALUES (@nombre)"); cmd.Parameters.Add(new SQLiteParameter("@nombre", c.Nombre)); cmd.Connection = Conexion.Connection; cmd.ExecuteNonQuery(); }
public async Task <IQueryable <Beer> > Get() { Continente parser = new Continente(); return(await parser.GetBeers()); //return _Db; }
public static void Delete(Continente c) { SQLiteCommand cmd = new SQLiteCommand("DELETE FROM CONTINENTE where id = @id;"); cmd.Parameters.Add(new SQLiteParameter("@id", c.Id)); cmd.Connection = Conexion.Connection; cmd.ExecuteNonQuery(); }
public async Task <IEnumerable <Pais> > GetAllPaisesByContinente(Continente continente) { var query = "SELECT * FROM CAT_Pais WHERE Continente = @Continente"; var list = await SqlMapper.QueryAsync <Pais>(_connectionFactory.GetConnection, query, new { Continente = continente.Id }, commandType : System.Data.CommandType.Text); return(list); }
public static void Update(Continente c) { SQLiteCommand cmd = new SQLiteCommand("UPDATE CONTINENTE SET nombre = @nombre where id = @id;"); cmd.Parameters.Add(new SQLiteParameter("@nombre", c.Nombre)); cmd.Parameters.Add(new SQLiteParameter("@id", c.Id)); cmd.Connection = Conexion.Connection; cmd.ExecuteNonQuery(); }
public bool verificar(string token) { if (punctuator.Contains(token)) { return(false); } token = token.ToLower(); if (token.Equals("nombre")) { if (is_graph) { is_graph_name = true; return(true); } if (is_continente) { is_continente_name = true; return(true); } if (is_pais) { is_pais_name = true; return(true); } } if (token.Equals("continente")) { continente_actual = new Modal.Continente(); is_continente = true; return(true); } else if (token.Equals("pais")) { pais_actual = new Modal.Pais(); is_pais = true; return(true); } else if (token.Equals("poblacion")) { is_poblacion = true; return(true); } else if (token.Equals("saturacion")) { is_saturacion = true; return(true); } else if (token.Equals("bandera")) { is_bandera = true; return(true); } return(false); }
public IHttpActionResult GetContinente(int id) { Continente continente = db.Continente.Find(id); if (continente == null) { return(NotFound()); } return(Ok(continente)); }
public async Task <IActionResult> Create([Bind("ContinenteId,NombreContinente")] Continente continente) { if (ModelState.IsValid) { _context.Add(continente); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(continente)); }
public IHttpActionResult PostContinente(Continente continente) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Continente.Add(continente); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = continente.idContinente }, continente)); }
private Boolean verificarContinente(Continente continente, List <Continente> continentes) { Boolean exists = false; foreach (Continente con in continentes) { if (con == continente) { exists = true; } } return(exists); }
public IHttpActionResult DeleteContinente(int id) { Continente continente = db.Continente.Find(id); if (continente == null) { return(NotFound()); } db.Continente.Remove(continente); db.SaveChanges(); return(Ok(continente)); }
//Arma el texto para graficar public void generarTexto() { ArrayList continentes = ContinenteControlador.Instancia.getArrayListContinentes(); int satContinente = 0; int satPais = 0; string cabeza = ""; string cuerpo = ""; string aux = ""; //Encabezado grafoDot = "digraph G {" + "start[shape = Mdiamond label = \"" + TokenControlador.Instancia.getNombreGrafica() + "\"];"; for (int i = 0; i < continentes.Count; i++) { Continente c = (Continente)continentes[i]; string nContinente = c.Nombre.Replace(" ", ""); cabeza = aux + "start->" + c.Nombre + ";"; for (int j = 0; j < c.Paises.Count; j++) { Pais p = (Pais)c.Paises[j]; string nPais = p.Nombre.Replace(" ", ""); //Suma las saturaciones de los paises satPais = satPais + p.Satuacion; //Arma el cuerpo cuerpo = cuerpo + nContinente + "->" + nPais + ";" + nPais + "[shape = record label = \"{" + p.Nombre + "|" + p.Satuacion + "}\"style = filled fillcolor = " + getColor(p.Satuacion) + "];"; } //Saturacion del continente double auxd = satPais / c.Paises.Count; satContinente = (int)Math.Round(auxd, 0, MidpointRounding.AwayFromZero); aux = cabeza + cuerpo + nContinente + "[shape=record label=\"{" + nContinente + "| " + satContinente + "} \" style=filled fillcolor=" + getColor(satContinente) + "];"; grafoDot = grafoDot + aux; cabeza = ""; cuerpo = ""; aux = ""; satPais = 0; } grafoDot = grafoDot + " } "; ordenarPais(); }
public static Continente GetById(int id) { Continente c = new Continente(); Conexion.OpenConnection(); SQLiteCommand cmd = new SQLiteCommand("SELECT id, nombre FROM CONTINENTE where id = @id;"); cmd.Parameters.Add(new SQLiteParameter("@id", id)); cmd.Connection = Conexion.Connection; SQLiteDataReader obdr = cmd.ExecuteReader(); while (obdr.Read()) { c.Id = obdr.GetInt32(0); c.Nombre = obdr.GetString(1); } return(c); }
public List <Continente> ListarContinentes() { List <Continente> lista = new List <Continente>(); SqlConnection cn = new SqlConnection(cad_cn); cn.Open(); SqlCommand cmd = new SqlCommand("SP_LISTAR_CONTINENTE", cn); cmd.CommandType = CommandType.StoredProcedure; SqlDataReader lector = cmd.ExecuteReader(); while (lector.Read()) { Continente con = new Continente() { ide_con = int.Parse(lector[0].ToString()), nom_con = lector[1].ToString() }; lista.Add(con); } cn.Close(); return(lista); }
public País(string nombre, Continente continente, IEnumerable <Departamento> departamentos) { Nombre = nombre; Continente = continente; Departamentos = departamentos; }
public País(string nombre, Continente continente) { Nombre = nombre; Continente = continente; }
public async Task <IEnumerable <Pais> > GetPaisesByContinente(Continente continente) { return(await _unitOfWork.PaisRepository.GetAllPaisesByContinente(continente)); }
public void agregarContinente(string nombre, ArrayList paises) { Continente continente = new Continente(nombre, paises); arrayListContinentes.Add(continente); }
public Grafico generar(List <Token> salida) { for (int x = 0; x < salida.Count; x++) { if (salida[x].getTipoToken().Equals("PALABRA RESERVADA GRAFICA")) { grafico = new Grafico(); grafico.Nombre = salida[x + 6].Valor; continentes = new List <Continente>(); grafico.Continentes = continentes; } else if (salida[x].getTipoToken().Equals("PALABRA RESERVADA CONTINENTE")) { continente = new Continente(); continente.IdContinente = continentes.Count + 1; continente.Nombre = salida[x + 6].Valor; paises = new List <Pais>(); continente.Paises = paises; continentes.Add(continente); } else if (salida[x].getTipoToken().Equals("PALABRA RESERVADA PAIS")) { pais = new Pais(); pais.IdPais = paises.Count + 1; pais.Continente = continente; int y = x; while (!(salida[y + 1].getTipoToken().Equals("PALABRA RESERVADA PAIS")) && !(salida[y + 1].getTipoToken().Equals("PALABRA RESERVADA CONTINENTE"))) { if (salida[y].getTipoToken().Equals("PALABRA RESERVADA NOMBRE")) { pais.Nombre = salida[y + 3].Valor; } else if (salida[y].getTipoToken().Equals("PALABRA RESERVADA POBLACION")) { pais.Poblacion = salida[y + 2].Valor; } else if (salida[y].getTipoToken().Equals("PALABRA RESERVADA SATURACION")) { pais.Saturacion = Convert.ToInt32(salida[y + 2].Valor); if (0 < pais.Saturacion && pais.Saturacion <= 15) { pais.Color = "white"; } else if (16 <= pais.Saturacion && pais.Saturacion <= 30) { pais.Color = "blue"; } else if (31 <= pais.Saturacion && pais.Saturacion <= 45) { pais.Color = "green"; } else if (46 <= pais.Saturacion && pais.Saturacion <= 60) { pais.Color = "yellow"; } else if (61 <= pais.Saturacion && pais.Saturacion <= 75) { pais.Color = "orange"; } else if (76 <= pais.Saturacion && pais.Saturacion <= 100) { pais.Color = "red"; } } else if (salida[y].getTipoToken().Equals("PALABRA RESERVADA BANDERA")) { pais.UrlBandera = salida[y + 3].Valor; } if (y + 2 == salida.Count) { break; } else { y++; } } paises.Add(pais); } } return(calcularSaturacionContinente(grafico)); }
public Pais getPaisMejorOpcion() { this.arayAuxiliar.Clear(); //////////////////////////////////////////////////////// /// parte que verifica si la saturacion más pequeña viene mas de una vez /// if (this.paises.Count != 0) { int saturacion = ((Pais)paises[0]).Satuacion; int contador = 0; listaPaises.Add(((Pais)paises[0]).Nombre); for (int i = 1; i < paises.Count; i++) { Pais p = (Pais)paises[i]; //verifica si la saturacion mas pequeña se repite if (saturacion == p.Satuacion) { //Agrega el nombre del pais que se repitió listaPaises.Add(p.Nombre); contador++; } } if (contador >= 1) { for (int i = 0; i < continentes.Count; i++) { Continente c = (Continente)continentes[i]; for (int j = 0; j < c.Paises.Count; j++) { Pais p = (Pais)c.Paises[j]; for (int k = 0; k < listaPaises.Count; k++) { if (listaPaises[k].ToString() != "") { if (listaPaises[k].ToString().Equals(p.Nombre)) { int satCont = 0; for (int m = 0; m < c.Paises.Count; m++) { satCont = satCont + ((Pais)c.Paises[m]).Satuacion; } string var = c.Nombre + "," + (satCont / c.Paises.Count); arayAuxiliar.Add(var); } } } } } //METODO BURBUJA QUE ORDENA SEGUN CONTINENTE for (int i = 0; i <= arayAuxiliar.Count - 1; i++) { for (int j = 0; j < arayAuxiliar.Count - i - 1; j++) { string[] a = ((String)arayAuxiliar[j]).Split(','); string[] b = ((String)arayAuxiliar[j + 1]).Split(','); int a1 = int.Parse(a[1]); int b1 = int.Parse(b[1]); if (a1 > b1) { object tem = arayAuxiliar[j]; arayAuxiliar[j] = arayAuxiliar[j + 1]; arayAuxiliar[j + 1] = tem; } } } for (int i = 0; i < continentes.Count; i++) { Continente c = (Continente)continentes[i]; String[] detCont = ((String)arayAuxiliar[0]).Split(','); String var = detCont[0]; if (c.Nombre.Equals(var)) { for (int j = 0; j < c.Paises.Count; j++) { int sat = ((Pais)c.Paises[j]).Satuacion; if (sat == saturacion) { return((Pais)c.Paises[j]); } } break; } } Console.WriteLine("la saturacion es " + saturacion + " y se repite " + contador + " veces"); } else { return((Pais)paises[0]); Console.WriteLine("la saturacion es " + saturacion + " y se repite " + contador + " veces"); } } return(null); }