Changing Foreach loop to Linq