Esempio n. 1
0
        public ValidationResult ValidatePaymentLevelCanBeDeactivated(DeactivatePaymentLevelCommand command)
        {
            var validator        = new DeactivatePaymentLevelValidator(_repository, _paymentLevelQueries);
            var validationResult = validator.Validate(command);

            return(validationResult);
        }
        public ActionResult Deactivate(DeactivatePaymentLevelCommand data)
        {
            var validationResult = _paymentLevelCommands.ValidatePaymentLevelCanBeDeactivated(data);

            if (!validationResult.IsValid)
            {
                return(ValidationErrorResponseActionResult(validationResult.Errors));
            }

            _paymentLevelCommands.Deactivate(data);

            return(this.Success());
        }
Esempio n. 3
0
        public void Cannot_deactivate_invalid_payment_level()
        {
            var createPaymentLevelData = CreatePaymentLevelData();
            var id = _paymentLevelCommands.Save(createPaymentLevelData).PaymentLevelId;

            _paymentRepository.PaymentLevels.Single(x => x.Id == id).Status = PaymentLevelStatus.Inactive;

            var deactivatePaymentLevelCommand = new DeactivatePaymentLevelCommand {
                Id = id
            };

            var canDeactivate = _paymentLevelCommands.ValidatePaymentLevelCanBeDeactivated(deactivatePaymentLevelCommand);

            Assert.That(canDeactivate.IsValid, Is.False);
        }
Esempio n. 4
0
        public void Deactivate(DeactivatePaymentLevelCommand command)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var oldPaymentLevel = _repository.PaymentLevels
                                      .Include(x => x.Brand)
                                      .Single(x => x.Id == command.Id);

                oldPaymentLevel.Status        = PaymentLevelStatus.Inactive;
                oldPaymentLevel.DeactivatedBy = _actorInfoProvider.Actor.UserName;

                oldPaymentLevel.DateDeactivated = DateTimeOffset.Now.ToBrandOffset(oldPaymentLevel.Brand.TimezoneId);

                if (command.NewPaymentLevelId.HasValue)
                {
                    _playerCommands.UpdatePlayersPaymentLevel(command.Id, command.NewPaymentLevelId.Value);

                    var newPaymentLevel = _repository.PaymentLevels.Single(x => x.Id == command.NewPaymentLevelId);

                    _brandCommands.MakePaymentLevelDefault(newPaymentLevel.Id, newPaymentLevel.BrandId, newPaymentLevel.CurrencyCode);

                    _repository.PlayerPaymentLevels
                    .Include(x => x.PaymentLevel)
                    .Where(x => x.PaymentLevel.Id == command.Id)
                    .ForEach(x => x.PaymentLevel = newPaymentLevel);
                }

                _repository.SaveChanges();

                _eventBus.Publish(new PaymentLevelDeactivated
                {
                    Id              = oldPaymentLevel.Id,
                    Code            = oldPaymentLevel.Code,
                    Name            = oldPaymentLevel.Name,
                    DeactivatedBy   = oldPaymentLevel.DeactivatedBy,
                    DeactivatedDate = oldPaymentLevel.DateDeactivated.Value,
                    Remarks         = command.Remarks,
                    EventCreated    = DateTimeOffset.Now.ToBrandOffset(oldPaymentLevel.Brand.TimezoneId),
                });

                scope.Complete();
            }
        }
Esempio n. 5
0
        public void Can_deactivate_payment_level()
        {
            var createPaymentLevelData = CreatePaymentLevelData();
            var id = _paymentLevelCommands.Save(createPaymentLevelData).PaymentLevelId;

            var deactivatePaymentLevelCommand = new DeactivatePaymentLevelCommand {
                Id = id
            };

            var canDeactivate = _paymentLevelCommands.ValidatePaymentLevelCanBeDeactivated(deactivatePaymentLevelCommand);

            Assert.That(canDeactivate.IsValid, Is.True);

            _paymentLevelCommands.Deactivate(deactivatePaymentLevelCommand);

            var newStatus = _paymentRepository.PaymentLevels.Single(x => x.Id == id).Status;

            Assert.That(newStatus, Is.EqualTo(PaymentLevelStatus.Inactive));
        }