예제 #1
0
        //TODO need to have validation logic here (or on PlayedGame similar to what is on NewlyCompletedGame)
        public PlayedGame CreatePlayedGame(NewlyCompletedGame newlyCompletedGame, TransactionSource transactionSource, ApplicationUser currentUser)
        {
            GameDefinition gameDefinition = dataContext.FindById <GameDefinition>(newlyCompletedGame.GameDefinitionId);

            securedEntityValidatorForGameDefinition.ValidateAccess(gameDefinition, currentUser, typeof(GameDefinition), newlyCompletedGame.GameDefinitionId);

            this.ValidateAccessToPlayers(newlyCompletedGame, currentUser);

            List <PlayerGameResult> playerGameResults = TransformNewlyCompletedGamePlayerRanksToPlayerGameResults(newlyCompletedGame);

            PlayedGame playedGame = TransformNewlyCompletedGameIntoPlayedGame(
                newlyCompletedGame,
                currentUser.CurrentGamingGroupId,
                currentUser.Id,
                playerGameResults);

            dataContext.Save(playedGame, currentUser);

            playedGameTracker.TrackPlayedGame(currentUser, transactionSource);

            foreach (PlayerGameResult result in playerGameResults)
            {
                nemesisRecalculator.RecalculateNemesis(result.PlayerId, currentUser);
            }
            championRecalculator.RecalculateChampion(playedGame.GameDefinitionId, currentUser);

            return(playedGame);
        }
        public static TransactionSourceModel FromEntity(TransactionSource transactionSource)
        {
            var transactionSourceModel = new TransactionSourceModel(transactionSource.Id);

            transactionSourceModel.MapFromEntity(transactionSource);
            return(transactionSourceModel);
        }
예제 #3
0
 public Context()
 {
     StepDelay           = TimeSpan.FromMilliseconds(20);
     TransactionSource   = Substitute.For <ITxSource>();
     BlockchainProcessor = Substitute.For <IBlockchainProcessor>();
     Sealer               = Substitute.For <ISealer>();
     BlockTree            = Substitute.For <IBlockTree>();
     BlockProcessingQueue = Substitute.For <IBlockProcessingQueue>();
     StateProvider        = Substitute.For <IStateProvider>();
     Timestamper          = Substitute.For <ITimestamper>();
     AuRaStepCalculator   = Substitute.For <IAuRaStepCalculator>();
     NodeAddress          = TestItem.AddressA;
     TransactionSource.GetTransactions(Arg.Any <BlockHeader>(), Arg.Any <long>()).Returns(Array.Empty <Transaction>());
     Sealer.CanSeal(Arg.Any <long>(), Arg.Any <Keccak>()).Returns(true);
     Sealer.SealBlock(Arg.Any <Block>(), Arg.Any <CancellationToken>()).Returns(c => Task.FromResult(c.Arg <Block>()));
     Sealer.Address.Returns(TestItem.AddressA);
     BlockProcessingQueue.IsEmpty.Returns(true);
     AuRaStepCalculator.TimeToNextStep.Returns(StepDelay);
     BlockTree.BestKnownNumber.Returns(1);
     BlockTree.Head.Returns(Build.A.Block.WithHeader(Build.A.BlockHeader.WithAura(10, Array.Empty <byte>()).TestObject).TestObject);
     BlockchainProcessor.Process(Arg.Any <Block>(), ProcessingOptions.ProducingBlock, Arg.Any <IBlockTracer>()).Returns(returnThis: c =>
     {
         Block block = c.Arg <Block>();
         block.TrySetTransactions(TransactionSource.GetTransactions(BlockTree.Head !.Header, block.GasLimit).ToArray());
         return(block);
     });
예제 #4
0
        //TODO need to have validation logic here (or on PlayedGame similar to what is on NewlyCompletedGame)
        public PlayedGame CreatePlayedGame(NewlyCompletedGame newlyCompletedGame, TransactionSource transactionSource, ApplicationUser currentUser)
        {
            if (newlyCompletedGame.GamingGroupId.HasValue && newlyCompletedGame.GamingGroupId != currentUser.CurrentGamingGroupId)
            {
                _securedEntityValidator.RetrieveAndValidateAccess<GamingGroup>(newlyCompletedGame.GamingGroupId.Value, currentUser);
            }

            var gameDefinition = _securedEntityValidator.RetrieveAndValidateAccess<GameDefinition>(newlyCompletedGame.GameDefinitionId, currentUser);

            _linkedPlayedGameValidator.Validate(newlyCompletedGame);

            var gamingGroupId = newlyCompletedGame.GamingGroupId ?? currentUser.CurrentGamingGroupId;

            ValidateAccessToPlayers(newlyCompletedGame.PlayerRanks, gamingGroupId, currentUser);

            var playerGameResults = MakePlayerGameResults(newlyCompletedGame, gameDefinition.BoardGameGeekGameDefinitionId);

            var playedGame = TransformNewlyCompletedGameIntoPlayedGame(
                newlyCompletedGame,
                gamingGroupId,
                currentUser.Id,
                playerGameResults);

            playedGame = _dataContext.Save(playedGame, currentUser);

            CreateApplicationLinkages(newlyCompletedGame.ApplicationLinkages, playedGame.Id);

            DoPostSaveStuff(transactionSource, currentUser, playedGame.Id, playedGame.GameDefinitionId, playerGameResults);

            return playedGame;
        }
예제 #5
0
        public virtual NewlyCreatedGamingGroupResult CreateNewGamingGroup(
            string gamingGroupName,
            TransactionSource registrationSource,
            ApplicationUser currentUser)
        {
            ValidateGamingGroupName(gamingGroupName);

            var gamingGroup = new GamingGroup()
            {
                OwningUserId = currentUser.Id,
                Name = gamingGroupName
            };

            var newlyCreatedGamingGroupResult = new NewlyCreatedGamingGroupResult();
            var newGamingGroup = dataContext.Save<GamingGroup>(gamingGroup, currentUser);
            newlyCreatedGamingGroupResult.NewlyCreatedGamingGroup = newGamingGroup;
            //commit changes since we'll need the GamingGroup.Id
            dataContext.CommitAllChanges();

            var newlyCreatedPlayer = this.AssociateUserWithGamingGroup(currentUser, newGamingGroup);
            newlyCreatedGamingGroupResult.NewlyCreatedPlayer = newlyCreatedPlayer;

            new Task(() => eventTracker.TrackGamingGroupCreation(registrationSource)).Start();

            return newlyCreatedGamingGroupResult;
        }
예제 #6
0
        public virtual NewlyCreatedGamingGroupResult CreateNewGamingGroup(
            string gamingGroupName,
            TransactionSource registrationSource,
            ApplicationUser currentUser)
        {
            ValidateGamingGroupName(gamingGroupName);

            GamingGroup gamingGroup = new GamingGroup()
            {
                OwningUserId = currentUser.Id,
                Name         = gamingGroupName
            };

            NewlyCreatedGamingGroupResult newlyCreatedGamingGroupResult = new NewlyCreatedGamingGroupResult();
            GamingGroup newGamingGroup = dataContext.Save <GamingGroup>(gamingGroup, currentUser);

            newlyCreatedGamingGroupResult.NewlyCreatedGamingGroup = newGamingGroup;
            //commit changes since we'll need the GamingGroup.Id
            dataContext.CommitAllChanges();

            Player newlyCreatedPlayer = this.AssociateUserWithGamingGroup(currentUser, newGamingGroup);

            newlyCreatedGamingGroupResult.NewlyCreatedPlayer = newlyCreatedPlayer;

            new Task(() => eventTracker.TrackGamingGroupCreation(registrationSource)).Start();

            return(newlyCreatedGamingGroupResult);
        }
        public async Task Create(DonorContext db, IIntegrationEventQueue queue, bool commitTransaction = true)
        {
            if (!IsValidated)
            {
                throw new Exception("Please validate model before creation.");
            }

            var donor = await db.Donors.FilterDeletedItems().SingleOrDefaultAsync(x => x.Id == DonorId);

            if (donor == null)
            {
                throw new ArgumentException($"Donor with ID '{DonorId}' does not exist.", nameof(DonorId));
            }

            var transactionSource = new TransactionSource();

            MapToEntity(transactionSource);
            db.TransactionSources.Add(transactionSource);
            MapFromEntity(transactionSource);

            if (commitTransaction)
            {
                await db.SaveChangesAsync();

                Id = transactionSource.Id;
                var integrationEvent = new IntegrationEvent <DonorTransactionSourceEvent>(ServiceNames.DonorService.ToString(), EventNames.AddDonorTransactionSource.ToString(), ToDonorTransactionSourceEvent());
                queue.Post(integrationEvent);
            }
        }
예제 #8
0
 public PlayedGameCreatedEvent(int playedGameId, int gameDefinitionId, List <int> participatingPlayerIds, TransactionSource expectedTransactionSource, ApplicationUser currentUser)
 {
     TriggerEntityId        = playedGameId;
     TransactionSource      = expectedTransactionSource;
     GameDefinitionId       = gameDefinitionId;
     ParticipatingPlayerIds = participatingPlayerIds;
     CurrentUser            = currentUser;
 }
 private void MapToEntity(TransactionSource transactionSource)
 {
     transactionSource.DonorId = DonorId;
     transactionSource.FinancialInstitution = FinancialInstitution;
     transactionSource.Identifier           = Identifier;
     transactionSource.Type = Enum.Parse <TransactionSourceType>(Type, true);
     transactionSource.TransactionSourceIdentifier = TransactionSourceIdentifier ?? Guid.NewGuid();
 }
 public void MapFromEntity(TransactionSource transactionSource)
 {
     Id      = transactionSource.Id;
     DonorId = transactionSource.DonorId;
     FinancialInstitution = transactionSource.FinancialInstitution;
     Identifier           = transactionSource.Identifier;
     Type = transactionSource.Type.ToString();
     TransactionSourceIdentifier = transactionSource.TransactionSourceIdentifier;
 }
        public void SetUp()
        {
            var userStoreMock = MockRepository.GenerateMock<IUserStore<ApplicationUser>>();
            var dataProtector = MockRepository.GenerateMock<IDataProtector>();
            dataProtectionProviderMock = MockRepository.GenerateMock<IDataProtectionProvider>();
            dataProtectionProviderMock.Expect(mock => mock.Create(Arg<string>.Is.Anything)).Return(dataProtector);
            applicationUserManagerMock = MockRepository.GenerateMock<ApplicationUserManager>(userStoreMock, dataProtectionProviderMock);
            gamingGroupSaverMock = MockRepository.GenerateMock<IGamingGroupSaver>();
            configurationManagerMock = MockRepository.GenerateMock<IConfigurationManager>();
            dataContextMock = MockRepository.GenerateMock<IDataContext>();

            firstTimeAuthenticator = new FirstTimeAuthenticator(
                gamingGroupSaverMock,
                applicationUserManagerMock,
                configurationManagerMock,
                dataContextMock);

            applicationUser = new ApplicationUser
            {
                Id = "user id",
                UserName = "******"
            };

            registrationSource = TransactionSource.RestApi;

            var appSettingsMock = MockRepository.GenerateMock<IAppSettings>();
            configurationManagerMock.Expect(mock => mock.AppSettings)
                                    .Return(appSettingsMock);
            appSettingsMock.Expect(mock => mock.Get(FirstTimeAuthenticator.APP_KEY_EMAIL_CONFIRMATION_CALLBACK_URL))
                           .Return(callbackUrl);

            expectedNewlyCreatedGamingGroupResult = new NewlyCreatedGamingGroupResult
            {
                NewlyCreatedGamingGroup = new GamingGroup {  Id = 1 },
                NewlyCreatedPlayer = new Player { Id = 100, Name = "some awesome player name"}
            };
            gamingGroupSaverMock.Expect(mock => mock.CreateNewGamingGroup(
                                                                          Arg<string>.Is.Anything,
                                                                          Arg<TransactionSource>.Is.Anything,
                                                                          Arg<ApplicationUser>.Is.Anything))
                                .Return(expectedNewlyCreatedGamingGroupResult);

            applicationUserManagerMock.Expect(mock => mock.GenerateEmailConfirmationTokenAsync(applicationUser.Id))
                                      .Return(Task.FromResult(confirmationToken));

            string expectedCallbackUrl = callbackUrl + string.Format(
                                                                     FirstTimeAuthenticator.CONFIRMATION_EMAIL_CALLBACK_URL_SUFFIX,
                                                                     applicationUser.Id,
                                                                     HttpUtility.UrlEncode(confirmationToken));
            string expectedEmailBody = string.Format(FirstTimeAuthenticator.CONFIRMATION_EMAIL_BODY, expectedCallbackUrl);
            applicationUserManagerMock.Expect(mock => mock.SendEmailAsync(
                                                                          applicationUser.Id,
                                                                          FirstTimeAuthenticator.EMAIL_SUBJECT,
                                                                          expectedEmailBody))
                                      .Return(Task.FromResult(-1));
        }
        public ITransactionSource Convert()
        {
            ITransactionSource transactionSource = new TransactionSource()
            {
                TransactionSourceId = TransactionSourceId,
                Name = Name
            };

            return(transactionSource);
        }
        public void TrackGamingGroupCreation(TransactionSource registrationSource)
        {
            IUniversalAnalyticsEvent universalAnalyticsEvent = eventFactory.MakeUniversalAnalyticsEvent(
                DEFAULT_ANONYMOUS_CLIENT_ID,
                EventCategoryEnum.GamingGroups.ToString(),
                EventActionEnum.Created.ToString(),
                registrationSource.ToString());

            eventTracker.TrackEvent(universalAnalyticsEvent);
        }
        public void TrackPlayedGame(ApplicationUser currentUser, TransactionSource transactionSource)
        {
            IUniversalAnalyticsEvent universalAnalyticsEvent = eventFactory.MakeUniversalAnalyticsEvent(
                currentUser.AnonymousClientId,
                EventCategoryEnum.PlayedGames.ToString(),
                EventActionEnum.Created.ToString(),
                transactionSource.ToString());

            eventTracker.TrackEvent(universalAnalyticsEvent);
        }
예제 #15
0
        public PlayedGame UpdatePlayedGame(UpdatedGame updatedGame, TransactionSource transactionSource, ApplicationUser currentUser)
        {
            if (updatedGame.GamingGroupId.HasValue)
            {
                _securedEntityValidator.RetrieveAndValidateAccess <GamingGroup>(updatedGame.GamingGroupId.Value, currentUser);
            }
            _securedEntityValidator.RetrieveAndValidateAccess <PlayedGame>(updatedGame.PlayedGameId, currentUser);
            _securedEntityValidator.RetrieveAndValidateAccess <GameDefinition>(updatedGame.GameDefinitionId, currentUser);

            var playedGameWithStuff = _dataContext.GetQueryable <PlayedGame>()
                                      .Where(x => x.Id == updatedGame.PlayedGameId)
                                      .Include(x => x.ApplicationLinkages)
                                      .Include(x => x.GameDefinition)
                                      .Include(x => x.PlayerGameResults)
                                      .FirstOrDefault();

            if (playedGameWithStuff == null)
            {
                throw new EntityDoesNotExistException(typeof(PlayedGame), updatedGame.PlayedGameId);
            }

            var gamingGroupId = updatedGame.GamingGroupId ?? playedGameWithStuff.GamingGroupId;

            ValidateAccessToPlayers(updatedGame.PlayerRanks, gamingGroupId, currentUser, _dataContext);

            var playerGameResults = MakePlayerGameResults(updatedGame, playedGameWithStuff.GameDefinition?.BoardGameGeekGameDefinitionId, _dataContext);
            var updatedPlayedGame = TransformNewlyCompletedGameIntoPlayedGame(updatedGame, gamingGroupId, currentUser.Id, playerGameResults);

            updatedPlayedGame.Id          = updatedGame.PlayedGameId;
            updatedPlayedGame.DateUpdated = DateTime.UtcNow;

            CleanupPlayerResultsAndApplicationLinkages(currentUser, playedGameWithStuff);

            var returnPlayedGame = _dataContext.Save(updatedPlayedGame, currentUser);

            //--Entity Framework doesn't appear to save new child entities when updating the parent entity so we have to save them separately
            playerGameResults.ForEach(x =>
            {
                x.PlayedGameId = returnPlayedGame.Id;
                _dataContext.Save(x, currentUser);
            });

            CreateApplicationLinkages(updatedGame.ApplicationLinkages, updatedGame.PlayedGameId, _dataContext);

            var playerIds = playerGameResults.Select(x => x.PlayerId).ToList();

            _businessLogicEventSender.SendEvent(new PlayedGameCreatedEvent(
                                                    updatedGame.PlayedGameId,
                                                    updatedGame.GameDefinitionId,
                                                    playerIds,
                                                    transactionSource,
                                                    currentUser));

            return(returnPlayedGame);
        }
예제 #16
0
        public void TrackUserRegistration(TransactionSource registrationSource)
        {
            IUniversalAnalyticsEvent universalAnalyticsEvent = eventFactory.MakeUniversalAnalyticsEvent(
                DEFAULT_ANONYMOUS_CLIENT_ID,
                EventCategoryEnum.Users.ToString(),
                EventActionEnum.Created.ToString(),
                registrationSource.ToString(),
                nonInteractionEvent: IsNonInteractionEvent(TransactionSource.RestApi));

            eventTracker.TrackEvent(universalAnalyticsEvent);
        }
예제 #17
0
        internal virtual void DoPostSaveStuff(TransactionSource transactionSource,
            ApplicationUser currentUser, int playedGameId, int gameDefinitionId, List<PlayerGameResult> playerGameResults)
        {
            _playedGameTracker.TrackPlayedGame(currentUser, transactionSource);

            foreach (var result in playerGameResults)
            {
                _nemesisRecalculator.RecalculateNemesis(result.PlayerId, currentUser);
            }
            _championRecalculator.RecalculateChampion(gameDefinitionId, currentUser, false);

            SendEvents(new IBusinessLogicEvent[] {new PlayedGameCreatedEvent() {TriggerEntityId = playedGameId}});
        }
예제 #18
0
        public void ItSetsTheEventLabelToTheTransactionSource()
        {
            TransactionSource transactionSource = TransactionSource.RestApi;

            eventFactoryMock.Expect(mock => mock.MakeUniversalAnalyticsEvent(
                                        Arg <string> .Is.Anything,
                                        Arg <string> .Is.Anything,
                                        Arg <string> .Is.Anything,
                                        Arg <string> .Is.Equal(transactionSource.ToString()),
                                        Arg <string> .Is.Anything))
            .Return(analyticsEvent);

            tracker.TrackPlayedGame(currentUser, transactionSource);

            eventTrackerMock.AssertWasCalled(mock => mock.TrackEvent(analyticsEvent));
        }
예제 #19
0
        public void ItTracksTheGamingGroupCreation()
        {
            GamingGroup expectedGamingGroup = new GamingGroup()
            {
                Id = 123
            };

            autoMocker.Get <IDataContext>().Expect(mock => mock.Save(Arg <GamingGroup> .Is.Anything, Arg <ApplicationUser> .Is.Anything))
            .Repeat.Once()
            .Return(expectedGamingGroup);
            TransactionSource expectedRegistrationSource = TransactionSource.RestApi;

            autoMocker.ClassUnderTest.CreateNewGamingGroup(gamingGroupName, expectedRegistrationSource, currentUser);

            autoMocker.Get <INemeStatsEventTracker>().AssertWasCalled(mock => mock.TrackGamingGroupCreation(expectedRegistrationSource));
        }
        public void ItSetsTheLabelToTheSpecifiedRegistrationSource()
        {
            TransactionSource registrationSource = TransactionSource.RestApi;

            eventFactoryMock.Expect(mock => mock.MakeUniversalAnalyticsEvent(
                                        Arg <string> .Is.Anything,
                                        Arg <string> .Is.Anything,
                                        Arg <string> .Is.Anything,
                                        Arg <string> .Is.Equal(registrationSource.ToString()),
                                        Arg <string> .Is.Anything))
            .Return(analyticsEvent);

            tracker.TrackGamingGroupCreation(registrationSource);

            eventTrackerMock.AssertWasCalled(mock => mock.TrackEvent(analyticsEvent));
        }
예제 #21
0
        public void ItSetsTheEventLabelToTheTransactionSource()
        {
            TransactionSource transactionSource = TransactionSource.RestApi;

            _autoMocker.Get <IUniversalAnalyticsEventFactory>().Expect(mock => mock.MakeUniversalAnalyticsEvent(
                                                                           Arg <string> .Is.Anything,
                                                                           Arg <string> .Is.Anything,
                                                                           Arg <string> .Is.Anything,
                                                                           Arg <string> .Is.Equal(transactionSource.ToString()),
                                                                           Arg <string> .Is.Anything,
                                                                           Arg <string> .Is.Anything,
                                                                           Arg <bool> .Is.Anything))
            .Return(analyticsEvent);

            _autoMocker.ClassUnderTest.TrackPlayedGame(currentUser, transactionSource);

            _autoMocker.Get <IEventTracker>().AssertWasCalled(mock => mock.TrackEvent(analyticsEvent));
        }
        public void ItSetsTheLabelToTheSpecifiedRegistrationSource()
        {
            TransactionSource registrationSource = TransactionSource.RestApi;

            _autoMocker.Get <IUniversalAnalyticsEventFactory>().Expect(mock => mock.MakeUniversalAnalyticsEvent(
                                                                           Arg <string> .Is.Anything,
                                                                           Arg <string> .Is.Anything,
                                                                           Arg <string> .Is.Anything,
                                                                           Arg <string> .Is.Equal(registrationSource.ToString()),
                                                                           Arg <string> .Is.Anything,
                                                                           Arg <string> .Is.Anything,
                                                                           Arg <bool> .Is.Anything))
            .Return(analyticsEvent);

            _autoMocker.ClassUnderTest.TrackGamingGroupCreation(registrationSource);

            _autoMocker.Get <IEventTracker>().AssertWasCalled(mock => mock.TrackEvent(analyticsEvent));
        }
예제 #23
0
        private void AddDonation(TransactionSource transactionSource, TransactionIntegrationEvent @event)
        {
            var charities = _donorContext.DonorCharities
                            .FilterDeletedItems()
                            .Include(x => x.DonorCharityProportions)
                            .Include(x => x.Donor)
                            .Where(x => x.DonorId == transactionSource.DonorId)
                            .ToList();

            if (!charities.Any())
            {
                return;
            }

            foreach (var charity in charities)
            {
                var donorCharityProportion = charity
                                             .DonorCharityProportions
                                             .LastOrDefault(x => @event.TransactionDateTimeUtc >= x.ValidFromUtc && @event.TransactionDateTimeUtc <= x.ValidToUtc);

                if (donorCharityProportion == null)
                {
                    continue;
                }

                var donationPercentage = donorCharityProportion.DonationPercentage;

                var donation = new Donation
                {
                    Amount   = (@event.Amount * (charity.Donor.TransactionDonationPercentage / (decimal)100.0)) * (donationPercentage / (decimal)100.0),
                    Currency = @event.Currency,
                    DonorCharityProportionId      = donorCharityProportion.Id,
                    TransactionIdentifier         = @event.TransactionIdentifier,
                    DonationDateTimeUtc           = DateTime.UtcNow,
                    MerchantName                  = @event.MerchantName,
                    TransactionAmount             = @event.Amount,
                    TransactionDateTimeUtc        = @event.TransactionDateTimeUtc,
                    TransactionDonationPercentage = charity.Donor.TransactionDonationPercentage
                };

                _donorContext.Donations.Add(donation);
            }
        }
예제 #24
0
        public void ItRecordsAGamePlayedEvent()
        {
            PlayerRank playerRank = new PlayerRank()
            {
                GameRank = 1,
                PlayerId = 1
            };
            NewlyCompletedGame newlyCompletedGame = new NewlyCompletedGame()
            {
                GameDefinitionId = gameDefinition.Id,
                PlayerRanks      = new List <PlayerRank>()
                {
                    playerRank
                }
            };
            TransactionSource transactionSource = TransactionSource.RestApi;

            autoMocker.ClassUnderTest.CreatePlayedGame(newlyCompletedGame, transactionSource, this.currentUser);

            autoMocker.Get <INemeStatsEventTracker>().AssertWasCalled(mock => mock.TrackPlayedGame(currentUser, transactionSource));
        }
예제 #25
0
        public async Task<NewlyRegisteredUser> CreateGamingGroupAndSendEmailConfirmation(
            ApplicationUser applicationUser, 
            TransactionSource registrationSource)
        {
            //fetch this first since we want to fail as early as possible if the config entry is missing
            var callbackUrl = this.GetCallbackUrlFromConfig();

            NewlyCreatedGamingGroupResult result = this.gamingGroupSaver.CreateNewGamingGroup(
                applicationUser.UserName + "'s Gaming Group",
                registrationSource,
                applicationUser);

            await this.SendConfirmationEmail(applicationUser, callbackUrl);

            return new NewlyRegisteredUser
            {
                GamingGroupId = result.NewlyCreatedGamingGroup.Id,
                GamingGroupName = result.NewlyCreatedGamingGroup.Name,
                PlayerId = result.NewlyCreatedPlayer.Id,
                PlayerName = result.NewlyCreatedPlayer.Name,
                UserId = applicationUser.Id
            };
        }
예제 #26
0
        public async Task <NewlyRegisteredUser> CreateGamingGroupAndSendEmailConfirmation(
            ApplicationUser applicationUser,
            TransactionSource registrationSource)
        {
            //fetch this first since we want to fail as early as possible if the config entry is missing
            var callbackUrl = this.GetCallbackUrlFromConfig();

            NewlyCreatedGamingGroupResult result = this.gamingGroupSaver.CreateNewGamingGroup(
                applicationUser.UserName + "'s Gaming Group",
                registrationSource,
                applicationUser);

            await this.SendConfirmationEmail(applicationUser, callbackUrl);

            return(new NewlyRegisteredUser
            {
                GamingGroupId = result.NewlyCreatedGamingGroup.Id,
                GamingGroupName = result.NewlyCreatedGamingGroup.Name,
                PlayerId = result.NewlyCreatedPlayer.Id,
                PlayerName = result.NewlyCreatedPlayer.Name,
                UserId = applicationUser.Id
            });
        }
예제 #27
0
        public async Task <IActionResult> PostTransactions(string accountId, [FromQuery] TransactionSource transactionSource)
        {
            var bytes = new byte[HttpContext.Request.ContentLength.Value];

            using (var ms = new MemoryStream(bytes.Length))
            {
                await HttpContext.Request.Body.CopyToAsync(ms);

                ms.Seek(0, SeekOrigin.Begin);

                using (var sr = new StreamReader(ms))
                {
                    switch (transactionSource)
                    {
                    case TransactionSource.Hac:
                        await _accountHandler.ProcessHacTransactions(accountId, await sr.ReadToEndAsync());

                        break;

                    case TransactionSource.OtpBank:
                        await _accountHandler.ProcessOtpBankTransactions(accountId, await sr.ReadToEndAsync());

                        break;

                    case TransactionSource.Revolut:
                        await _accountHandler.ProcessRevolutTransactions(accountId, await sr.ReadToEndAsync());

                        break;

                    default:
                        throw new System.Exception();
                    }
                }
            }

            return(Ok());
        }
예제 #28
0
        public async Task Handle(JsonElement transaction, JsonElement contractCall, TransactionSource transactionSource, CancellationToken cancellationToken)
        {
            if (contractCall.GetProperty(Blocknative.Properties.MethodName).ValueEquals(Uniswap.SwapExactEthForTokens))
            {
                var transactionHash = transaction.GetProperty(Blocknative.Properties.Hash).GetString();
                _logger.LogTrace($"Transaction {transactionHash} received");

                var transactionStatus = EnumHelper.GetValueFromDescription <TransactionStatus>(transaction.GetProperty(Blocknative.Properties.Status).GetString());

                switch (transactionStatus)
                {
                case TransactionStatus.Pending:
                    var @params = contractCall.GetProperty(Blocknative.Properties.Params);
                    await _transactionProcessorService.Process(new Swap
                    {
                        TransactionHash = transactionHash,
                        AmountIn        = TryParseJsonString(transaction, Blocknative.Properties.Value),
                        Gas             = transaction.GetProperty(Blocknative.Properties.Gas).GetUInt64(),
                        GasPrice        = TryParseJsonString(transaction, Blocknative.Properties.GasPrice),
                        AmountOutMin    = TryParseJsonString(@params, Blocknative.Properties.AmountOutMin),
                        Deadline        = (long)TryParseJsonString(@params, Blocknative.Properties.Deadline),
                        Path            = @params.GetProperty(Blocknative.Properties.Path).EnumerateArray().Select(e => e.GetString()).ToList(),
                        Source          = transactionSource
                    }, cancellationToken);
예제 #29
0
 public Application(TransactionSource transactionSource)
 {
     _source = transactionSource;
 }
예제 #30
0
        public PlayedGame UpdatePlayedGame(UpdatedGame updatedGame, TransactionSource transactionSource, ApplicationUser currentUser)
        {
            if (updatedGame.GamingGroupId.HasValue)
            {
                _securedEntityValidator.RetrieveAndValidateAccess<GamingGroup>(updatedGame.GamingGroupId.Value, currentUser);
            }
            _securedEntityValidator.RetrieveAndValidateAccess<PlayedGame>(updatedGame.PlayedGameId, currentUser);
            _securedEntityValidator.RetrieveAndValidateAccess<GameDefinition>(updatedGame.GameDefinitionId, currentUser);

            var playedGameWithStuff = _dataContext.GetQueryable<PlayedGame>()
                .Where(x => x.Id == updatedGame.PlayedGameId)
                .Include(x => x.ApplicationLinkages)
                .Include(x => x.GameDefinition)
                .Include(x => x.PlayerGameResults)
                .FirstOrDefault();

            if (playedGameWithStuff == null)
            {
                throw new EntityDoesNotExistException(typeof(PlayedGame), updatedGame.PlayedGameId);
            }

            var gamingGroupId = updatedGame.GamingGroupId ?? playedGameWithStuff.GamingGroupId;

            ValidateAccessToPlayers(updatedGame.PlayerRanks, gamingGroupId, currentUser);
            
            var playerGameResults = MakePlayerGameResults(updatedGame, playedGameWithStuff.GameDefinition?.BoardGameGeekGameDefinitionId);
            var updatedPlayedGame = TransformNewlyCompletedGameIntoPlayedGame(updatedGame, gamingGroupId, currentUser.Id, playerGameResults);

            updatedPlayedGame.Id = updatedGame.PlayedGameId;
            updatedPlayedGame.DateUpdated = DateTime.UtcNow;

            CleanupPlayerResultsAndApplicationLinkages(currentUser, playedGameWithStuff);

            var returnPlayedGame = _dataContext.Save(updatedPlayedGame, currentUser);

            //--Entity Framework doesn't appear to save new child entities when updating the parent entity so we have to save them separately
            playerGameResults.ForEach(x =>
            {
                x.PlayedGameId = returnPlayedGame.Id;
                _dataContext.Save(x, currentUser);
            });

            CreateApplicationLinkages(updatedGame.ApplicationLinkages, updatedGame.PlayedGameId);

            DoPostSaveStuff(transactionSource, currentUser, playedGameWithStuff.Id, playedGameWithStuff.GameDefinitionId, playerGameResults);

            return returnPlayedGame;
        }
예제 #31
0
 internal virtual bool IsNonInteractionEvent(TransactionSource transactionSource)
 {
     return(transactionSource == TransactionSource.RestApi);
 }
예제 #32
0
 public TransactionApp(TransactionSource ts)
 {
     this.ts = ts;
 }
예제 #33
0
 public PayrollApp(TransactionSource ts) : base(ts)
 {
     PayrollFactory.paymentFactory = new PaymentFactoryImplementation();
     RequestFactory.rf             = new RequestFactoryImplementation();
 }
예제 #34
0
 public void AddTransactionSource(TransactionSource source)
 {
     source.Id = _nextSourceId;
     _sources.Add(source);
     _nextSourceId++;
 }