예제 #1
0
        public async Task SetIsInternalByWalletAsync(SetIsInternalByWalletRequest request)
        {
            using var activity = MyTelemetry.StartActivity("SetIsInternalByWalletAsync");
            request.AddToActivityAsJsonTag("request");

            _logger.LogWarning("Change IsInternal. Wallet: {walletId}, IsInternal: {flag}", request.WalletId, request.IsInternal);

            await using var ctx = new DatabaseContext(_dbContextOptionsBuilder.Options);

            var walletEntity = ctx.ClientWallet.FirstOrDefault(e => e.WalletId == request.WalletId);

            if (walletEntity != null)
            {
                if (request.IsInternal)
                {
                    walletEntity.EnableEarnProgram = false;
                }

                walletEntity.IsInternal = request.IsInternal;
                await ctx.SaveChangesAsync();
            }
        }
예제 #2
0
        public async Task SetIsInternalByWalletAsync(SetIsInternalByWalletRequest request)
        {
            using var activity = MyTelemetry.StartActivity("SetIsInternalByWalletAsync");
            request.AddToActivityAsJsonTag("request");

            _logger.LogWarning("Change IsInternal. Wallet: {walletId}, IsInternal: {flag}", request.WalletId, request.IsInternal);

            await using var ctx = new DatabaseContext(_dbContextOptionsBuilder.Options);

            var walletEntity = ctx.ClientWallet.FirstOrDefault(e => e.WalletId == request.WalletId);

            if (walletEntity != null)
            {
                var oldWallet = (ClientWallet)walletEntity.Clone();

                if (request.IsInternal)
                {
                    walletEntity.EnableEarnProgram = false;
                }

                walletEntity.IsInternal = request.IsInternal;
                await ctx.SaveChangesAsync();

                await UpdateCache(
                    walletEntity.ClientId,
                    walletEntity.BrokerId,
                    new List <ClientWalletEntity> {
                    walletEntity
                });

                await _publisher.PublishAsync(new ClientWalletUpdateMessage()
                {
                    OldWallet = ClientWallet.Create(oldWallet),
                    NewWallet = ClientWallet.Create(walletEntity)
                });
            }
        }