public void ClaimBonusRedemption(ClaimBonusRedemption model)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var validationResult = _bonusQueries.GetValidationResult(model);
                if (validationResult.IsValid == false)
                {
                    throw new RegoException(validationResult.Errors.First().ErrorMessage);
                }

                var redemption = _repository.GetBonusRedemption(model.PlayerId, model.RedemptionId);
                ClaimBonusRedemption(redemption);
                _repository.SaveChanges();

                redemption.Events.ForEach(_eventBus.Publish);
                scope.Complete();
            }
        }
Exemple #2
0
        private Guid AddBonus(Data.Bonus bonus)
        {
            bonus.Id       = Guid.NewGuid();
            bonus.Template = _repository.Templates
                             .Include(o => o.Info)
                             .Include(o => o.Info.Brand)
                             .Single(a => a.Id == bonus.Template.Id &&
                                     a.Version == bonus.Template.Version);

            bonus.CreatedOn = DateTimeOffset.Now.ToBrandOffset(bonus.Template.Info.Brand.TimezoneId);
            bonus.CreatedBy = _actorInfoProvider.Actor.UserName;
            bonus.Statistic = new BonusStatistic();

            _repository.Bonuses.Add(bonus);
            _repository.SaveChanges();

            _eventBus.Publish(new BonusCreated
            {
                AggregateId  = bonus.Id,
                Description  = bonus.Description,
                Name         = bonus.Name,
                Code         = bonus.Code,
                BrandId      = bonus.Template.Info.Brand.Id,
                BonusType    = bonus.Template.Info.TemplateType,
                IsActive     = bonus.IsActive,
                EventCreated = bonus.CreatedOn
            });

            return(bonus.Id);
        }