/// <summary> /// Assigns subscription object based on data from database to each Subscription button based on initial Button.Tag property and PosNumber endpoint in API. /// </summary> private void InitializeSubscriptionButtons() { //START - All buttons have Tag property with their consecutive number var buttons = HoursTopUpsButtons.Children.OfType <Button>().Concat(DaysTopUpsButtons.Children.OfType <Button>()); var subscriptionCollection = new SubscriptionRequest().GetByPosNumber(notNull: true); foreach (var button in buttons.Where(button => button.Tag != null)) { button.Tag = subscriptionCollection.Where(subscription => subscription.PosNumber == Convert.ToInt32(button.Tag.ToString())).FirstOrDefault(); if (button.Tag == null) { button.IsEnabled = false; } else { ((TextBlock)button.Content).Text = ((Subscription)button.Tag).Name + "\n" + ((decimal)((Subscription)button.Tag).Price / 100).ToString("0.00") + " PLN"; } } }