Пример #1
0
        public ActionResult Play(long poemId, VerseEngineeringUser user, HideCandidateVersesFlag hideCandidateVerses)
        {
            if (!IsPlayRequestValid(poemId, user))
            {
                return RedirectToAction("Start");
            }

            Poem poem = poemService.GetPoemById(poemId);

            if (poem == null)
            {
                return RedirectToAction("Start");
            }

            if(!IsUserInPlayersList(user, poem))
            {
                return RedirectToAction("Start");
            }

            PoemVersesBag versesBag = verseService.GetPoemVersesForUser(poemId, user.UserId);

            if (hideCandidateVerses.HidePreviousCandidateVerses)
            {
                versesBag.FilterToLatestCandidateVerses();
            }

            signalizerFactory.GetSignal<PlayerEnteredTheGameSignal<Raw>>()
                .FromUser(user.UserId, user.Name)
                .Send(poem.Id, new UserProfileData { Id = user.UserId, Name = user.Name, PictureUrl = user.UserId.ToSquarePictureLink() });

            PlayPoemViewModel viewModel = new PlayPoemViewModel
                {
                    Poem = poem,
                    Verses = versesBag,
                    AcceptedPlayers = poemService.GetPlayersThatAcceptedGameInvitation(poem),
                    PendingPlayers = poemService.GetPendingGamePlayers(poem),
                    IsAbleToHidePreviousCandidateVerses = IsAbleToHidePreviousCandidateVerses(versesBag, hideCandidateVerses),
                    Me = user,
                    AuthToken = cryptoService.Encrypt(new PoemToken { PoemId = poem.Id, ProfileId = user.UserId })
                };

            return View(viewModel);
        }
Пример #2
0
        private bool IsAbleToHidePreviousCandidateVerses(PoemVersesBag versesBag, HideCandidateVersesFlag hideCandidateVerses)
        {
            if (hideCandidateVerses.HidePreviousCandidateVerses == false && versesBag.CandidateVerses.Any())
            {
                if (versesBag.PoemVerses.Any()
                    &&
                    versesBag.CandidateVerses.Max(verse => verse.OrderNr)
                    > versesBag.PoemVerses.Max(verse => verse.OrderNr))
                {
                    return true;
                }
            }

            return false;
        }