Ouch, this is a lot of code to include in a View. Looks like a ViewModel is in order.