/// <summary> /// Obtiene un Telefono de la base de datos /// </summary> /// <param name="id"></param> /// <returns></returns> public static Telefono Get(int id) { Telefono res = new Telefono(); SqlCommand cmd = null; SqlDataReader dr = null; string query = @"SELECT * FROM Telefono WHERE IdTelefono=@id"; try { cmd = Methods.CreateBasicCommand(query); cmd.Parameters.AddWithValue("@id", id); dr = Methods.ExecuteDataReaderCommand(cmd); while (dr.Read()) { res = new Telefono() { IdTelefono = dr.GetInt32(0), Numero = dr.GetString(1), Tipo = TipoDal.Get(dr.GetInt32(2)), }; } } catch (Exception ex) { Methods.GenerateLogsRelease("TelefonoDal", "Obtenet(Get)", string.Format("{0} {1} Error: {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), ex.Message)); throw ex; } finally { cmd.Connection.Close(); } return(res); }
/// <summary> /// Obtiene un Direccion de la base de datos /// </summary> /// <param name="id"></param> /// <returns></returns> public static Direccion Get(int id) { Direccion res = new Direccion(); SqlCommand cmd = null; SqlDataReader dr = null; string query = "Select * From Direccion where IdDireccion = @id"; try { cmd = Methods.CreateBasicCommand(query); cmd.Parameters.AddWithValue("@id", id); dr = Methods.ExecuteDataReaderCommand(cmd); while (dr.Read()) { res = new Direccion() { IdDireccion = dr.GetInt32(0), Descripcion = dr.GetString(1), Tipo = TipoDal.Get(dr.GetInt32(2)), Latitud = dr.GetSqlDecimal(3).ToDouble(), Longitud = dr.GetSqlDecimal(4).ToDouble(), }; } } catch (Exception ex) { Methods.GenerateLogsRelease("DireccionDal", "Obtener", string.Format("{0} {1} Error: {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), ex.Message)); throw ex; } finally { cmd.Connection.Close(); } return(res); }
/// <summary> /// Obtiene una lista de direcciones por id de Persona /// </summary> /// <param name="id"></param> /// <returns></returns> public static List <Direccion> GetList(int id) { List <Direccion> res = new List <Direccion>(); SqlCommand cmd = null; SqlDataReader dr = null; string query = @"SELECT * FROM Direccion WHERE IdPersona=@idPersona"; try { cmd = Methods.CreateBasicCommand(query); cmd.Parameters.AddWithValue("@idPersona", id); dr = Methods.ExecuteDataReaderCommand(cmd); while (dr.Read()) { res.Add(new Direccion() { IdDireccion = dr.GetInt32(0), Descripcion = dr.GetString(1), Tipo = TipoDal.Get(dr.GetInt32(2)), Latitud = dr.GetSqlDecimal(3).ToDouble(), Longitud = dr.GetSqlDecimal(4).ToDouble() }); } } catch (SqlException ex) { Methods.GenerateLogsRelease("DireccionDal", "ObtenerLista", ex.Message + " " + ex.StackTrace); throw ex; } catch (Exception ex) { Methods.GenerateLogsRelease("DireccionDal", "ObtenerLista", ex.Message + " " + ex.StackTrace); throw ex; } finally { cmd.Connection.Close(); } return(res); }
/// <summary> /// Obtiene una lista de Telefonos por id de Persona /// </summary> /// <param name="id"></param> /// <returns></returns> public static List <Telefono> GetList(int id) { List <Telefono> res = new List <Telefono>(); SqlCommand cmd = null; SqlDataReader dr = null; string query = @"SELECT * FROM Telefono WHERE IdPersona=@idPersona"; try { cmd = Methods.CreateBasicCommand(query); cmd.Parameters.AddWithValue("@idPersona", id); dr = Methods.ExecuteDataReaderCommand(cmd); while (dr.Read()) { res.Add(new Telefono() { IdTelefono = dr.GetInt32(0), Numero = dr.GetString(1), Tipo = TipoDal.Get(dr.GetInt32(2)) }); } } catch (SqlException ex) { Methods.GenerateLogsRelease("TelefonoDal", "ObtenerLista", ex.Message + " " + ex.StackTrace); throw ex; } catch (Exception ex) { Methods.GenerateLogsRelease("TelefonoDal", "ObtenerLista", ex.Message + " " + ex.StackTrace); throw ex; } finally { cmd.Connection.Close(); } return(res); }