Beispiel #1
0
        public LeagueYearViewModel(LeagueYear leagueYear, SupportedYear supportedYear, IEnumerable <Publisher> publishers, FantasyCriticUser currentUser, Publisher userPublisher,
                                   IClock clock, PlayStatus playStatus, StartDraftResult startDraftResult, IEnumerable <FantasyCriticUser> users, Maybe <Publisher> nextDraftPublisher, DraftPhase draftPhase,
                                   IEnumerable <PublisherGame> availableCounterPicks, LeagueWideValues leagueWideValues)
        {
            LeagueID                = leagueYear.League.LeagueID;
            Year                    = leagueYear.Year;
            SupportedYear           = new SupportedYearViewModel(supportedYear);
            StandardGames           = leagueYear.Options.StandardGames;
            GamesToDraft            = leagueYear.Options.GamesToDraft;
            CounterPicks            = leagueYear.Options.CounterPicks;
            MaximumEligibilityLevel = new EligibilityLevelViewModel(leagueYear.Options.MaximumEligibilityLevel, false);
            DraftSystem             = leagueYear.Options.DraftSystem.Value;
            PickupSystem            = leagueYear.Options.PickupSystem.Value;
            ScoringSystem           = leagueYear.Options.ScoringSystem.Name;
            UnlinkedGameExists      = publishers.SelectMany(x => x.PublisherGames).Any(x => x.MasterGame.HasNoValue);
            Publishers              = publishers.OrderBy(x => x.DraftPosition).Select(x => new PublisherViewModel(x, clock, nextDraftPublisher)).ToList();
            Standings               = publishers.OrderByDescending(x => x.TotalFantasyPoints).Select(x => new StandingViewModel(x, leagueYear.Options.ScoringSystem, leagueWideValues)).ToList();

            if (!(userPublisher is null))
            {
                UserPublisher = new PublisherViewModel(userPublisher, clock);
            }

            List <PlayerWithPublisherViewModel> playerVMs = new List <PlayerWithPublisherViewModel>();
            bool allPublishersMade = true;

            foreach (var user in users)
            {
                var publisher = publishers.SingleOrDefault(x => x.User.UserID == user.UserID);
                if (publisher is null)
                {
                    playerVMs.Add(new PlayerWithPublisherViewModel(leagueYear, user));
                    allPublishersMade = false;
                }
                else
                {
                    playerVMs.Add(new PlayerWithPublisherViewModel(leagueYear, user, publisher, clock));
                }
            }

            bool readyToSetDraftOrder = false;

            if (allPublishersMade)
            {
                Players = playerVMs.OrderBy(x => x.Publisher.DraftPosition).ToList();
                readyToSetDraftOrder = true;
            }
            else
            {
                Players = playerVMs;
            }

            PlayStatus            = new PlayStatusViewModel(playStatus, readyToSetDraftOrder, startDraftResult.Ready, startDraftResult.Errors, draftPhase);
            AvailableCounterPicks = availableCounterPicks.Select(x => new PublisherGameViewModel(x, clock)).ToList();
        }
Beispiel #2
0
        public LeagueYearViewModel(LeagueYear leagueYear, SupportedYear supportedYear, IEnumerable <Publisher> publishers, Maybe <Publisher> userPublisher,
                                   IClock clock, PlayStatus playStatus, StartDraftResult startDraftResult, IEnumerable <FantasyCriticUser> activeUsers, Maybe <Publisher> nextDraftPublisher, DraftPhase draftPhase,
                                   IEnumerable <PublisherGame> availableCounterPicks, LeagueOptions options, SystemWideValues systemWideValues, IEnumerable <LeagueInvite> invitedPlayers,
                                   bool userIsInLeague, bool userIsInvitedToLeague, bool userIsManager, Maybe <FantasyCriticUser> accessingUser)
        {
            LeagueID            = leagueYear.League.LeagueID;
            Year                = leagueYear.Year;
            SupportedYear       = new SupportedYearViewModel(supportedYear);
            StandardGames       = leagueYear.Options.StandardGames;
            GamesToDraft        = leagueYear.Options.GamesToDraft;
            CounterPicks        = leagueYear.Options.CounterPicks;
            EligibilitySettings = new EligibilitySettingsViewModel(leagueYear.Options.AllowedEligibilitySettings, false);
            DraftSystem         = leagueYear.Options.DraftSystem.Value;
            PickupSystem        = leagueYear.Options.PickupSystem.Value;
            ScoringSystem       = leagueYear.Options.ScoringSystem.Name;
            UnlinkedGameExists  = publishers.SelectMany(x => x.PublisherGames).Any(x => x.MasterGame.HasNoValue);
            UserIsActive        = activeUsers.Any(x => x.UserID == accessingUser.Unwrap(y => y.UserID));
            Publishers          = publishers
                                  .OrderBy(x => x.DraftPosition)
                                  .Select(x => new PublisherViewModel(x, clock, nextDraftPublisher, userIsInLeague, userIsInvitedToLeague, systemWideValues, supportedYear.Finished))
                                  .ToList();

            if (userPublisher.HasValue)
            {
                UserPublisher = new PublisherViewModel(userPublisher.Value, clock, userIsInLeague, userIsInvitedToLeague, systemWideValues, supportedYear.Finished);
            }

            List <PlayerWithPublisherViewModel> playerVMs = new List <PlayerWithPublisherViewModel>();
            bool allPublishersMade = true;

            foreach (var user in activeUsers)
            {
                var publisher = publishers.SingleOrDefault(x => x.User.UserID == user.UserID);
                if (publisher is null)
                {
                    playerVMs.Add(new PlayerWithPublisherViewModel(leagueYear, user, false));
                    allPublishersMade = false;
                }
                else
                {
                    playerVMs.Add(new PlayerWithPublisherViewModel(leagueYear, user, publisher, clock, options, systemWideValues,
                                                                   userIsInLeague, userIsInvitedToLeague, supportedYear, false));
                }
            }

            foreach (var invitedPlayer in invitedPlayers)
            {
                allPublishersMade = false;

                if (invitedPlayer.User.HasValue)
                {
                    playerVMs.Add(new PlayerWithPublisherViewModel(invitedPlayer.InviteID, invitedPlayer.User.Value.DisplayName));
                }
                else
                {
                    if (accessingUser.HasValue)
                    {
                        if (userIsManager || string.Equals(invitedPlayer.EmailAddress, accessingUser.Value.EmailAddress, StringComparison.OrdinalIgnoreCase))
                        {
                            playerVMs.Add(new PlayerWithPublisherViewModel(invitedPlayer.InviteID, invitedPlayer.EmailAddress));
                        }
                        else
                        {
                            playerVMs.Add(new PlayerWithPublisherViewModel(invitedPlayer.InviteID, "<Email Address Hidden>"));
                        }
                    }
                    else
                    {
                        playerVMs.Add(new PlayerWithPublisherViewModel(invitedPlayer.InviteID, "<Email Address Hidden>"));
                    }
                }
            }

            bool readyToSetDraftOrder = false;

            if (allPublishersMade)
            {
                Players = playerVMs.OrderBy(x => x.Publisher.DraftPosition).ToList();
                readyToSetDraftOrder = true;
            }
            else
            {
                Players = playerVMs;
            }

            PlayStatus            = new PlayStatusViewModel(playStatus, readyToSetDraftOrder, startDraftResult.Ready, startDraftResult.Errors, draftPhase);
            AvailableCounterPicks = availableCounterPicks
                                    .Select(x => new PublisherGameViewModel(x, clock, leagueYear.Options.ScoringSystem, systemWideValues))
                                    .OrderBy(x => x.GameName).ToList();
            EligibilityOverrides = leagueYear.EligibilityOverrides.Select(x => new EligibilityOverrideViewModel(x, clock)).ToList();
        }