public void InserirTeste() { //Instaciando uma classe var destino = new Destino(); //Criando Objeto destino.Cidade = "São Pailo"; destino.Nome = "Conheça São Paulo"; destino.NomeImagem = "Paulista.png"; destino.Pais = "Brasil"; //Este é o Insert do Entity _db.Destinos.Add(destino); //Este é o comando que execulta a tarefa no banco _db.SaveChanges(); }
public ActionResult DestinoSalvar(Destino destino) { try { if (!ModelState.IsValid) { throw new ValidationException("Favor preencher todos os campos obrigatórios"); } if (string.IsNullOrEmpty(destino.Foto) && (Request.Files.Count == 0 || Request.Files[0].ContentLength == 0)) { throw new ArgumentException("É Necessário enviar uma foto"); } using (var db = ObterDbContext()) { if (destino.DestinoId > 0) { var destinoOriginal = db.Destinos.Find(destino.DestinoId); destinoOriginal.Nome = destino.Nome; destinoOriginal.Pais = destino.Pais; destinoOriginal.Cidade = destino.Cidade; if (Request.Files.Count != 0 && Request.Files[0].ContentLength != 0) { destinoOriginal.Foto = GravarFoto(Request); } } else { destino.Foto = GravarFoto(Request); db.Destinos.Add(destino); } db.SaveChanges(); return(RedirectToAction(ActionDestinoListagem)); } } catch (Exception ex) { ModelState.AddModelError("", ex.Message); return(View("DestinoFormulario", destino)); } }
public List <Destino> VerificarEndereco(Destino pdvDestinoMelhor, List <PdvFuncionario> listaPdvFuncionario, Funcionario funcionario, DateTime data) { foreach (var t in listaPdvFuncionario) { Destino d = new Destino(); d.PdvFuncionario = t; d.Tempo = Distance(DePara(pdvDestinoMelhor.PdvFuncionario.IdEndereco), DePara(t.IdEndereco)); d.Data = data; var pdvPossivel = VerificarHorarioAtendimentoPdv(t, funcionario); if (pdvPossivel != null) { destinos.Add(d); destinoRepositorio.Save(d); } } return(destinos); }
public void ActualizarEstadiasActivas(Destino destinoViejo, Destino destinoNuevo) { Estadia nueva = new Estadia(); List <Estadia> activas = db.Estadias.Where(m => m.Activo == true && m.Destino == destinoViejo).ToList(); List <Estadia> nuevas = new List <Estadia>(); foreach (Estadia e in activas) { nueva.Dias = e.Dias; nueva.Activo = true; nueva.Destino = destinoNuevo; e.Activo = false; db.Estadias.Add(nueva); db.SaveChanges(); db.Entry(e).State = EntityState.Modified; db.SaveChanges(); } }
public Destino buscarPorId(int id) { Destino retorno = null; var query = new StringBuilder(); query.AppendLine("SELECT DestinoId, Nome, Dia"); query.AppendLine("FROM Destino"); query.AppendLine("WHERE DestinoId = @id"); DataTable dt = this.executeDataTable(query.ToString(), new SqlParameter("id", id)); if (dt.Rows.Count > 0) { retorno = this.preencherDestino(dt.Rows[0]); } return(retorno); }
public bool EliminarDestino(string nombre, string ciudad, string pais, string id) { bool retorno = false; //Verifico si existe el destino a eliminar Destino unD = instancia.RepoDestinos.FindById(id); if (unD != null) { //verifico que el destino no este en uso if (RepoExcurciones.FindDestinoById(id) == null) { retorno = RepoDestinos.Delete(unD); FachadaAgencia.Instancia.SerializarTodo(); FachadaAgencia.Instancia.GuardarParametros(":"); } } return(retorno); }
public void PopularDestino(List <PdvFuncionario> pdvFuncionarios, Funcionario funcionario) { List <Rota> rotas = new List <Rota>(); if (funcionario != null) { var idfuncionario = funcionario.IDEndereco; foreach (var t in pdvFuncionarios) { Destino d = new Destino(); d.PdvFuncionario = t; d.Tempo = Distance(DePara(idfuncionario), DePara(t.IdEndereco)); d.Data = data; var jornada = ExisteTempoJornadaFuncionario(d.Tempo + TempoVisita(DePara(t.IdEndereco))); if (jornada) { var pdvPossivel = VerificarHorarioAtendimentoPdv(t, funcionario); if (pdvPossivel != null) { destinos.Add(d); destinoRepositorio.Save(d); } } } } var lista = OrdenaRemoveLista(pdvFuncionarios, funcionario); if (lista == null || lista.Count <= 0) { return; } else { while (lista.FirstOrDefault() != null) { VerificarEndereco(mUltimoEndereco, pdvFuncionarios, funcionario, data); lista = OrdenaRemoveLista(lista, funcionario); } data = data.AddDays(1); PopularDestino(pdvFuncionarios, funcionario); } }
private void CargarGameObjects() { //Se carga los objetos a cada posición. gameObject[0, 0] = new Vacio(); gameObject[0, 1] = new Vacio(); gameObject[0, 2] = new Pared(); gameObject[0, 3] = new Pared(); gameObject[0, 4] = new Pared(); gameObject[0, 5] = new Vacio(); gameObject[0, 6] = new Vacio(); gameObject[0, 7] = new Vacio(); gameObject[1, 0] = new Vacio(); gameObject[1, 1] = new Vacio(); gameObject[1, 2] = new Pared(); gameObject[1, 3] = new Destino(); gameObject[1, 4] = new Pared(); gameObject[1, 5] = new Vacio(); gameObject[1, 6] = new Vacio(); gameObject[1, 7] = new Vacio(); gameObject[2, 0] = new Vacio(); gameObject[2, 1] = new Vacio(); gameObject[2, 2] = new Pared(); gameObject[2, 3] = new Piso(); gameObject[2, 4] = new Pared(); gameObject[2, 5] = new Pared(); gameObject[2, 6] = new Pared(); gameObject[2, 7] = new Pared(); gameObject[3, 0] = new Pared(); gameObject[3, 1] = new Pared(); gameObject[3, 2] = new Pared(); gameObject[3, 3] = new Caja(); gameObject[3, 4] = new Piso(); gameObject[3, 5] = new Caja(); gameObject[3, 6] = new Destino(); gameObject[3, 7] = new Pared(); gameObject[4, 0] = new Pared(); gameObject[4, 1] = new Destino(); gameObject[4, 2] = new Piso(); gameObject[4, 3] = new Caja(); gameObject[4, 4] = new Jugador(); gameObject[4, 5] = new Piso(); gameObject[4, 6] = new Pared(); gameObject[4, 7] = new Pared(); gameObject[5, 0] = new Pared(); gameObject[5, 1] = new Pared(); gameObject[5, 2] = new Pared(); gameObject[5, 3] = new Pared(); gameObject[5, 4] = new Pared(); gameObject[5, 5] = new Caja(); gameObject[5, 6] = new Pared(); gameObject[5, 7] = new Vacio(); gameObject[6, 0] = new Vacio(); gameObject[6, 1] = new Vacio(); gameObject[6, 2] = new Vacio(); gameObject[6, 3] = new Vacio(); gameObject[6, 4] = new Pared(); gameObject[6, 5] = new Destino(); gameObject[6, 6] = new Pared(); gameObject[6, 7] = new Vacio(); gameObject[7, 0] = new Vacio(); gameObject[7, 1] = new Vacio(); gameObject[7, 2] = new Vacio(); gameObject[7, 3] = new Vacio(); gameObject[7, 4] = new Pared(); gameObject[7, 5] = new Pared(); gameObject[7, 6] = new Pared(); gameObject[7, 7] = new Vacio(); }
public ActionResult Put(int id, [FromBody] Destino destino) { try { if (destino.Id == id) { context.Entry(destino).State = EntityState.Modified; context.SaveChanges(); return(Ok()); } else { return(BadRequest()); } } catch (Exception e) { return(BadRequest(e.Message)); } }
public Destino buscarPorId(int id) { Destino destino = new Destino(); ConectarSql(); string query = "SELECT * FROM Destino WHERE DestinoId = @id"; SqlCommand cmd = new SqlCommand(query, conn); cmd.Parameters.Add("@id", SqlDbType.Int).Value = id; try { SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows == false) { throw new Exception("Destino não encontrado"); } reader.Read(); destino.Nome = Convert.ToString(reader["Nome"]); destino.Dia = Convert.ToDateTime(reader["Dia"]); return(destino); } catch (Exception ex) { throw ex; } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } if (conn != null) { conn.Dispose(); } } }
public async Task <ActionResult <Destino> > PostDestino(Destino destino) { _context.Destino.Add(destino); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (DestinoExists(destino.CdDestino)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetDestino", new { id = destino.CdDestino }, destino)); }
public IHttpActionResult Post(Destino oDestino) { try { var destino = db.Destino.Where(d => d.Id == oDestino.Id).Count(); if (destino == 0) { db.Destino.Add(oDestino); db.SaveChanges(); return(Ok(oDestino)); } else { return(BadRequest("El destino ya existe")); } } catch (Exception ex) { throw new Exception("Ocurrió un error inesperado. Código de error: " + ex.Message); } }
public bool Read(int id) { try { var p = new OracleDynamicParameters(); p.Add("Id", id); p.Add("c1", dbType: OracleDbType.RefCursor, direction: ParameterDirection.Output); var result = Db.QuerySingle <dynamic>(Procs.Destino_Asociado_Por_Id, param: p, commandType: CommandType.StoredProcedure); Contrato_Api contrato = new Contrato_Api(); contrato.Read((int)result.CONTRATOID); Destino_Api destino = new Destino_Api(); destino.Read((int)result.DESTINOID); Id = (int)result.ID; Contrato = new Contrato() { Id = contrato.Id, Curso = contrato.Curso, Nombre = contrato.Nombre, Descripcion = contrato.Descripcion, Fecha_Viaje = contrato.Fecha_Viaje, Valor = contrato.Valor }; Destino = new Destino() { Id = destino.Id, Nombre = destino.Nombre, Valor = destino.Valor }; return(true); } catch (Exception ex) { logger.Error(ex.Message); return(false); } }
public bool Delete(Destino Destino) { string comandoSql = "DELETE FROM [Cartas$] WHERE [COD] = @COD "; OleDbCommand comando = new OleDbCommand(comandoSql, conexao); //comando.Parameters.Add("@COD", OleDbType.Integer).Value = //Convert.ToInt16(Destino.cod); //try //{ // conexao.Open(); // comando.ExecuteNonQuery(); //} //catch //{ //} //finally //{ // conexao.Close(); //} return(true); }
internal Destino BuscarDestinoTodos(string pCod) { SqlConnection _Conexion = new SqlConnection(Conexion.MiConexion); SqlCommand _Comando = new SqlCommand("BuscarDestinoTodos", _Conexion); _Comando.CommandType = CommandType.StoredProcedure; _Comando.Parameters.AddWithValue("@codigo", pCod); SqlDataReader lector; Destino unDestino = null; List <Facilidades> lasFacilidades = new List <Facilidades>(); try { _Conexion.Open(); lector = _Comando.ExecuteReader(); if (lector.HasRows) { lector.Read(); string codigo = (string)lector["codigo"]; string cidudad = (string)lector["ciudad"]; string pais = (string)lector["pais"]; unDestino = new Destino(codigo, cidudad, pais, lasFacilidades); lector.Close(); if (unDestino != null) { PersistenciaFacilidades.GetInstancia().FacilidadesDeUnDestino(unDestino); } } } catch (Exception ex) { throw ex; } finally { _Conexion.Close(); } return(unDestino); }
private static void IngresaDestino() { string ciudad, pais; decimal costo; decimal cantidadDias; ciudad = PedirTexto("Ingrese la ciudad"); pais = PedirTexto("Ingrese el pais"); costo = PedirNumero("Ingrese el costo"); cantidadDias = PedirNumero("Ingrese los días"); if (unaAgencia.AgregarDestinos(ciudad, pais, costo, cantidadDias)) { if (Destino.ValidarString2(ciudad) && Destino.ValidarString2(pais) && Destino.ValidarEnteros(costo) && Destino.ValidarEnteros(cantidadDias)) { Console.WriteLine("Alta destino OK"); } else { Console.WriteLine("- Ciudad y país deben tener al menos 3 caracteres" + "\n" + "- Valores númericos no pueden ser negativos"); } } }
public static List <Destino> executeObtenerDestinos() { DataTable dt = fillDTStoreProcedure("spObtenerDestinos", null); List <Destino> destinosDisponibles = new List <Destino>(); foreach (DataRow row in dt.Rows) { Destino destino = new Destino { Idn = row["Idn"].ToString(), Nombre = row["Nombre"].ToString(), Descripcion = row["Descripcion"].ToString(), ImgURL = row["ImgURL"].ToString(), Precio = Convert.ToDouble(row["Precio"]) }; destinosDisponibles.Add(destino); } return(destinosDisponibles); }
public string DestinoAñadir(Destino Destino) { try { DataTable DestinosTabla = ConexionDestinos.BuscarDestinos(); List <SqlParameter> Parametros = new List <SqlParameter>(); Parametros.Add(Paramiters.CrearParametro("@destino", Destino.LugarDestino)); Parametros.Add(Paramiters.CrearParametro("@ubicacion", Destino.DestinoMaps)); if (ConexionDestinos.AñadirDestino(Parametros)) { return("Destino Creado Exitosamente"); } return("Ocurrio un error en la base de datos"); } catch (Exception) { return("Ocurrio un error, intentelo mas tarde"); } }
public Destino buscarPorId(int id) { SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Server=den1.mssql6.gear.host;Database=testecore;User Id=testecore;Password=Dz2iI~!U1Edq"; conn.Open(); string sql = string.Format("select * from Destino where DestinoId={0}", id); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); Destino resultado = new Destino(); if (reader.Read()) { resultado.DestinoId = (int)reader["DestinoId"]; resultado.Nome = reader["Nome"].ToString(); if (reader["Dia"] != null) { resultado.Dia = Convert.ToDateTime(reader["Dia"]); } } return(resultado); }
public bool ExisteDestino(Destino ADestino) { string pSentencia = "SELECT CLAVE FROM DRASDEST WHERE UPPER(TRIM(DESTINO)) = @DESTINO"; FbConnection con = _Conexion.ObtenerConexion(); FbCommand com = new FbCommand(pSentencia, con); com.Parameters.Add("@DESTINO", FbDbType.VarChar).Value = ADestino._Destino.ToUpper().Trim(); try { con.Open(); FbDataReader reader = com.ExecuteReader(); if (reader.Read()) { int clave = (int)reader["CLAVE"]; if (clave == ADestino.Clave) { return(false); } else { return(true); } } } finally { if (con.State == System.Data.ConnectionState.Open) { con.Close(); } } return(false); }
internal void FacilidadesDeUnDestino(Destino unDestino) { SqlConnection _cnn = new SqlConnection(Conexion.MiConexion); SqlCommand _comando = new SqlCommand("FacilidadesDeUnDestino", _cnn); _comando.CommandType = CommandType.StoredProcedure; _comando.Parameters.AddWithValue("@Cod", unDestino.Cod); try { //me conecto _cnn.Open(); //ejecuto consulta SqlDataReader _lector = _comando.ExecuteReader(); //verifico si hay facilidades if (_lector.HasRows) { while (_lector.Read()) { Facilidades f = new Facilidades((string)_lector["facilidad"]); unDestino.AgregarFacilidad(f); } } _lector.Close(); } catch (Exception ex) { throw ex; } finally { _cnn.Close(); } }
private void btnGuardar_Click(object sender, EventArgs e) { if (txtDescripcion.Text == string.Empty) { MessageBox.Show("Ingrese la descripción del destino a agregar.", "Datos Incompletos", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { DialogResult respuesta; respuesta = MessageBox.Show("¿Desea guardas los datos?", "Alta de Destino", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (respuesta == DialogResult.Yes) { Destino oDestino = new Destino(); oDestino.DES_Descripcion = txtDescripcion.Text; TrabajarDestinos.agregarDestino(oDestino); dgvDestino.DataSource = TrabajarDestinos.traerDestino(); MessageBox.Show("Se ha registrado correctamente.", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information); TrabajarDestinos.traerDestino();//para actualizar el dgvDestino con el registro agregado } } ClaseUtil.limpiarFormulario(gbDestino); }
public int Grabar(TipoGrabacion myTipo, Destino myDestino) { int registrosAfectados = 0; var myDao = DAODestino.CrearDao(); if (myTipo.Equals(TipoGrabacion.Agregar)) { registrosAfectados = myDao.Agregar(myDestino); } if (myTipo.Equals(TipoGrabacion.Editar)) { registrosAfectados = myDao.Editar(myDestino); } if (myTipo.Equals(TipoGrabacion.Inhabilitar)) { registrosAfectados = myDao.Inhabilitar(myDestino); } if (myTipo.Equals(TipoGrabacion.Habilitar)) { registrosAfectados = myDao.Habilitar(myDestino); } return(registrosAfectados); }
private void GuardarEjercicioBtn_Click(object sender, RoutedEventArgs e) { Ejercicio.Nombre = NombreEjercicioTextBox.Text; Ejercicio.Descripcion = DescripcionEjercicioTextBox.Text; Ejercicio.Dificultad = DificultadRatingBar.Value; if (ValidarEjercicio()) { var selectedValue = DestinoComboBox.SelectedValue.ToString(); if (selectedValue == Destino.FirstOrDefault()) { var result = ServerHelper.EnviarEjercicio(Ejercicio, null); if (result == ServerHelper.SERVER_OK) { CerrarBtn_Click(sender, e); } else { EstadoSnackBar("No hay conexión para guardar el ejercicio. Intente nuevamente en unos minutos."); } } else { var PacienteSeleccionado = Pacientes.Pacientes.FirstOrDefault( x => x.Nombre == selectedValue); var result = ServerHelper.EnviarEjercicio(Ejercicio, PacienteSeleccionado.PacienteId + ""); if (result == ServerHelper.SERVER_OK) { CerrarBtn_Click(sender, e); } else { EstadoSnackBar("No hay conexión para guardar el ejercicio. Intente nuevamente en unos minutos."); } } } }
public List <Boleto> GetAll() { List <Boleto> boletos = new List <Boleto>(); try { this.OpenConnection(); SqlCommand cmdBoleto = new SqlCommand("select * from Boletos b inner join Destinos d on b.id_destino=d.id_destino where asientos_disponibles>0", SqlConn); SqlDataReader drBoleto = cmdBoleto.ExecuteReader(); while (drBoleto.Read()) { Boleto b = new Boleto(); b.ID = (int)drBoleto["id_boleto"]; b.FechaSalida = (DateTime)drBoleto["fecha_salida"]; b.FechaRegreso = (DateTime)drBoleto["fecha_regreso"]; b.Precio = (int)drBoleto["precio"]; b.IDColectivo = (int)drBoleto["id_colectivo"]; b.AsientosDisponibles = (int)drBoleto["asientos_disponibles"]; Destino d = new Destino(); d.ID = (int)drBoleto["id_destino"]; d.Descripcion = (string)drBoleto["descripcion"]; b.Destino = d; boletos.Add(b); } drBoleto.Close(); } catch (Exception Ex) { Exception ExcepcionManejada = new Exception("Error al recuperar lista de boletos", Ex); throw ExcepcionManejada; } finally { this.CloseConnection(); } return(boletos); }
// DESTINO: ALTA Y MOSTRAR #region Destino static void AltaDestino() { string msgDestino = "Error: Datos incorrectos"; Console.WriteLine("Ingrese pais"); string pais = Console.ReadLine(); Console.WriteLine("Ingrese ciudad"); string ciudad = Console.ReadLine(); Console.WriteLine("Ingrese cantidad de dias de estadia"); int cantDias; int.TryParse(Console.ReadLine(), out cantDias); Console.WriteLine("Ingrese el costo por dia"); double costoXDia; double.TryParse(Console.ReadLine(), out costoXDia); // primera letra en mayuscula, ya que guardo todos los nombres en minuscula para procesar. string ciudadPais = ciudad.Substring(0, 1).ToUpper() + ciudad.Substring(1).ToLower() + ", " + pais.Substring(0, 1).ToUpper() + pais.Substring(1).ToLower(); if (pais.Length >= 3 && ciudad.Length >= 3 && cantDias > 0 && costoXDia > 0) { Destino nuevoD = agencia.crearDestino(pais, ciudad, cantDias, costoXDia); if (nuevoD != null) { msgDestino = "Destino " + ciudadPais + " fue creado con exito!"; } else { Console.WriteLine(""); msgDestino = "Error: Destino " + ciudadPais + " ya existe"; } } Console.WriteLine(msgDestino); }
public List <Destino> ListarDestinoXFiltro(string p_NomDestino) { conexion = new ConexionDAO(); cnn = conexion.crearConexion(); List <Destino> listaDestino = new List <Destino>(); cnn.Open(); SqlCommand cmd = new SqlCommand("sp_BuscarDestino", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@P_vcCodFiltro", p_NomDestino); SqlDataReader rd = cmd.ExecuteReader(); if (rd.HasRows) { while (rd.Read()) { Destino oDestino = new Destino(); //Se llenan datos de hotel oDestino.IdDepartamaneto = rd.GetInt32(2); oDestino.IdProvincia = rd.GetInt32(1); oDestino.IdDistrito = rd.GetInt32(0); oDestino.NombreDestino = rd.GetString(3); //Se agrega al hotel a la lista que retorna el WS listaDestino.Add(oDestino); } } cnn.Close(); return(listaDestino); }
/// <summary> /// /// </summary> /// <param name="filtro"></param> /// <returns></returns> public List <Destino> ListarDestino() { SqlConnection conn = new SqlConnection(); conn.ConnectionString = "Server=den1.mssql6.gear.host;Database=testecore;User Id=testecore;Password=Dz2iI~!U1Edq"; conn.Open(); string sql = "select * from Destino"; SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader reader = cmd.ExecuteReader(); List <Destino> resultado = new List <Destino>(); while (reader.Read()) { Destino item = new Destino(); item.DestinoId = (int)reader["DestinoId"]; item.Nome = reader["Nome"].ToString(); if (reader["Dia"] != null) { item.Dia = Convert.ToDateTime(reader["Dia"]); } resultado.Add(item); } return(resultado); }
public List <Destino> ListarDestino() { var listaDestinos = new List <Destino>(); ConectarSql(); var query = "SELECT * FROM Destino"; var cmd = new SqlCommand(query, conn); var reader = cmd.ExecuteReader(); while (reader.Read()) { var destino = new Destino() { Nome = Convert.ToString(reader["Nome"]), Dia = Convert.ToDateTime(reader["Dia"]) }; listaDestinos.Add(destino); } return(listaDestinos); }
private static void IngresaDestino() { string ciudad, pais; decimal costo; decimal cantidadDias; bool bandera = false; ciudad = PedirTexto("Ingrese la ciudad"); pais = PedirTexto("Ingrese el pais"); costo = PedirNumero("Ingrese el costo"); cantidadDias = PedirNumero("Ingrese los días"); if (Destino.ValidarString2(ciudad) && Destino.ValidarString2(pais) && Destino.ValidarEnteros(costo) && Destino.ValidarEnteros(cantidadDias)) { bandera = unaAgencia.AgregarDestinos(ciudad, pais, costo, cantidadDias); if (bandera) { Console.WriteLine("Alta destino OK"); } else { Console.WriteLine("Error, algo salió mal. Verifique que lo ingresado este correcto."); } } }