Beispiel #1
0
        public void Handle(PlayerContactVerified @event)
        {
            var repository = _container.Resolve <IBonusRepository>();

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var player = repository.GetLockedPlayer(@event.PlayerId);
                if (@event.ContactType == ContactType.Mobile)
                {
                    player.VerifyMobileNumber();
                }
                if (@event.ContactType == ContactType.Email)
                {
                    player.VerifyEmailAddress();
                }

                if (player.Data.IsEmailVerified && player.Data.IsMobileVerified)
                {
                    var bonusCommands = _container.Resolve <BonusCommands>();
                    bonusCommands.ProcessFirstBonusRedemptionOfType(player, BonusType.MobilePlusEmailVerification);
                }

                repository.SaveChanges();
                scope.Complete();
            }
        }
        public RiskProfileConfiguration Create(RiskProfileCheckDTO data)
        {
            var entity = new RiskProfileConfiguration();

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                ValidateData(data, RiskAction.Create);

                entity.Id = Guid.NewGuid();
                CopyFromModel(data, entity);

                entity.CreatedBy = _actorInfoProvider.Actor.Id;

                if (data.HasFraudRiskLevel)
                {
                    foreach (var riskLevelId in data.RiskLevels)
                    {
                        var riskLevel = _fraudRepository.RiskLevels
                                        .Single(x => x.Id == riskLevelId);

                        entity.AllowedRiskLevels.Add(riskLevel);
                    }
                }

                if (data.HasPaymentMethodCheck)
                {
                    foreach (var paymentMethodId in data.PaymentMethods)
                    {
                        var method = _fraudRepository.PaymentMethods
                                     .Single(o => o.Id == paymentMethodId);

                        entity.AllowedPaymentMethods.Add(method);
                    }
                }

                if (data.HasBonusCheck)
                {
                    foreach (var bonusId in data.Bonuses)
                    {
                        var bonus = _fraudRepository.Bonuses
                                    .Single(o => o.Id == bonusId);

                        entity.AllowedBonuses.Add(bonus);
                    }
                }

                _fraudRepository.RiskProfileConfigurations.Add(entity);
                _fraudRepository.SaveChanges();
                scope.Complete();
            }

            _eventBus.Publish(new RiskProfileCheckConfigCreated
            {
                Id          = entity.Id,
                CreatedBy   = _actorInfoProvider.Actor.UserName,
                DateCreated = entity.DateCreated
            });

            return(entity);
        }
        private void EnsureTopicExists(string topicName)
        {
            if (_topicExistanceChecked)
            {
                return;
            }

            using (var scope = CustomTransactionScope.GetTransactionSuppressedScope())
            {
                _syncService.Execute("WindowsServiceBus_" + topicName, () =>
                {
                    var namespaceManager = GetNamespaceManager();
                    if (!namespaceManager.TopicExists(topicName))
                    {
                        _logger.Debug("Attempting to create topic {0}...".Args(topicName));

                        var topicDescription = new TopicDescription(topicName);
                        namespaceManager.CreateTopic(topicDescription);

                        _logger.Debug("Topic {0} created.".Args(topicName));
                    }

                    _topicExistanceChecked = true;
                });

                scope.Complete();
            }
        }
        public Player AddPlayerFromRequest(AuthorizePlayerRequest request, Guid brandId)
        {
            var player = new Player
            {
                Id           = Guid.Parse(request.userid),
                BrandId      = brandId,
                CurrencyCode = request.cur,
                CultureCode  = request.lang,
                Name         = request.username,
            };

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                _repository.Players.AddOrUpdate(player);

                var wallet = new Wallet()
                {
                    Id           = Guid.NewGuid(),
                    BrandId      = player.BrandId,
                    Balance      = 0,
                    CurrencyCode = player.CurrencyCode,
                    PlayerId     = player.Id
                };
                _repository.Wallets.AddOrUpdate(wallet);

                _repository.SaveChanges();

                scope.Complete();
            }

            return(player);
        }
Beispiel #5
0
        public void PassInvestigation(OfflineWithdrawId id, string remarks)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var offlineWithdrawal = GetWithdrawalWithPlayer(id);
                offlineWithdrawal.InvestigatedBy    = _actorInfoProvider.Actor.UserName;
                offlineWithdrawal.InvestigationDate = DateTimeOffset.Now.ToBrandOffset(offlineWithdrawal.PlayerBankAccount.Player.Brand.TimezoneId);
                offlineWithdrawal.Remarks           = remarks;
                offlineWithdrawal.Status            = WithdrawalStatus.Verified;

                _eventBus.Publish(new WithdrawalInvestigated(
                                      id,
                                      offlineWithdrawal.Amount,
                                      offlineWithdrawal.InvestigationDate.Value,
                                      _actorInfoProvider.Actor.Id,
                                      offlineWithdrawal.PlayerBankAccount.Player.Id,
                                      WithdrawalStatus.Investigation,
                                      remarks,
                                      offlineWithdrawal.TransactionNumber)
                {
                    EventCreated = offlineWithdrawal.InvestigationDate.Value,
                });

                _repository.SaveChanges();
                scope.Complete();
            }
        }
Beispiel #6
0
        public void Handle(DepositApproved @event)
        {
            var bonusCommands = _container.Resolve <BonusCommands>();
            var repository    = _container.Resolve <IBonusRepository>();
            var bus           = _container.Resolve <IEventBus>();

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var wallet = repository.GetLockedWallet(@event.PlayerId);
                wallet.Deposit(@event.ActualAmount, @event.ReferenceCode);
                wallet.Events.ForEach(bus.Publish);
                var player = repository.GetLockedPlayer(@event.PlayerId);
                var depositBonusRedemptions = player.BonusesRedeemed
                                              .Where(r => r.Parameters.TransferExternalId == @event.DepositId)
                                              .Select(br => new BonusRedemption(br));
                foreach (var depositBonusRedemption in depositBonusRedemptions)
                {
                    depositBonusRedemption.Data.Parameters.TransferAmount = @event.ActualAmount;
                    bonusCommands.ProcessBonusRedemptionLifecycle(depositBonusRedemption);
                    depositBonusRedemption.Events.ForEach(bus.Publish);
                }

                bonusCommands.ProcessHighDepositBonus(player);

                repository.SaveChanges();
                scope.Complete();
            }
        }
Beispiel #7
0
        public void Revert(OfflineWithdrawId id, string remarks)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var withdrawal = GetWithdrawalWithPlayer(id);
                if (withdrawal.Status != WithdrawalStatus.Verified)
                {
                    ThrowStatusError(withdrawal.Status, WithdrawalStatus.Reverted);
                }
                withdrawal.Remarks      = remarks;
                withdrawal.Status       = WithdrawalStatus.Reverted;
                withdrawal.RevertedBy   = _actorInfoProvider.Actor.UserName;
                withdrawal.RevertedTime =
                    DateTimeOffset.Now.ToBrandOffset(withdrawal.PlayerBankAccount.Player.Brand.TimezoneId);

                _eventBus.Publish(new WithdrawalReverted(
                                      id,
                                      withdrawal.Amount,
                                      withdrawal.RevertedTime.Value,
                                      _actorInfoProvider.Actor.Id,
                                      withdrawal.PlayerBankAccount.Player.Id,
                                      WithdrawalStatus.Reverted,
                                      remarks,
                                      withdrawal.TransactionNumber,
                                      _actorInfoProvider.Actor.UserName)
                {
                    EventCreated = withdrawal.RevertedTime.Value,
                });

                _repository.SaveChanges();
                scope.Complete();
            }
        }
        public Guid UpdateWagerConfiguration(WagerConfigurationDTO wagerConfigurationDTO, Guid userId)
        {
            var validationResult = new UpdateWageringConfigurationValidator(_fraudRepository)
                                   .Validate(wagerConfigurationDTO);

            if (!validationResult.IsValid)
            {
                throw new RegoValidationException(validationResult);
            }

            var wagerConfiguration = _fraudRepository.WagerConfigurations.First(x => x.Id == wagerConfigurationDTO.Id);

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                wagerConfiguration.IsActive = false;
                wagerConfiguration.BrandId  = wagerConfigurationDTO.BrandId;
                wagerConfiguration.IsDepositWageringCheck          = wagerConfigurationDTO.IsDepositWageringCheck;
                wagerConfiguration.IsRebateWageringCheck           = wagerConfigurationDTO.IsRebateWageringCheck;
                wagerConfiguration.IsManualAdjustmentWageringCheck = wagerConfigurationDTO.IsManualAdjustmentWageringCheck;
                wagerConfiguration.CurrencyCode         = wagerConfigurationDTO.Currency;
                wagerConfiguration.IsServeAllCurrencies = wagerConfiguration.CurrencyCode == "All";
                wagerConfiguration.UpdatedBy            = userId;
                wagerConfiguration.DateUpdated          = DateTimeOffset.UtcNow;

                _fraudRepository.SaveChanges();
                scope.Complete();
            }
            return(wagerConfiguration.Id);
        }
Beispiel #9
0
        public void Handle(DepositSubmitted @event)
        {
            var bonusCommands   = _container.Resolve <BonusCommands>();
            var bonusQueries    = _container.Resolve <BonusQueries>();
            var bus             = _container.Resolve <IEventBus>();
            var bonusRepository = _container.Resolve <IBonusRepository>();

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var player           = bonusRepository.GetLockedPlayer(@event.PlayerId);
                var redemptionParams = new RedemptionParams
                {
                    TransferAmount           = @event.Amount,
                    TransferExternalId       = @event.DepositId,
                    TransferWalletTemplateId = player.Data.Brand.WalletTemplates.Single(wt => wt.IsMain).Id
                };

                bonusQueries
                .GetQualifiedAutomaticBonusIds(@event.PlayerId, player.DepositQuailifiedBonusType, redemptionParams)
                .ForEach(bonusId =>
                {
                    var redemption = bonusCommands.RedeemBonus(@event.PlayerId, bonusId, redemptionParams);
                    redemption.Events.ForEach(bus.Publish);
                });

                scope.Complete();
            }
        }
Beispiel #10
0
        public void FailInvestigation(OfflineWithdrawId id, string remarks)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var withdrawal = GetWithdrawalWithPlayer(id);
                withdrawal.InvestigatedBy    = _actorInfoProvider.Actor.UserName;
                withdrawal.InvestigationDate =
                    DateTimeOffset.Now.ToBrandOffset(withdrawal.PlayerBankAccount.Player.Brand.TimezoneId);
                withdrawal.Remarks = remarks;
                withdrawal.Status  = WithdrawalStatus.Unverified;

                _serviceBus.PublishMessage(new WithdrawRequestCancel
                {
                    WithdrawId     = id,
                    ActorName      = _actorInfoProvider.Actor.UserName,
                    CanceledUserId = _actorInfoProvider.Actor.Id,
                    Status         = WithdrawalStatus.Unverified,
                    Remarks        = remarks
                });


                _repository.SaveChanges();
                scope.Complete();
            }
        }
Beispiel #11
0
        public void SetInvestigateState(Guid requestId, string remarks)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var withdrawal = GetWithdrawalWithPlayer(requestId);
                if (withdrawal == null)
                {
                    return;
                }

                var eventCreated = DateTimeOffset.Now.ToBrandOffset(withdrawal.PlayerBankAccount.Player.Brand.TimezoneId);

                _eventBus.Publish(new WithdrawalInvestigated(
                                      withdrawal.Id,
                                      withdrawal.Amount,
                                      eventCreated,
                                      _actorInfoProvider.Actor.Id,
                                      withdrawal.PlayerBankAccount.Player.Id,
                                      WithdrawalStatus.Investigation,
                                      remarks,
                                      withdrawal.TransactionNumber)
                {
                    EventCreated = eventCreated,
                });

                withdrawal.Remarks = remarks;
                withdrawal.Status  = WithdrawalStatus.Investigation;
                _repository.SaveChanges();
                scope.Complete();
            }
        }
Beispiel #12
0
        public void FailWager(OfflineWithdrawId id, string remarks)
        {
            var withdrawal = GetWithdrawalWithPlayer(id);

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                withdrawal.WagerCheck = false;
                withdrawal.Remarks    = remarks;
                AppendWagerCheckComments(withdrawal, _actorInfoProvider.Actor.UserName);
                withdrawal.Status = WithdrawalStatus.Unverified;

                _serviceBus.PublishMessage(new WithdrawRequestCancel
                {
                    WithdrawId     = id,
                    ActorName      = _actorInfoProvider.Actor.UserName,
                    CanceledUserId = _actorInfoProvider.Actor.Id,
                    Status         = WithdrawalStatus.Unverified,
                    Remarks        = remarks
                });



                _repository.SaveChanges();
                scope.Complete();
            }
        }
Beispiel #13
0
        public void Edit(EditMessageTemplate model)
        {
            var validationResult = _messageTemplateQueries.GetValidationResult(model);

            if (!validationResult.IsValid)
            {
                throw new RegoValidationException(validationResult);
            }

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var messageTemplate = _messagingRepository.MessageTemplates.Single(x => x.Id == model.Id);

                messageTemplate           = Mapper.Map(model, messageTemplate);
                messageTemplate.Updated   = DateTimeOffset.Now.ToBrandOffset(messageTemplate.Brand.TimezoneId);
                messageTemplate.UpdatedBy = _actorInfoProvider.Actor.UserName;

                _messagingRepository.SaveChanges();

                _eventBus.Publish(new MessageTemplateEditedEvent(Mapper.Map <Interface.Data.MessageTemplate>(messageTemplate))
                {
                    EventCreated = DateTimeOffset.Now.ToBrandOffset(messageTemplate.Brand.TimezoneId),
                });

                scope.Complete();
            }
        }
        public string Revert(SaveCurrencyExchangeData model)
        {
            string message;

            var currencyExchange = _paymentRepository.CurrencyExchanges.SingleOrDefault(c => c.Brand.Id == model.BrandId && c.CurrencyTo.Code == model.Currency);

            if (currencyExchange == null)
            {
                throw new RegoException("Currency Exchange not found");
            }

            if (currencyExchange.PreviousRate == null)
            {
                throw new RegoException("Currency Exchange Previous Rate not found");
            }

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                currencyExchange.PreviousRate = currencyExchange.CurrentRate;
                currencyExchange.CurrentRate  = model.PreviousRate;
                currencyExchange.DateUpdated  = DateTimeOffset.UtcNow;
                currencyExchange.UpdatedBy    = _actorInfoProvider.Actor.UserName;

                _paymentRepository.SaveChanges();

                scope.Complete();

                message = "app:currencies.updated";
            }

            return(message);
        }
        public string Add(SaveCurrencyExchangeData model)
        {
            string message;

            if (_queries.GetCurrencyExchanges().Any(c => c.Brand.Id == model.BrandId && c.IsBaseCurrency && c.Brand.BaseCurrencyCode == model.Currency))
            {
                throw new RegoException("Base currency can't set as Currency To");
            }

            if (_queries.GetCurrencyExchanges().Any(c => c.BrandId == model.BrandId && !c.IsBaseCurrency && c.CurrencyToCode == model.Currency))
            {
                throw new RegoException("Currency Exchange Rate already exists");
            }

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var currencyExchange = new CurrencyExchange
                {
                    BrandId        = model.BrandId,
                    CurrencyToCode = model.Currency,
                    CurrentRate    = model.CurrentRate,
                    CreatedBy      = _actorInfoProvider.Actor.UserName,
                    DateCreated    = DateTimeOffset.UtcNow,
                };

                _paymentRepository.CurrencyExchanges.Add(currencyExchange);
                _paymentRepository.SaveChanges();

                scope.Complete();

                message = "app:currencies.created";
            }

            return(message);
        }
        public void Approve(OfflineDepositApprove approveCommand)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var offlineDeposit = _repository.GetDepositById(approveCommand.Id);

                if (approveCommand.ActualAmount > offlineDeposit.Data.Amount)
                {
                    throw new RegoException("actualAmountGreaterThanVerified");
                }

                _validator.Validate(offlineDeposit.Data.PlayerId,
                                    offlineDeposit.Data.CurrencyCode,
                                    approveCommand.ActualAmount);

                var depositCommand = offlineDeposit.Approve(
                    approveCommand.ActualAmount,
                    approveCommand.Fee,
                    approveCommand.PlayerRemark,
                    _actorInfoProvider.Actor.UserName,
                    approveCommand.Remark);

                _repository.SaveChanges();

                _serviceBus.PublishMessage(depositCommand);

                scope.Complete();
            }
        }
Beispiel #17
0
        public void SaveExemption(Exemption exemption)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var player     = _repository.Players.Single(x => x.Id == exemption.PlayerId);
                var brand      = _brandQueries.GetBrandOrNull(player.BrandId);
                var exemptFrom = DateTime.Parse(exemption.ExemptFrom, CultureInfo.InvariantCulture);
                var exemptTo   = DateTime.Parse(exemption.ExemptTo, CultureInfo.InvariantCulture);

                if (exemptTo < exemptFrom)
                {
                    throw new ArgumentException("ExemptTo must be greater or equal then ExemptFrom.");
                }

                player.ExemptWithdrawalVerification = exemption.Exempt;
                player.ExemptWithdrawalFrom         = exemptFrom.ToBrandDateTimeOffset(brand.TimezoneId);
                player.ExemptWithdrawalTo           = exemptTo.ToBrandDateTimeOffset(brand.TimezoneId);
                player.ExemptLimit = exemption.ExemptLimit;
                _repository.SaveChanges();

                _eventBus.Publish(new PlayerAccountRestrictionsChanged(
                                      player.Id,
                                      player.ExemptLimit,
                                      player.ExemptWithdrawalTo,
                                      player.ExemptWithdrawalFrom,
                                      player.ExemptWithdrawalVerification)
                {
                    EventCreated = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
                });

                scope.Complete();
            }
        }
Beispiel #18
0
        public async Task Update(EventAreaDto entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException();
            }

            if (entity.EventId <= 0)
            {
                throw new EventAreaException("EventId is invalid");
            }

            if (!IsDescriptionUnique(entity, false))
            {
                throw new EventAreaException("Area description isn't unique");
            }

            if (!entity.Seats.Any())
            {
                throw new EventAreaException("Invalid state of event area. Seat list is empty");
            }

            using (var transaction = CustomTransactionScope.GetTransactionScope())
            {
                var update = await _context.EventAreaRepository.GetAsync(entity.Id);

                update.Price       = entity.Price;
                update.Description = entity.Description;
                update.CoordY      = entity.CoordY;
                update.CoordX      = entity.CoordX;
                _context.EventAreaRepository.Update(update);
                await _context.SaveAsync();

                //find seats which were deleted
                var seats = await _context.EventSeatRepository.FindByAsync(x => x.EventAreaId == update.Id);

                var differences = seats.Where(list2 => entity.Seats.All(list1 => list1.Id != list2.Id)).ToList();

                foreach (var seat in differences)
                {
                    await _seatService.Delete(seat.Id);
                }

                foreach (var seat in entity.Seats)
                {
                    seat.EventAreaId = update.Id;
                    if (seat.Id == 0)
                    {
                        await _seatService.Create(seat);
                    }
                    else
                    {
                        await _seatService.Update(seat);
                    }
                }

                transaction.Complete();
            }
        }
Beispiel #19
0
        public void Consume(Interface.Commands.WithdrawRequestApprove command)
        {
            var paymentRepository = _container.Resolve <IPaymentRepository>();
            var serviceBus        = _container.Resolve <IServiceBus>();

            var withdrawal = paymentRepository.OfflineWithdraws
                             .Include(x => x.PlayerBankAccount.Player)
                             .FirstOrDefault(x => x.Id == command.WithdrawId);

            if (withdrawal == null)
            {
                throw new RegoException(string.Format(WithdrawRecordNotFoundMessage, command.WithdrawId));
            }

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                if (withdrawal.Status != WithdrawalStatus.Accepted)
                {
                    throw new InvalidOperationException(string.Format("The withdrawal has \"{0}\" status, so it can't be Approve, id:{1}", withdrawal.Status, command.WithdrawId));
                }

                withdrawal.Remarks    = command.Remarks;
                withdrawal.Status     = WithdrawalStatus.Approved;
                withdrawal.Approved   = command.Approved;
                withdrawal.ApprovedBy = command.ActorName;

                var eventCreated = DateTimeOffset.Now.ToOffset(command.Approved.Offset);

                //UnLock WithdrawLock
                var withdrawLock =
                    paymentRepository.WithdrawalLocks.FirstOrDefault(x => x.WithdrawalId == command.WithdrawId);
                withdrawLock.Status     = Status.Inactive;
                withdrawLock.UnLockedBy = command.ActorName;
                withdrawLock.UnLockedOn = eventCreated;

                paymentRepository.SaveChanges();

                //raise WithdrawalApproved event
                var withdrawalApprovedEvent = new WithdrawalApproved(
                    command.WithdrawId,
                    withdrawal.Amount,
                    eventCreated,
                    command.ApprovedUerId,
                    withdrawal.PlayerBankAccount.Player.Id,
                    WithdrawalStatus.Approved,
                    command.Remarks,
                    withdrawal.TransactionNumber,
                    command.ActorName)
                {
                    EventCreatedBy = command.ActorName,
                    EventCreated   = command.Approved,
                };

                serviceBus.PublishMessage(withdrawalApprovedEvent);

                scope.Complete();
            }
        }
Beispiel #20
0
        public Guid Add(AddBankAccountData data)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var validationResult = new AddBankAccountValidator(_repository, _brandRepository).Validate(data);

                if (!validationResult.IsValid)
                {
                    throw new RegoException(validationResult.Errors.First().ErrorMessage);
                    //throw validationResult.GetValidationError();
                }

                var brand = _repository.Brands.Single(x => x.Id == new Guid(data.BrandId));

                var bankAccount = new BankAccount
                {
                    Id            = data.Id ?? Guid.NewGuid(),
                    Bank          = _repository.Banks.Single(x => x.Id == data.Bank),
                    CurrencyCode  = data.Currency,
                    AccountId     = data.AccountId,
                    AccountName   = data.AccountName,
                    AccountNumber = data.AccountNumber,
                    //AccountType = data.AccountType,
                    AccountType   = _repository.BankAccountTypes.Single(x => x.Id == data.AccountType),
                    Province      = data.Province,
                    Branch        = data.Branch,
                    SupplierName  = data.SupplierName,
                    ContactNumber = data.ContactNumber,
                    USBCode       = data.USBCode,
                    //Temporrary solution for Bank Account seeding
                    PurchasedDate = DateTime.UtcNow,
                    Remarks       = data.Remarks,
                    Status        = BankAccountStatus.Pending,
                    Created       = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
                    CreatedBy     = _actorInfoProvider.Actor.UserName
                };

                _repository.BankAccounts.Add(bankAccount);
                _repository.SaveChanges();

                var bankAccountAdded = new BankAccountAdded
                {
                    Id                = bankAccount.Id,
                    AccountId         = bankAccount.AccountId,
                    BankId            = bankAccount.Bank.Id,
                    BankAccountStatus = bankAccount.Status,
                    CreatedBy         = bankAccount.CreatedBy,
                    CreatedDate       = bankAccount.Created,
                    EventCreated      = bankAccount.Created,
                };

                _eventBus.Publish(bankAccountAdded);

                scope.Complete();

                return(bankAccount.Id);
            }
        }
Beispiel #21
0
 public void Deactivate(DeactivateUserData data)
 {
     using (var scope = CustomTransactionScope.GetTransactionScope())
     {
         ChangeStatus(data.Id, false);
         _eventBus.Publish(new AdminDeactivated(data.Id, data.Remarks));
         scope.Complete();
     }
 }
Beispiel #22
0
        public Guid AddBrand(AddBrandRequest addBrandRequest)
        {
            var validationResult = ValidateThatBrandCanBeAdded(addBrandRequest);

            if (!validationResult.IsValid)
            {
                throw new RegoValidationException(validationResult);
            }

            var brand = new Interface.Data.Brand
            {
                Id                     = addBrandRequest.Id ?? Guid.NewGuid(),
                LicenseeId             = addBrandRequest.Licensee,
                Licensee               = _repository.Licensees.Single(x => x.Id == addBrandRequest.Licensee),
                Code                   = addBrandRequest.Code,
                Name                   = addBrandRequest.Name,
                Email                  = addBrandRequest.Email,
                SmsNumber              = addBrandRequest.SmsNumber,
                WebsiteUrl             = Uri.EscapeUriString(addBrandRequest.WebsiteUrl),
                Type                   = addBrandRequest.Type,
                TimezoneId             = addBrandRequest.TimeZoneId,
                EnablePlayerPrefix     = addBrandRequest.EnablePlayerPrefix,
                PlayerPrefix           = addBrandRequest.PlayerPrefix,
                PlayerActivationMethod = addBrandRequest.PlayerActivationMethod,
                Status                 = BrandStatus.Inactive,
                CreatedBy              = _actorInfoProvider.Actor.UserName,
                DateCreated            = DateTimeOffset.Now.ToBrandOffset(addBrandRequest.TimeZoneId)
            };

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                _repository.Brands.Add(brand);
                _repository.SaveChanges();

                _adminCommands.AddBrandToAdmin(_actorInfoProvider.Actor.Id, brand.Id);
                _eventBus.Publish(new BrandRegistered
                {
                    Id                     = brand.Id,
                    Code                   = brand.Code,
                    Name                   = brand.Name,
                    Email                  = brand.Email,
                    SmsNumber              = brand.SmsNumber,
                    WebsiteUrl             = brand.WebsiteUrl,
                    LicenseeId             = brand.Licensee.Id,
                    LicenseeName           = brand.Licensee.Name,
                    TimeZoneId             = brand.TimezoneId,
                    BrandType              = brand.Type,
                    Status                 = brand.Status,
                    PlayerPrefix           = brand.PlayerPrefix,
                    InternalAccountsNumber = brand.InternalAccountsNumber,
                    EventCreated           = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
                });
                scope.Complete();
            }

            return(brand.Id);
        }
Beispiel #23
0
        public void Edit(EditPlayerBankAccountData model)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope(IsolationLevel.RepeatableRead))
            {
                var validationResult = new EditPlayerBankAccountValidator(_repository, _queries).Validate(model);

                if (!validationResult.IsValid)
                {
                    throw new RegoValidationException(validationResult);
                }

                var bank = _repository.Banks.Single(x => x.Id == model.Bank);

                var bankAccount = _repository.PlayerBankAccounts
                                  .Include(x => x.Player.CurrentBankAccount)
                                  .Include(x => x.Player.Brand)
                                  .Include(x => x.Bank)
                                  .Single(x => x.Id == model.Id.Value);

                var isModified =
                    bankAccount.Bank.Id != bank.Id ||
                    bankAccount.Province != model.Province ||
                    bankAccount.City != model.City ||
                    bankAccount.Branch != model.Branch ||
                    bankAccount.SwiftCode != model.SwiftCode ||
                    bankAccount.Address != model.Address ||
                    bankAccount.AccountName != model.AccountName ||
                    bankAccount.AccountNumber != model.AccountNumber;

                if (isModified)
                {
                    bankAccount.Status = BankAccountStatus.Pending;
                }

                bankAccount.Bank          = bank;
                bankAccount.Province      = model.Province;
                bankAccount.City          = model.City;
                bankAccount.Branch        = model.Branch;
                bankAccount.SwiftCode     = model.SwiftCode;
                bankAccount.Address       = model.Address;
                bankAccount.AccountName   = model.AccountName;
                bankAccount.AccountNumber = model.AccountNumber;
                bankAccount.Updated       = DateTimeOffset.Now.ToBrandOffset(bankAccount.Player.Brand.TimezoneId);
                bankAccount.UpdatedBy     = _actorInfoProvider.Actor.UserName;

                _repository.SaveChanges();
                _eventBus.Publish(new PlayerBankAccountEdited
                {
                    Id           = bankAccount.Id,
                    Name         = bankAccount.AccountName,
                    Number       = bankAccount.AccountNumber,
                    EventCreated = bankAccount.Updated.Value,
                });

                scope.Complete();
            }
        }
        public CurrencyCRUDStatus Save(EditCurrencyData model)
        {
            var oldCode = model.OldCode;
            var oldName = model.OldName;

            var currency = _paymentRepository.Currencies.SingleOrDefault(c => c.Code == oldCode);

            if (currency == null)
            {
                return(new CurrencyCRUDStatus {
                    IsSuccess = false, Message = "invalidId"
                });
            }

            if (_queries.GetCurrencies().Any(c => c.Code == model.Code && c.Code != oldCode))
            {
                return(new CurrencyCRUDStatus {
                    IsSuccess = false, Message = "codeUnique"
                });
            }

            if (_queries.GetCurrencies().Any(c => c.Name == model.Name && c.Name != oldName))
            {
                return(new CurrencyCRUDStatus {
                    IsSuccess = false, Message = "nameUnique"
                });
            }

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var username = _actorInfoProvider.Actor.UserName;
                currency.UpdatedBy   = username;
                currency.DateUpdated = DateTimeOffset.UtcNow;
                currency.Name        = model.Name;
                currency.Remarks     = model.Remarks;

                _paymentRepository.SaveChanges();

                var currencyUpdated = new CurrencyUpdated
                {
                    OldCode = model.OldCode,
                    OldName = model.OldName,
                    Code    = currency.Code,
                    Name    = currency.Name,
                    Remarks = currency.Remarks
                };

                _eventBus.Publish(currencyUpdated);

                scope.Complete();
            }

            return(new CurrencyCRUDStatus {
                IsSuccess = true, Message = "updated"
            });
        }
Beispiel #25
0
        public void UpdateAdmin(EditAdminData data)
        {
            var validationResult = new EditAdminValidator().Validate(data);

            if (!validationResult.IsValid)
            {
                throw new RegoException(validationResult.Errors.First().ErrorMessage);
            }

            var admin = _repository.GetAdminById(data.Id);

            //todo: KB: should be handled by EditAdminValidator
            if (admin == null)
            {
                throw new RegoException(string.Format("User with id: {0} not found", data.Id));
            }

            var role = _repository.Roles.SingleOrDefault(r => r.Id == data.RoleId);

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                admin.Username    = data.Username;
                admin.FirstName   = data.FirstName;
                admin.LastName    = data.LastName;
                admin.IsActive    = data.IsActive;
                admin.Language    = data.Language;
                admin.Description = data.Description;

                //todo: KB: should be handled by EditAdminValidator
                if (role != null)
                {
                    admin.Role = role;
                }

                admin.SetLicensees(data.AssignedLicensees);

                admin.SetAllowedBrands(data.AllowedBrands);

                admin.SetCurrencies(data.Currencies);

                if (data.RoleId != role.Id)
                {
                    _authCommands.AssignRoleToActor(new AssignRole
                    {
                        ActorId = admin.Id,
                        RoleId  = role.Id
                    });
                }

                _repository.SaveChanges();

                _eventBus.Publish(new AdminUpdated(admin));

                scope.Complete();
            }
        }
Beispiel #26
0
        public void AssignBrandCountry(AssignBrandCountryRequest assignBrandCountryRequest)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var validationResult = new AssignBrandCountryValidator(_repository).Validate(assignBrandCountryRequest);

                if (!validationResult.IsValid)
                {
                    throw new RegoValidationException(validationResult);
                }

                var brand = _repository.Brands
                            .Include(x => x.BrandCountries.Select(y => y.Country))
                            .Single(x => x.Id == assignBrandCountryRequest.Brand);

                var oldCountries = brand.BrandCountries
                                   .Where(x => !assignBrandCountryRequest.Countries.Contains(x.CountryCode))
                                   .ToArray();

                foreach (var oldCountry in oldCountries)
                {
                    brand.BrandCountries.Remove(oldCountry);
                }

                var newCountries = assignBrandCountryRequest.Countries
                                   .Where(x => brand.BrandCountries.All(y => y.CountryCode != x))
                                   .ToArray();

                foreach (var country in newCountries)
                {
                    var countryToAdd = _repository.Countries.Single(x => x.Code == country);

                    brand.BrandCountries.Add(new BrandCountry
                    {
                        BrandId     = brand.Id,
                        Brand       = brand,
                        CountryCode = countryToAdd.Code,
                        Country     = countryToAdd,
                        DateAdded   = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
                        AddedBy     = _actorInfoProvider.Actor.UserName
                    });
                }

                brand.DateUpdated = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId);
                brand.UpdatedBy   = _actorInfoProvider.Actor.UserName;

                _repository.SaveChanges();

                _eventBus.Publish(new BrandCountriesAssigned(brand)
                {
                    EventCreated = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId),
                });

                scope.Complete();
            }
        }
Beispiel #27
0
 public void DeleteGame(Guid id)
 {
     using (var scope = CustomTransactionScope.GetTransactionScope())
     {
         var game = _repository.Games.Single(x => x.Id == id);
         _repository.Games.Remove(game);
         _repository.SaveChanges();
         scope.Complete();
     }
 }
        //[Permission(Permissions.Delete, Module = Modules.AutoVerificationConfiguration)]
        public void Delete(Guid id)
        {
            var avcConfiguratoin = _fraudRepository.AutoVerificationCheckConfigurations.Single(x => x.Id == id);

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                _fraudRepository.AutoVerificationCheckConfigurations.Remove(avcConfiguratoin);
                _fraudRepository.SaveChanges();
                scope.Complete();
            }
        }
        public void Save(string key, string value)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var settingsItem = UpdateOrCreateSettingsItem(key, value);

                _settingsRepository.SaveChanges();

                _eventBus.Publish(new SettingsItemChanged(settingsItem));

                scope.Complete();
            }
        }
        public void Consume(RiskLevelStatusUpdated message)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var riskLevel = _brandRepository.RiskLevels.Single(x => x.Id == message.Id);

                riskLevel.Status = (Status)message.NewStatus;

                _brandRepository.SaveChanges();

                scope.Complete();
            }
        }