Пример #1
0
        private async void UpdateLeagues()
        {
            var LeaguesAPIList = await RapidFutballHelper.GetLeagues(SelectedCountry.country);

            Leagues.Clear();
            foreach (var League in LeaguesAPIList)
            {
                Leagues.Add(League);
            }
        }
Пример #2
0
        public void AddSeasonAction()
        {
            var vm      = new LeagueViewModel(SimpleIoc.Default.GetInstance <IOpenLigaService>());
            var message = new ModalDialogMessage {
                ViewModel = vm
            };

            this.MessengerInstance.Send(message);
            if (message.DialogResult == true)
            {
                Leagues.Add(vm);
            }
        }
 private void ReloadLeagues(List <League> leagues)
 {
     Leagues.Clear();
     foreach (var league in leagues.OrderBy(l => l.Name)) //pero mas mejor si lo mando desde el api
     {
         Leagues.Add(new LeagueItemViewModel
         {
             LeagueId = league.LeagueId,
             Logo     = league.Logo,
             Name     = league.Name,
             Teams    = league.Teams,
         });
     }
 }
Пример #4
0
        private void AddAllLeagues()
        {
            foreach (var league in _leagueAndSeasonInfoService.GetAllLeagueInfo())
            {
                foreach (var season in league.Seasons)
                {
                    Leagues.Add(LeagueViewModel.Create(league.League, season));
                }
            }

            if (Leagues.Count > 0)
            {
                SelectedLeague = Leagues[0];
            }
        }
Пример #5
0
        public static Leagues ParseLeagues(XmlNodeList leaguesList)
        {
            Leagues l = new Leagues();

            if (leaguesList.Count > 0)
            {
                foreach (XmlNode league in leaguesList)
                {
                    int id = int.Parse(league["ID"].InnerText);
                    bool leagueLoaded = bool.Parse(league["Loaded"].InnerText);

                    Rounds rounds = RoundParsing.ParseRounds(league.SelectNodes("Rounds/Round"));
                    l.Add(new League(id, league["Name"].InnerText, leagueLoaded, rounds));
                }
            }

            return l;
        }
Пример #6
0
        async public Task GetAvailableLeagues(bool forceRefresh = false)
        {
            Debug.WriteLine(IsBusy);
            //using(new Busy(this))
            {
                Debug.WriteLine(IsBusy);
                try
                {
                    var leagueIds = App.Instance.CurrentAthlete.Memberships.Select(m => m.LeagueId).ToList();
                    var toJoin    = await AzureService.Instance.LeagueManager.Table.Where(l => l.IsAcceptingMembers && l.IsEnabled).ToListAsync();

                    if (leagueIds.Count > 0)
                    {
                        toJoin = toJoin.Where(l => !leagueIds.Contains(l.Id)).ToList();
                    }

                    Leagues.Clear();
                    toJoin.ForEach(l => Leagues.Add(new LeagueViewModel {
                        League = l
                    }));
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine(e);
                }

                if (Leagues.Count == 0)
                {
                    Leagues.Add(new LeagueViewModel
                    {
                        EmptyMessage = "There are no available leagues to join."
                    });
                }

                Debug.WriteLine(IsBusy);
            }
        }
Пример #7
0
 public virtual void Add(League league)
 {
     Leagues.Add(league);
     league.Country = this;
 }
        public bool Refresh()
        {
            /**
             * Note: checking if cache has changed after refresh
             *
             *  Algorithm:
             *      checking if the sequence had changed (by sequenceEqual).
             *      if it had changed - an update occur. and isChanged = true;
             *
             *  Author:
             *      Idan Izicovich.
             * */

            /* ---------- Cache Dictionaries ---------- */

            // Users
            bool isUserChanged = false;

            if (!UserManager.Users.SequenceEqual(Users))
            {
                Users.Clear();
                UserManager.Users.ToList().ForEach(userPair => Users.Add(userPair.Key, userPair.Value));
                isUserChanged = true;
            }

            // Players
            bool isPlayersChanged = false;

            if (!GameCenter.Players.SequenceEqual(Players.Values, new AddressComparer <Player>()))
            {
                Players.Clear();
                GameCenter.Players.ToList().ForEach(player => Players.Add(player.GetHashCode(), player));
                isPlayersChanged = true;
            }

            // Rooms
            bool isRoomChanged = false;

            if (!GameCenter.Rooms.SequenceEqual(Rooms.Values))
            {
                Rooms.Clear();
                GameCenter.Rooms.ToList().ForEach(room => Rooms.Add(room.GetHashCode(), room));
                isRoomChanged = true;
            }

            // Leagues
            //Undone: idan - make sure this is the right dictionary key needed for mapping the leagues at the cache
            bool isLeagueChange = false;

            if (!GameCenter.Leagues.SequenceEqual(Leagues.Values))
            {
                Leagues.Clear();
                GameCenter.Leagues.ToList().ForEach(league => Leagues.Add(league.GetHashCode(), league));
                isLeagueChange = true;
            }


            /* ------- link-cache dictionaries ---------- */

            // PlayerToRoom
            if (isPlayersChanged | isRoomChanged)
            {
                PlayerToRoom.Clear();
                GameCenter.PlayerToRoom.ToList().ForEach(pair => PlayerToRoom.Add(pair.Key, pair.Value));
            }

            // RoomToLeague
            if (isRoomChanged | isLeagueChange)
            {
                RoomToLeague.Clear();
                GameCenter.RoomToLeague.ToList().ForEach(pair => RoomToLeague.Add(pair.Key, pair.Value));
            }

            return(isLeagueChange | isPlayersChanged | isRoomChanged | isUserChanged);
        }
        public void LocalRefresh()
        {
            if (App.CurrentAthlete == null)
            {
                return;
            }

            var comparer = new LeagueComparer();
            var toJoin   = DataManager.Instance.Leagues.Where(k => !App.CurrentAthlete.Memberships.Select(m => m.LeagueId).Contains(k.Key))
                           .Select(k => k.Value).ToList();

            var toRemove = Leagues.Where(vm => vm.League != null).Select(vm => vm.League).Except(toJoin, comparer).ToList();
            var toAdd    = toJoin.Except(Leagues.Select(vm => vm.League), comparer).OrderBy(r => r.Name).Select(l => new LeagueViewModel {
                LeagueId = l.Id
            }).ToList();

            toRemove.ForEach(l => Leagues.Remove(Leagues.Single(vm => vm.League == l)));

            if (Leagues.Count == 0 && toAdd.Count == 0)
            {
                if (_empty == null)
                {
                    _empty = new LeagueViewModel {
                        EmptyMessage = "There are no available leagues to join."
                    }
                }
                ;

                if (!Leagues.Contains(_empty))
                {
                    Leagues.Add(_empty);
                }
            }

            var compare = new LeagueSortComparer();

            foreach (var lv in toAdd)
            {
                int index = 0;
                foreach (var l in Leagues.ToList())
                {
                    if (compare.Compare(lv, l) < 0)
                    {
                        break;
                    }

                    index++;
                }
                Leagues.Insert(index, lv);
            }

            if (toAdd.Count > 0 || toRemove.Count > 0)
            {
                var last = Leagues.LastOrDefault();
                foreach (var l in Leagues)
                {
                    l.IsLast = l == last;
                }
            }

            if (Leagues.Count > 0 && Leagues.Contains(_empty) && Leagues.First() != _empty)
            {
                Leagues.Remove(_empty);
            }
        }

        async public Task GetAvailableLeagues(bool forceRefresh = false)