Пример #1
0
        private void OnButtonImageTapped(Object sender, EventArgs e)
        {
            var paramItem = ((GroupModelCollection <Donation>)((Button)sender).CommandParameter);
            var item      = _viewModel.GroupedDonationList.Where
                            (
                gdl => gdl.Title == paramItem.Title &&
                gdl.ShortName == paramItem.ShortName
                            ).FirstOrDefault();

            var indexItem = _viewModel.GroupedDonationList.IndexOf(item);

            _viewModel.GroupedDonationList[indexItem].Expanded = !_viewModel.GroupedDonationList[indexItem].Expanded;

            var newDonationListUpdated = new ObservableCollection <GroupModelCollection <Donation> >();

            foreach (var vmGroupedDonationList in _viewModel.GroupedDonationList)
            {
                var group = new GroupModelCollection <Donation>(vmGroupedDonationList.Title, vmGroupedDonationList.ShortName, vmGroupedDonationList.Expanded);
                group.GroupCount = vmGroupedDonationList.GroupCount;

                if (group.Expanded)
                {
                    foreach (var vmDonationCollection in vmGroupedDonationList)
                    {
                        group.Add(vmDonationCollection);
                    }
                }

                newDonationListUpdated.Add(group);
            }

            GroupedDonationView.ItemsSource = newDonationListUpdated;
        }
Пример #2
0
        protected async Task ExecuteSearchCommand()
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;

            GroupedDonationList.Clear();

            var donations = await _donationService.ListDonationsByLanguageAndNameAsync(_query);

            if (donations != null && donations.Count > 0)
            {
                var donationsDads = donations.Where(c => c.idDonationsDad == null);
                foreach (var itemDad in donationsDads)
                {
                    if (itemDad.names.Count > 0)
                    {
                        var groupName = itemDad.names[0].name;
                        var newGroup  = new GroupModelCollection <Donation>(groupName, groupName.Substring(0, 1))
                        {
                        };

                        var donationsDadSons = donations.Where(c => c.idDonationsDad == itemDad.idDonations);
                        newGroup.GroupCount = donationsDadSons.Count();
                        foreach (var itemDadSon in donationsDadSons)
                        {
                            if (itemDadSon.names.Count > 0)
                            {
                                newGroup.Add(new Donation()
                                {
                                    Id = itemDadSon.idDonations, Name = itemDadSon.names[0].name, Icon = "tab_about.png", Img = itemDadSon.img
                                });
                            }
                        }

                        GroupedDonationList.Add(newGroup);
                    }
                }
            }
            else
            {
                await Application.Current.MainPage.DisplayAlert("Query", "Donations not found", "Ok");
            }

            IsBusy = false;
        }