Exemplo n.º 1
0
        public IList <Propietario> ObtenerTodos()
        {
            IList <Propietario> res = new List <Propietario>();

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT IdPropietario, Nombre, Apellido, Dni, Telefono, Email, Clave" +
                             $" FROM Propietarios";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        Propietario p = new Propietario
                        {
                            IdPropietario = reader.GetInt32(0),
                            Nombre        = reader.GetString(1),
                            Apellido      = reader.GetString(2),
                            Dni           = reader.GetString(3),
                            Telefono      = reader.GetString(4),
                            Email         = reader.GetString(5),
                            Clave         = reader.GetString(6),
                        };
                        res.Add(p);
                    }
                    connection.Close();
                }
            }
            return(res);
        }
Exemplo n.º 2
0
        public IList <Propietario> BuscarPorNombre(string nombre)
        {
            List <Propietario> res = new List <Propietario>();
            Propietario        p   = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT IdPropietario, Nombre, Apellido, Dni, Telefono, Email, Clave FROM Propietarios" +
                             $" WHERE Nombre LIKE %@nombre% OR Apellido LIKE %@nombre";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Parameters.Add("@nombre", SqlDbType.VarChar).Value = nombre;
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        p = new Propietario
                        {
                            IdPropietario = reader.GetInt32(0),
                            Nombre        = reader.GetString(1),
                            Apellido      = reader.GetString(2),
                            Dni           = reader.GetString(3),
                            Telefono      = reader.GetString(4),
                            Email         = reader.GetString(5),
                            Clave         = reader.GetString(6),
                        };
                        res.Add(p);
                    }
                    connection.Close();
                }
            }
            return(res);
        }
Exemplo n.º 3
0
        public Propietario ObtenerPorEmail(string email)
        {
            Propietario p = null;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"SELECT IdPropietario, Nombre, Apellido, Dni, Telefono, Email, Clave FROM Propietarios" +
                             $" WHERE Email=@email";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.Parameters.Add("@email", SqlDbType.VarChar).Value = email;
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    var reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        p = new Propietario
                        {
                            IdPropietario = reader.GetInt32(0),
                            Nombre        = reader.GetString(1),
                            Apellido      = reader.GetString(2),
                            Dni           = reader.GetString(3),
                            Telefono      = reader.GetString(4),
                            Email         = reader.GetString(5),
                            Clave         = reader.GetString(6),
                        };
                    }
                    connection.Close();
                }
            }
            return(p);
        }
Exemplo n.º 4
0
        public int Modificacion(Propietario p)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                string sql = $"UPDATE Propietarios SET Nombre='{p.Nombre}', Apellido='{p.Apellido}', Dni='{p.Dni}', Telefono='{p.Telefono}', Email='{p.Email}', Clave='{p.Clave}' " +
                             $"WHERE PropietarioId = {p.PropietarioId}";
                using (SqlCommand command = new SqlCommand(sql, connection))
                {
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    res = command.ExecuteNonQuery();
                    connection.Close();
                }
            }
            return(res);
        }
        public int Alta(Propietario p)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString)) {
                string sql = $"INSERT INTO Propietarios (Nombre, Apellido, Dni, Telefono, Email, Clave) " +
                             $"VALUES ('{p.Nombre}', '{p.Apellido}','{p.Dni}','{p.Telefono}','{p.Email}','{p.Clave}')";
                using (SqlCommand command = new SqlCommand(sql, connection)) {
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    res = command.ExecuteNonQuery();
                    command.CommandText = "SELECT SCOPE_IDENTITY()";
                    var id = command.ExecuteScalar();
                    p.IdPropietario = Convert.ToInt32(id);
                    connection.Close();
                }
            }
            return(res);
        }
        public int Modificacion(Propietario p)
        {
            int res = -1;

            using (SqlConnection connection = new SqlConnection(connectionString)) {
                string sql = $"UPDATE Propietarios SET Nombre=@nombre, Apellido=@apellido, Dni=@dni, Telefono=@telefono, Email=@mail " +
                             $"WHERE IdPropietario = {p.IdPropietario}";
                using (SqlCommand command = new SqlCommand(sql, connection)) {
                    command.Parameters.Add("@nombre", SqlDbType.VarChar).Value   = p.Nombre;
                    command.Parameters.Add("@apellido", SqlDbType.VarChar).Value = p.Apellido;
                    command.Parameters.Add("@dni", SqlDbType.VarChar).Value      = p.Dni;
                    command.Parameters.Add("@telefono", SqlDbType.VarChar).Value = p.Telefono;
                    command.Parameters.Add("@mail", SqlDbType.VarChar).Value     = p.Email;
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    res = command.ExecuteNonQuery();
                    connection.Close();
                }
            }

            return(res);
        }
Exemplo n.º 7
0
 public Conectado(Propietario p)
 {
     Usuario = p.Email;
     Nombre  = p.Nombre + " " + p.Apellido;
 }
Exemplo n.º 8
0
 public Propietario FinalizarContrato(Propietario i)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 9
0
 public Propietario Update(Propietario p)
 {
     throw new NotImplementedException();
 }