Esempio n. 1
0
        public void Insert(UserDO user)
        {
            string hashedPassword = EncriptadorIrreversible.EncriptarIrreversible(user.Password);

            using (var connection = SQLDbConnection.GetConnection())
            {
                var command = connection.CreateCommand();
                command.Parameters.Add(new SqlParameter("@username", user.Alias));
                command.Parameters.Add(new SqlParameter("@password", hashedPassword));
                command.Parameters.Add(new SqlParameter("@name", user.Nombre));
                command.Parameters.Add(new SqlParameter("@lastname", user.Apellido));
                command.Parameters.Add(new SqlParameter("@email", user.Email));
                command.CommandText = $"INSERT INTO {DbSchema.Users.Table} ({DbSchema.Users.ListColumns()}) " +
                                      $"VALUES(@username, @password, @name, @lastname, @email)";
                command.ExecuteNonQuery();
                connection.Close();
            }
        }
Esempio n. 2
0
        public void Update(UserDO user)
        {
            string hashedPassword = EncriptadorIrreversible.EncriptarIrreversible(user.Password);

            using (var connection = SQLDbConnection.GetConnection())
            {
                var command = connection.CreateCommand();
                command.Parameters.Add(new SqlParameter("@id", user.Id));
                command.Parameters.Add(new SqlParameter("username", user.Alias));
                command.Parameters.Add(new SqlParameter("@password", hashedPassword));
                command.Parameters.Add(new SqlParameter("@name", user.Nombre));
                command.Parameters.Add(new SqlParameter("@lastname", user.Apellido));
                command.Parameters.Add(new SqlParameter("@email", user.Email));
                command.CommandText = $"UPDATE {DbSchema.Users.Table} " +
                                      $"SET {DbSchema.Users.Nombre} = @username, {DbSchema.Users.Password} = @password, " +
                                      $"{DbSchema.Users.Nombre} = @name, {DbSchema.Users.Apellido} = @lastname, " +
                                      $"{DbSchema.Users.Email} = @email " +
                                      $"WHERE {DbSchema.Users.Id} = @id";
                command.ExecuteNonQuery();
                connection.Close();
            }
        }